const _Http = getApp().globalData.http; Page({ data: { isAdmin: getApp().globalData.auth.wcontract.options.some(v => v == "admin"), //是否具有管理权限 isLeader: false, //是否为负责人 options: getApp().globalData.auth.wcontract.options, //权限列表 tabsActive: 0, //tabs 选中项 sa_contractid: "", tabsList: [{ label: "详细信息", num: 132 }], tabbarList: [{ icon: "icon-genjin", label: "跟进" }], }, onLoad(options) { this.setData({ sa_contractid: options.sa_contractid }); this.getDetail(); }, getDetail() { _Http.basic({ "id": 20221121195102, "content": { nocache: true, "sa_contractid": this.data.sa_contractid }, }).then(res => { console.log("合同详情", res) if (res.msg != '成功') return wx.showToast({ title: res.msg, icon: "none" }); let isLeader = res.data.leader.some(some => some.userid == wx.getStorageSync('userMsg').userid), tabbarList = this.data.tabbarList; if (this.data.isAdmin) tabbarList = [{ icon: "icon-genjin", label: "审核" }, { icon: "icon-genjin", label: "反审核" }].concat(tabbarList); if (isLeader || this.data.isAdmin) tabbarList = tabbarList.concat([{ icon: "icon-genjin", label: "提交" }, { icon: "icon-genjin", label: "终止" }, { icon: "icon-zhuanyi", label: "更换负责人" }, { icon: "icon-shanchu", label: "作废" }]) let data = res.data, tabsList = this.data.tabsList, tabsActive = 0; switch (data.type) { case "框架": data.type = '经销商合作协议' tabsList = tabsList.concat([{ label: "产品明细折扣", num: 132 }, { label: "产品类型折扣", num: 132 }, { label: "跟进动态", num: 132 }]); tabsActive = 1; break; case "工具借用": data.type = '工具使用(借出)协议' tabsList = tabsList.concat([{ label: "工具清单", num: 132 }, { label: "跟进动态", num: 132 }]); tabsActive = 1; break; case "居间": data.type = '居间协议' break; case "项目": /* { label: "合同条款", num: 132 }, */ data.type = data.typemx + '项目协议' tabsList = tabsList.concat([{ label: "产品清单", num: 132 }, { label: "跟进动态", num: 132 }]); tabsActive = 1; break; default: result = '--' break; }; this.setDetail(data); this.setData({ isLeader, tabbarList, detail: data, list2: [{ label: "创建人", value: data.createby }, { label: "创建时间", value: data.createdate }, { label: "最近编辑人", value: data.changeby }, { label: "最近编辑时间", value: data.changedate }, { label: "最近跟进人", value: data.followby }, { label: "最近跟进时间", value: data.followdate }], tabsList, tabsActive }); /* 更新列表数据 */ let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/index'); if (page) { let i = page.data.list.findIndex(v => v.sa_contractid == this.data.sa_contractid); if (i != -1) page.setData({ [`list[${i}].status`]: res.data.status }) } this.getTags(); this.getGroup(); this.partialRenewal(); }) }, /* 设置详情信息 */ setDetail(data) { let briefs = [{ label: "合同编号", value: data.billno }, { label: "合同类型", value: data.type }, { label: "经销商", value: data.enterprisename }, { label: "整体折扣", value: data.discountrate }, { label: "签约时间", value: data.signdate }, { label: "状态", value: data.status }], list1 = [{ label: "合同标题", value: data.title }, { label: "合同编号", value: data.billno }, { label: "合同类型", value: data.type }, { label: "合同模板", value: data.type }, { label: "负责人", value: data.leader[0].name }, { label: "合同有效期", value: data.begdate + ' 至 ' + data.enddate }, { label: "签约时间", value: data.signdate }, { label: "合同描述", value: data.remarks } ]; if (data.typemx) { briefs.splice(5, 0, { label: "签约金额", value: data.signamount }) briefs.splice(4, 0, { label: "关联项目", value: data.projectname }) list1.splice(4, 0, { label: "关联项目", value: data.projectname }) list1.splice(7, 0, { label: "签约金额", value: data.signamount }) } else { switch (data.type) { case "居间协议": briefs.splice(2, 1, { label: "居间服务商", value: data.enterprisename }) briefs.splice(3, 0, { label: "关联项目", value: data.projectname }) briefs.splice(5, 0, { label: "佣金比例", value: data.kickback + '%' }) list1.splice(4, 0, { label: "居间服务商", value: data.enterprisename }) list1.splice(5, 0, { label: "关联项目", value: data.projectname }) list1.splice(8, 0, { label: "佣金比例", value: data.kickback + '%' }) break; case "工具使用(借出)协议": briefs.splice(2, 1, { label: "客户", value: data.enterprisename }) briefs.splice(3, 1) briefs.splice(4, 0, { label: "单套价格", value: data.signamount }) list1.splice(5, 0, { label: "客户", value: data.enterprisename }) list1.splice(8, 0, { label: "单套价格", value: data.signamount }) break; } } this.setData({ briefs, list1 }) }, //tabs 切换 tabsChange({ detail }) { this.setData({ tabsActive: detail }); this.partialRenewal(); }, //更新标签 getTags() { this.selectComponent("#Tags").getTags(); }, //更新团队成员 getGroup() { this.selectComponent("#Group").getList(); }, //局部数据更新 tabs partialRenewal(init = false) { let id = this.data.detail.sa_contractid; let model = ''; let name = this.data.tabsList[this.data.tabsActive].label; console.log(name) switch (name) { case "跟进动态": model = '#Trace' break; case "产品清单": model = '#Product' break; case "工具清单": model = '#Product' break; case "产品明细折扣": model = '#PiscountProduct' break; case "产品类型折扣": model = '#PiscountType' break; }; if (model) { // 确定好模块ID total = null 是第一次加载 加载数据 // init是新增或修改需要清数据 let Component = this.selectComponent(model); const { total, pageNumber, pageTotal } = Component.data.content; if (total == null || init) { Component.getList(id, init); } else if (pageNumber <= pageTotal) { Component.getList(id, false); } else { //用来判断 在搜索页面修改,与tabs选项不一致 但是切换到该选项 重置数据 } } }, onReachBottom() { this.partialRenewal(); }, //详情按钮回调 tabbarOnClick({ detail }) { let data = this.data.detail, that = this; switch (detail.label) { case "终止": wx.showModal({ title: '提示', content: `是否确定终止当前协议`, complete: (res) => { if (res.confirm) _Http.basic({ "id": 20221212102802, "content": { "sa_contractid": that.data.sa_contractid } }).then(res => { console.log("提交报价单", res) wx.showToast({ title: res.msg == '成功' ? "已终止" : res.msg, icon: "none" }) if (res.msg == '成功') setTimeout(() => { that.getDetail(); }, 300) }) } }) break; case "提交": if (data.status != '新建') return wx.showToast({ title: '当前状态不可提交!', icon: "none" }) wx.showModal({ title: '提示', content: `是否确定提交当前协议,提交后禁止使用部分功能`, complete: (res) => { if (res.confirm) _Http.basic({ "id": 20221121202802, "content": { "sa_contractids": [that.data.sa_contractid] } }).then(res => { console.log("提交报价单", res) wx.showToast({ title: res.msg == '成功' ? "提交成功" : res.msg, icon: "none" }) if (res.msg == '成功') setTimeout(() => { that.getDetail(); }, 300) }) } }) break; case "审核": if (data.status != '已提交') return wx.showToast({ title: '当前状态不可审核!', icon: "none" }) wx.showModal({ title: '提示', content: `是否通过当前协议`, complete: (res) => { if (res.confirm) _Http.basic({ "id": 20221121203102, "version": 1, "content": { "type": 1, //0:不通过,1:通过 "sa_contractids": [that.data.sa_contractid] } }).then(res => { console.log("审核合同", res) wx.showToast({ title: res.msg == '成功' ? "审核成功" : res.msg, icon: "none" }) if (res.msg == '成功') setTimeout(() => { that.getDetail(); }, 300) }) } }) break; case "反审核": if (data.status == '新建') return wx.showToast({ title: '当前状态不可反审核!', icon: "none" }) wx.showModal({ title: '提示', content: `是否退回当前协议`, complete: (res) => { if (res.confirm) _Http.basic({ "id": 20221212135402, "content": { "sa_contractid": that.data.sa_contractid, } }).then(res => { console.log("反审核合同", res) wx.showToast({ title: res.msg == '成功' ? "反审核成功" : res.msg, icon: "none" }) if (res.msg == '成功') setTimeout(() => { that.getDetail(); }, 300) }) } }) break; case "跟进": wx.navigateTo({ url: `/packageA/setclient/modules/trace/add/index?ownertable=sa_contract&ownerid=${data.sa_contractid}`, }) break; case "作废": wx.showModal({ title: '提示', content: '是否确认作废该协议?', complete: ({ confirm }) => { if (confirm) _Http.basic({ "id": 20221121202502, "version": 1, "content": { "sa_contractids": [this.data.detail.sa_contractid] } }).then(res => { wx.showToast({ title: res.msg == '成功' ? '已作废协议' : res.msg, icon: "none" }); if (res.msg == '成功') { setTimeout(() => { getCurrentPages().forEach(v => { if (v.__route__ == 'packageA/contract/index') { v.setData({ list: v.data.list.filter(value => value.sa_contractid != this.data.detail.sa_contractid), 'content.total': v.data.content.total - 1 }) } }) wx.navigateBack(); }, 300) } }) } }) break; case "更换负责人": wx.navigateTo({ url: `/pages/group/select?data=${JSON.stringify({ ownertable:"sa_contract", ownerid:data.sa_contractid, })}&radio=true&principal=true`, }) break; } }, /* 更换负责人 */ handelSubmit(arr) { const that = this; wx.showModal({ title: '提示', content: '是否确认更换负责人', complete: ({ confirm }) => { if (confirm) _Http.basic({ "id": 20220930103701, "content": { ownertable: "sa_contract", ownerid: that.data.detail.sa_contractid, userid: arr[0] } }).then(res => { console.log("更换负责人", res) if (res.msg != '成功') return wx.showToast({ title: res.data, icon: "none" }); wx.showToast({ title: '更换成功!', icon: "none" }); setTimeout(() => { that.getDetail(); wx.navigateBack(); }, 300) }) } }) }, onShareAppMessage() {} })