const _Http = getApp().globalData.http, currency = require("../../../../utils/currency"), CNY = value => currency(value, { symbol: "¥", precision: 2 }).format(); Component({ properties: { disabled: { type: Boolean }, //禁用 }, options: { addGlobalClass: true }, data: { sa_salesforecastbillid: 0, list: [], sa_projectid: 0, allinvoiceamount: "", alloutamount: "", "content": { "nocache": true, "pageNumber": 1, "pageTotal": 1, "pageSize": 20, "type": 2, // 1 订单 2项目 3客户 "total": null, "where": { "condition": "" } }, }, lifetimes: { attached: function () { getApp().globalData.Language.getLanguagePackage(this) } }, methods: { getList(id, init) { let content = this.data.content; content.sa_salesforecastbillid = id; if (init) content.pageNumber = 1 _Http.basic({ "id": 20230705145504, content }).then(res => { console.log("预测项目列表", res) if (res.code != '1') return wx.showToast({ title: res.data, icon: "none" }) content.total = res.total; content.pageNumber = res.pageNumber + 1; content.pageTotal = res.pageTotal; res.data = res.data.map(v => { v.signamount_due = CNY(v.signamount_due); return v }) this.setData({ list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data), sa_salesforecastbillid: id, content }); if (res.data.length) { this.setData({ allinvoiceamount: CNY(res.data[0].allinvoiceamount), alloutamount: CNY(res.data[0].alloutamount), }) } }) }, add() { wx.navigateTo({ url: `/packageA/select/project/select2?params=${JSON.stringify({ "id": 20230705145604, "content": { nocache: true, "sa_salesforecastbillid": this.data.sa_salesforecastbillid, "where": { "condition": "" } } })}`, }) getApp().globalData.handleSelect = this.handleAdd.bind(this); }, handleAdd({ result }) { const that = this; wx.showModal({ title: getApp().globalData.Language.getMapText('提示'), content: getApp().globalData.Language.joint([{ t: 1, v: '是否确认添加', r: " " }, { v: result.length, r: " " }, { t: 1, v: '个项目', r: "?" }]), cancelText: getApp().globalData.Language.getMapText('取消'), confirmText: getApp().globalData.Language.getMapText('确定'), complete: (res) => { if (res.confirm) _Http.basic({ "id": 20230705145104, "content": { "sa_salesforecastbillid": that.data.sa_salesforecastbillid, "ownertable": "sa_project", // sa_order 订单 sa_project 项目 sa_customers 客户 "salesforecastproject": result.map(v => { return { "sa_salesforecastprojectid": 0, "ownerid": v, discountrate: 1 } }) } }).then(res => { console.log("添加项目", res) wx.showToast({ title: res.code == '1' ? getApp().globalData.Language.getMapText('添加成功') : res.msg, icon: "none" }); getCurrentPages()[getCurrentPages().length - 2].getDetail(); if (res.code == '1') { that.getList(that.data.sa_salesforecastbillid, true) setTimeout(() => { wx.navigateBack() }, 300) } }) } }) }, deleteItem(e) { const { item } = e.currentTarget.dataset, that = this; wx.showModal({ title: getApp().globalData.Language.getMapText('提示'), content: getApp().globalData.Language.getMapText('是否确定删除') + `"${item.projectname}"` + getApp().globalData.Language.getMapText('项目'), cancelText: getApp().globalData.Language.getMapText('取消'), confirmText: getApp().globalData.Language.getMapText('确定'), complete: (res) => { if (res.confirm) _Http.basic({ "id": 20230705145304, "content": { "sa_salesforecastbillid": that.data.sa_salesforecastbillid, "sa_salesforecastprojectids": [item.sa_salesforecastprojectid] } }).then(res => { console.log("删除项目", res) wx.showToast({ title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg, icon: "none" }); if (res.code == '1') that.updateList() }) } }) }, updateList(projectnum) { let content = JSON.parse(JSON.stringify(this.data.content)); if (projectnum) { content.where.condition = projectnum; content.pageSize = 1; } else { content.pageSize = (content.pageNumber - 1) * content.pageNumber; } content.pageNumber = 1; _Http.basic({ "id": 20230705145504, content }).then(res => { console.log("更新数据", res) if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" }) res.data = res.data.map(v => { v.signamount_due = CNY(v.signamount_due); return v }) if (projectnum) { let index = this.data.list.findIndex(v => v.projectnum == projectnum); if (index != -1) this.setData({ [`list[${index}]`]: res.data[0] }) } else { this.setData({ list: res.data }) } this.setData({ allinvoiceamount: res.data.length ? CNY(res.data[0].allinvoiceamount) : "¥0.00", alloutamount: res.data.length ? CNY(res.data[0].alloutamount) : "¥0.00" }) }) getCurrentPages()[getCurrentPages().length - 1].getDetail(); }, onBlur(e) { const { item, name } = e.currentTarget.dataset; let value = e.detail.value; if (item[name] == value) return; item[name] = Number((value - 0).toFixed(2)) _Http.basic({ "id": 20230705145104, "content": { "sa_salesforecastbillid": this.data.sa_salesforecastbillid, "ownertable": "sa_project", // sa_order 订单 sa_project 项目 sa_customers 客户 "salesforecastproject": [{ "sa_salesforecastprojectid": item.sa_salesforecastprojectid, "ownerid": item.sa_projectid, "outamount": item.outamount, "invoiceamount": item.invoiceamount }] } }).then(res => { console.log("修改项目", res); wx.showToast({ title: res.code == '1' ? getApp().globalData.Language.getMapText('修改成功') : res.msg, icon: "none" }); if (res.code == '1') this.updateList(item.projectnum) }) } } })