|
|
@@ -1,25 +1,436 @@
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
+
|
|
|
Page({
|
|
|
data: {
|
|
|
- leadInfo: {}
|
|
|
+ detail: {},
|
|
|
+ followRecords: [],
|
|
|
+ operationRecords: [],
|
|
|
+ teamList: [],
|
|
|
+ showActionSheet: false,
|
|
|
+ teamActions: [],
|
|
|
+ currentOperation: '', // 记录当前操作类型:'分配'或'撤回'
|
|
|
+ showInvalidModal: false, // 控制无效原因模态框显示
|
|
|
+ invalidReason: '', // 无效原因
|
|
|
+ showAssignConfirm: false, // 控制分配确认弹窗显示
|
|
|
+ showWithdrawConfirm: false, // 控制撤回确认弹窗显示
|
|
|
+ selectedTeam: null, // 存储选择的团队成员
|
|
|
+ tabsList: [{
|
|
|
+ label: '跟进记录',
|
|
|
+ icon: "icon-tabgenjinjilu"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: "icon-tabcaozuojilu1",
|
|
|
+ label: '操作记录',
|
|
|
+ model: "#record"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ tabbarList: [],
|
|
|
+ tabsActive: 0
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
- const id = options.id;
|
|
|
- this.getLeadDetail(id);
|
|
|
- },
|
|
|
- getLeadDetail(id) {
|
|
|
- // 模拟获取线索详情数据
|
|
|
- const mockData = {
|
|
|
- id: id,
|
|
|
- name: `线索${id}`,
|
|
|
- source: id === 1 ? '网站' : id === 2 ? '电话' : '展会',
|
|
|
- status: id === 1 ? '待跟进' : id === 2 ? '跟进中' : '已转化',
|
|
|
- contact: `1380013800${id}`,
|
|
|
- email: `lead${id}@example.com`,
|
|
|
- description: `线索${id}的详细描述`,
|
|
|
- createTime: '2026-03-30'
|
|
|
+ let auth = wx.getStorageSync("auth").wcrmlead;
|
|
|
+ this.setData({
|
|
|
+ sat_orderclueid: options.id,
|
|
|
+ authoptions: auth.options
|
|
|
+ })
|
|
|
+ this.getDetail();
|
|
|
+ },
|
|
|
+ getDetail() {
|
|
|
+ _Http.basic({
|
|
|
+ classname: "webmanage.saletool.orderclue.publicclue.PublicClue",
|
|
|
+ method: "selectDetail",
|
|
|
+ content: {
|
|
|
+ sat_orderclueid: this.data.sat_orderclueid
|
|
|
+ },
|
|
|
+ }).then(res => {
|
|
|
+ console.log("线索详情", res)
|
|
|
+ if (res.code === 1) {
|
|
|
+ this.setData({
|
|
|
+ detail: res.data || {},
|
|
|
+ });
|
|
|
+ this.partialRenewal();
|
|
|
+ this.getTeamList();
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '获取线索详情失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '网络错误',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ tabsChange(e) {
|
|
|
+ this.setData({
|
|
|
+ tabsActive: e.detail
|
|
|
+ });
|
|
|
+ this.partialRenewal();
|
|
|
+ },
|
|
|
+ tabbarOnClick(e) {
|
|
|
+ switch (e.detail.label) {
|
|
|
+ case '线索分配':
|
|
|
+ this.setData({
|
|
|
+ currentOperation: '分配',
|
|
|
+ showActionSheet: true
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case '撤回':
|
|
|
+ // 撤回功能:默认选择团队中的负责人
|
|
|
+ const {
|
|
|
+ teamList
|
|
|
+ } = this.data;
|
|
|
+ const leader = teamList.find(team => team.isleader === 1);
|
|
|
+ if (leader) {
|
|
|
+ this.setData({
|
|
|
+ selectedTeam: leader,
|
|
|
+ showWithdrawConfirm: true
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '未找到团队负责人',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case '转化客户':
|
|
|
+ // 跳转到新建客户页面,默认带入当前的线索信息
|
|
|
+ const {
|
|
|
+ detail
|
|
|
+ } = this.data;
|
|
|
+ wx.navigateTo({
|
|
|
+ url: `/CRM/customer/create?clueId=${detail.sat_orderclueid}&clueInfo=${encodeURIComponent(JSON.stringify(detail))}`
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case '无效':
|
|
|
+ // 显示无效原因模态框
|
|
|
+ this.setData({
|
|
|
+ showInvalidModal: true,
|
|
|
+ invalidReason: ''
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 关闭动作面板
|
|
|
+ onActionSheetClose() {
|
|
|
+ this.setData({
|
|
|
+ showActionSheet: false,
|
|
|
+ currentOperation: ''
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 处理无效原因输入
|
|
|
+ onInvalidReasonInput(e) {
|
|
|
+ this.setData({
|
|
|
+ invalidReason: e.detail.value
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 确认无效操作
|
|
|
+ confirmInvalid() {
|
|
|
+ const {
|
|
|
+ invalidReason,
|
|
|
+ sat_orderclueid
|
|
|
+ } = this.data;
|
|
|
+
|
|
|
+ // 验证无效原因是否为空
|
|
|
+ if (!invalidReason) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入无效原因',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建请求参数
|
|
|
+ const content = {
|
|
|
+ sat_orderclueid: sat_orderclueid,
|
|
|
+ content: invalidReason,
|
|
|
+ logtype: "无效",
|
|
|
+ followTime: new Date().toISOString().slice(0, 19).replace('T', ' ') // 当前时间
|
|
|
};
|
|
|
+
|
|
|
+ // 调用跟进接口
|
|
|
+ _Http.basic({
|
|
|
+ id: "20221208100602",
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ console.log('标记无效结果:', res);
|
|
|
+
|
|
|
+ // 关闭模态框
|
|
|
+ this.setData({
|
|
|
+ showInvalidModal: false,
|
|
|
+ invalidReason: ''
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res.code === 1) {
|
|
|
+ // 显示成功提示
|
|
|
+ wx.showToast({
|
|
|
+ title: '线索已标记为无效',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+
|
|
|
+ // 刷新详情页
|
|
|
+ this.getDetail();
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.msg || '标记无效失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('标记无效失败:', err);
|
|
|
+
|
|
|
+ // 关闭模态框
|
|
|
+ this.setData({
|
|
|
+ showInvalidModal: false,
|
|
|
+ invalidReason: ''
|
|
|
+ });
|
|
|
+
|
|
|
+ wx.showToast({
|
|
|
+ title: '网络错误',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 取消无效操作
|
|
|
+ cancelInvalid() {
|
|
|
+ this.setData({
|
|
|
+ showInvalidModal: false,
|
|
|
+ invalidReason: ''
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 确认分配
|
|
|
+ confirmAssign() {
|
|
|
+ const {
|
|
|
+ selectedTeam
|
|
|
+ } = this.data;
|
|
|
+ if (selectedTeam) {
|
|
|
+ this.assignClue(selectedTeam);
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ showAssignConfirm: false,
|
|
|
+ selectedTeam: null
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 取消分配
|
|
|
+ cancelAssign() {
|
|
|
+ this.setData({
|
|
|
+ showAssignConfirm: false,
|
|
|
+ selectedTeam: null
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 确认撤回
|
|
|
+ confirmWithdraw() {
|
|
|
+ const {
|
|
|
+ selectedTeam
|
|
|
+ } = this.data;
|
|
|
+ if (selectedTeam) {
|
|
|
+ this.assignClue(selectedTeam);
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ showWithdrawConfirm: false,
|
|
|
+ selectedTeam: null
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 取消撤回
|
|
|
+ cancelWithdraw() {
|
|
|
+ this.setData({
|
|
|
+ showWithdrawConfirm: false,
|
|
|
+ selectedTeam: null
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 选择团队成员
|
|
|
+ onActionSheetSelect(event) {
|
|
|
+ const selectedTeam = event.detail.data;
|
|
|
+ this.setData({
|
|
|
+ selectedTeam: selectedTeam,
|
|
|
+ showAssignConfirm: true
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 分配线索
|
|
|
+ assignClue(team) {
|
|
|
+ _Http.basic({
|
|
|
+ "classname": "crm.agent.orderclue.orderclue",
|
|
|
+ "method": "changeClue",
|
|
|
+ content: {
|
|
|
+ sat_orderclueid: [this.data.sat_orderclueid],
|
|
|
+ sys_enterprise_hrid: team.sys_enterprise_hrid,
|
|
|
+ ordercluecount: "待跟进"
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("线索分配结果", res)
|
|
|
+ if (res.code === 1) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '线索分配成功',
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ // 关闭动作面板
|
|
|
+ this.setData({
|
|
|
+ showActionSheet: false
|
|
|
+ });
|
|
|
+ // 刷新详情页
|
|
|
+ this.getDetail();
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '线索分配失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('线索分配失败', err);
|
|
|
+ wx.showToast({
|
|
|
+ title: '网络错误',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //局部数据更新 tabs
|
|
|
+ partialRenewal(init = false) {
|
|
|
+ let model = this.data.tabsList[this.data.tabsActive].model;
|
|
|
+ if (model) {
|
|
|
+ let Component = this.selectComponent(model),
|
|
|
+ {
|
|
|
+ total,
|
|
|
+ pageNumber,
|
|
|
+ pageTotal
|
|
|
+ } = Component.data.content,
|
|
|
+ id = this.data.sat_orderclueid;
|
|
|
+ if (model == "#Files") init = true;
|
|
|
+ if (total == null || init) {
|
|
|
+ Component.getList(id, init);
|
|
|
+ } else if (pageNumber <= pageTotal) {
|
|
|
+ Component.getList(id, false);
|
|
|
+ }
|
|
|
+ } else if (this.data.tabsActive === 0) {
|
|
|
+ // 跟进记录Tab
|
|
|
+ let Component = this.selectComponent('#FollowRecord');
|
|
|
+ if (Component) {
|
|
|
+ Component.getList(this.data.sat_orderclueid, init);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onReachBottom() {
|
|
|
+ this.partialRenewal();
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ _Http.updateList && _Http.updateList()
|
|
|
+ const page = getCurrentPages().find(v => v.__route__ == 'CRM/lead/index');
|
|
|
+ if (!page) return;
|
|
|
+ let content = JSON.parse(JSON.stringify(page.data.content));
|
|
|
+ content.pageSize = (content.pageNumber - 1) * content.pageSize;
|
|
|
+ content.pageNumber = 1;
|
|
|
+ _Http.basic({
|
|
|
+ id: page.data.id,
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ console.log("更新线索列表", res);
|
|
|
+ if (res.code == '1') {
|
|
|
+ page.setData({
|
|
|
+ list: res.data,
|
|
|
+ "content.total": res.total
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取经销商团队列表
|
|
|
+ getTeamList() {
|
|
|
+ _Http.basic({
|
|
|
+ classname: "sale.team.team",
|
|
|
+ method: "query_teamList",
|
|
|
+ content: {
|
|
|
+ pageNumber: 1,
|
|
|
+ pageSize: 99999,
|
|
|
+ where: {
|
|
|
+ condition: ""
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }).then(res => {
|
|
|
+ console.log("经销商团队列表", res)
|
|
|
+ if (res.code === 1) {
|
|
|
+ const teamList = res.data || [];
|
|
|
+ this.setData({
|
|
|
+ teamList: teamList,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 生成团队成员操作选项
|
|
|
+ this.generateTeamActions(teamList);
|
|
|
+
|
|
|
+ // 生成操作按钮列表
|
|
|
+ this.generateTabbarList(teamList);
|
|
|
+ } else {
|
|
|
+ console.error('获取经销商团队列表失败', res.msg);
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('获取经销商团队列表失败', err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 生成团队成员操作选项
|
|
|
+ generateTeamActions(teamList) {
|
|
|
+ const {
|
|
|
+ detail,
|
|
|
+ currentOperation
|
|
|
+ } = this.data;
|
|
|
+ const teamActions = teamList.map(team => {
|
|
|
+ // 禁用与当前线索负责人姓名相同的选项
|
|
|
+ const disabled = detail.leadername === team.name;
|
|
|
+ return {
|
|
|
+ name: team.name,
|
|
|
+ subname: '在手 待跟进、跟进中 线索数量:' + team.ordercluecount,
|
|
|
+ disabled: disabled,
|
|
|
+ data: team
|
|
|
+ };
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ teamActions: teamActions
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 生成操作按钮列表
|
|
|
+ generateTabbarList(teamList) {
|
|
|
+ const {
|
|
|
+ detail
|
|
|
+ } = this.data;
|
|
|
+ const tabbarList = [];
|
|
|
+
|
|
|
+ // 若线索状态不等于已转化,则可使用转化客户
|
|
|
+ if (detail.status !== '已无效' && detail.status !== '已转化') {
|
|
|
+ tabbarList.push({
|
|
|
+ icon: "icon-tabkehu",
|
|
|
+ label: "转化客户"
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找团队中的负责人
|
|
|
+ const leader = teamList.find(team => team.isleader === 1);
|
|
|
+
|
|
|
+ // 若detail.leadername === teamList中isleader==1的name,则可操作分配,反之可操作撤回
|
|
|
+ if (detail.status !== '已无效' && this.data.authoptions.some(v => v == 'allot')) {
|
|
|
+ if (leader && detail.leadername === leader.name) {
|
|
|
+ tabbarList.push({
|
|
|
+ icon: "icon-tabchanpinleibie",
|
|
|
+ label: "线索分配"
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ tabbarList.push({
|
|
|
+ icon: "icon-a-baobeibohuituihui",
|
|
|
+ label: "撤回"
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 都为待跟进、跟进中状态才可用无效
|
|
|
+ if (detail.status !== '已无效') {
|
|
|
+ tabbarList.push({
|
|
|
+ icon: "icon-tabxiangxixinxi1",
|
|
|
+ label: "无效"
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
this.setData({
|
|
|
- leadInfo: mockData
|
|
|
+ tabbarList: tabbarList
|
|
|
});
|
|
|
}
|
|
|
});
|