const _Http = getApp().globalData.http; Page({ data: { pickerIndex: 0, showText: "全部", popupShow: false, activeId: null, mainActiveIndex: 0, active: "业绩目标", targetYear: null, hrid: null, sa_saleareaid: null, "year": new Date().getFullYear().toString(), "content": { "nocache": true, "year": new Date().getFullYear().toString(), //年 "targettype": "人员目标", //1 "type": 1, // "where": { "condition": "" } }, target: null, //目标 showActions: false, actionSheet: "开票金额", actions: [{ name: getApp().globalData.Language.getMapText('开票金额'), value: "1" }, { name: getApp().globalData.Language.getMapText('订单金额'), value: "2" }, { name: getApp().globalData.Language.getMapText('出货金额'), value: "3" }, { name: getApp().globalData.Language.getMapText('回款金额'), value: "4" }], }, onLoad(options) { getApp().globalData.Language.getLanguagePackage(this, '销售目标'); let wtarget = wx.getStorageSync('auth').target.optionnames.filter(v => v != "查询") if (wtarget.length == 0) { wx.showModal({ content: getApp().globalData.Language.getMapText('未获取到应用权限'), showCancel: false }) setTimeout(() => { wx.navigateBack() }, 1000); return } this.setData({ wtarget, "content.targettype": wtarget[0] == '业绩目标' ? '人员目标' : '项目目标', active: wtarget[0] }) /* 获取部门列表 */ _Http.basic({ "id": 20220922113302, "content": { pageSize: 9999 } }).then(res => { if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" }) let hrList = res.data.map(v => { v.hr.unshift({ name: v.depname + ' (包含所有下级)', hrid: v.sa_saleareaid }) return { id: v.sa_saleareaid, text: v.depname, children: v.hr.map(value => { const text = value.position ? value.name + ` (${value.position})` : value.name; if (value.hrid == wx.getStorageSync('userMsg').hrid) this.setData({ hrid: value.hrid, activeId: value.hrid, text: value.name, showText: value.name }) return { id: value.hrid, text } }) } }) this.setData({ hrList }) }); this.getYear(true) }, getYear(init = false) { /* 获取年份 */ _Http.basic({ "id": 20230728090204, "content": { "targettype": "人员目标", type: 1, } }).then(res => { console.log("人员开启年度", res) if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" }) let UYL = {}; res.data.forEach(v => UYL[v.year] = v.status) this.setData({ userYearList: res.data.map(v => v.year), UYL, "content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year, pickerIndex: res.data.length - 1 }) if (init) this.getData(); }) /* 获取年份 */ _Http.basic({ "id": 20230728090204, "content": { "targettype": "项目目标", type: 1, } }).then(res => { console.log('项目开启年度', res) if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" }) let PYL = {}; res.data.forEach(v => PYL[v.year] = v.status) this.setData({ projectYearList: res.data.map(v => v.year), PYL }) }) }, onShow() { this.getData(); }, onClickNav({ detail }) { this.setData({ mainActiveIndex: detail.index }) }, onClickItem({ detail }) { let hrid = null, sa_saleareaid = null; if (detail.text.includes('包含所有下级')) { sa_saleareaid = detail.id } else { hrid = detail.id }; let text = detail.text.split("(")[0]; this.setData({ hrid, sa_saleareaid, activeId: detail.id, text }) }, /* 切换分析对象 */ openPupop() { this.setData({ popupShow: true }) }, onClose() { this.setData({ popupShow: false }) }, toDetail() { if (this.data.active == "业绩目标") { wx.navigateTo({ url: `./person?year=${this.data.content.year}&yearArr=${this.data.userYearList}&pickerIndex=${this.data.pickerIndex}&UYL=${JSON.stringify(this.data.UYL)}` }) } else { wx.navigateTo({ url: `./project?year=${this.data.content.year}&yearArr=${this.data.projectYearList}&pickerIndex=${this.data.pickerIndex}&PYL=${JSON.stringify(this.data.PYL)}` }) } }, getData(e) { if (e) this.setData({ showText: this.data.text ? this.data.text : '全部' }) let content = this.data.content; if (this.data.hrid) content.hrid = this.data.hrid; if (this.data.sa_saleareaid) content.sa_saleareaid = this.data.sa_saleareaid; _Http.basic({ "id": 20220920133102, content }).then(res => { console.log("获取数据", res) this.onClose() if (res.code != '1') return wx.showToast({ title: res.data, icon: "none" }) let lineData = [], histogram = []; res.data.month.forEach(v => { lineData = lineData.concat([{ label: v.month + getApp().globalData.Language.getMapText('月'), value: v.l, type: getApp().globalData.Language.getMapText('基本目标金额') }, { label: v.month + getApp().globalData.Language.getMapText('月'), value: v.h, type: getApp().globalData.Language.getMapText('挑战目标金额') }, { label: v.month + getApp().globalData.Language.getMapText('月'), value: v.a, type: getApp().globalData.Language.getMapText('实际订单金额') } ]) histogram = histogram.concat([{ label: v.month + getApp().globalData.Language.getMapText('月'), value: v.pl, type: getApp().globalData.Language.getMapText('基础目标实际完成率') }, { label: v.month + getApp().globalData.Language.getMapText('月'), value: v.ph, type: getApp().globalData.Language.getMapText('挑战目标实际完成率') } ]) }); //绘制线图 this.selectComponent("#line").render(lineData); // this.selectComponent("#histogram").render(histogram); this.setData({ targetYear: { yl: res.data.y1l, yh: res.data.y1h, ya: res.data.y1a, jl: (res.data.y1a == 0 || res.data.y1l == 0) ? '0.00%' : res.data.y1l == 0 ? res.data.y1a + '%' : (res.data.y1a / res.data.y1l * 100).toFixed(2) + '%' } }); if (this.data.year == this.data.content.year) { const m = new Date().getMonth() + 1; let s = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12] ].findIndex(v => v.some(va => va == m)) + 1; this.setData({ targetSeason: { sl: res.data[`s${s}l`], sh: res.data[`s${s}h`], sa: res.data[`s${s}a`], jl: (res.data[`s${s}a`] == 0 || res.data[`s${s}l`] == 0) ? '0.00%' : res.data[`s${s}l`] == 0 ? res.data[`s${s}a`] + '%' : (res.data[`s${s}a`] / res.data[`s${s}l`] * 100).toFixed(2) + '%' }, targetMonth: { ml: res.data[`m${m}l`], mh: res.data[`m${m}h`], ma: res.data[`m${m}a`], jl: (res.data[`m${m}a`] == 0 || res.data[`m${m}l`] == 0) ? '0.00%' : res.data[`m${m}l`] == 0 ? res.data[`m${m}a`] + '%' : (res.data[`m${m}a`] / res.data[`m${m}l`] * 100).toFixed(2) + '%' } }) } }) }, /* 弹出选择 */ select({ detail }) { if (this.data.actionSheet == detail.name) return; this.setData({ actionSheet: detail.name, "content.type": detail.value, showActions: false }); this.getData(); }, cancelActions() { this.setData({ showActions: false }) }, openActions() { this.setData({ showActions: true }) }, /* 选择年份 */ bindDateChange({ detail }) { let index = detail.value; let year = this.data.active == '业绩目标' ? this.data.userYearList[index] : this.data.projectYearList[index]; if (year == detail.value) return; this.setData({ "content.year": year, pickerIndex: index }); this.getData(); }, /* tabs切换 */ tabsChange({ detail }) { let year = this.data.content.year; if (detail.title == '业绩目标') { let i = this.data.userYearList.findIndex(v => year == v) if (i == -1) { this.setData({ "content.year": this.data.userYearList[this.data.userYearList.length - 1], pickerIndex: this.data.userYearList.length - 1 }) } else { this.setData({ pickerIndex: i }) } } else { let i = this.data.projectYearList.findIndex(v => year == v); if (i == -1) { this.setData({ "content.year": this.data.projectYearList[this.data.projectYearList.length - 1], pickerIndex: this.data.projectYearList.length - 1 }) } else { this.setData({ pickerIndex: i }) } } console.log(detail.name) this.setData({ "content.targettype": detail.name == '业绩目标' ? '人员目标' : '项目目标', active: detail.name }); this.getData(); } })