| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- const _Http = getApp().globalData.http,
- currency = require("../../../../utils/currency"),
- file = require("../../../../utils/matchingFeilType"),
- CNY = value => currency(value, {
- symbol: "¥",
- precision: 2
- }).format();
- Component({
- properties: {
- disabled: {
- type: Boolean
- },
- toAdd: {
- type: Function
- }
- },
- options: {
- addGlobalClass: true
- },
- lifetimes: {
- attached: function () {
- getApp().globalData.Language.getLanguagePackage(this)
- }
- },
- data: {
- sa_salesforecastbillid: 0,
- list: [],
- sa_projectid: 0,
- "content": {
- "nocache": true,
- pageSize: 9999,
- "total": null,
- "where": {
- "condition": ""
- }
- },
- project: null
- },
- methods: {
- getList(id, init, update = false) {
- let content = this.data.content;
- content.sa_salesforecastbillid = id;
- content.where.condition = update ? this.data.project.projectnum : "";
- _Http.basic({
- "id": 20230705144904,
- content
- }).then(res => {
- console.log("预测项目列表", res)
- if (res.code != '1') return wx.showToast({
- title: res.data,
- icon: "none"
- })
- res.data = res.data.map(v => {
- v.zk = currency(v.discountrate).multiply(100).value;
- v.shouAmount = CNY(v.sumprojectamount)
- return v
- });
- if (update) {
- const index = this.data.list.findIndex(v => v.projectnum == this.data.project.projectnum);
- if (index != -1) {
- this.setData({
- [`list[${index}]`]: res.data[0],
- project: res.data[0]
- });
- this.getProduct();
- }
- } else {
- content.total = res.total;
- this.setData({
- list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
- content
- });
- if (res.data.length) {
- this.setData({
- sa_projectid: res.data[0].sa_projectid,
- project: res.data[0]
- });
- this.getProduct();
- } else {
- this.setData({
- sa_projectid: 0,
- project: null
- })
- }
- }
- this.setData({
- sa_salesforecastbillid: id
- })
- })
- },
- onChange({
- detail
- }) {
- this.setData({
- sa_projectid: detail.name,
- project: this.data.list[detail.index]
- });
- this.getProduct();
- },
- addProject() {
- this.triggerEvent("toAdd")
- },
- /* 折扣失焦 */
- onBlur(e) {
- let zk = e.detail.value,
- project = JSON.parse(JSON.stringify(this.data.project));
- if (zk > 100) {
- zk = 100
- } else if (zk < 0.01) {
- zk = project.zk;
- wx.showToast({
- title: getApp().globalData.Language.getMapText('折扣过小'),
- icon: "none"
- })
- }
- if (zk == project.zk) return;
- project.zk = currency(zk).multiply(1).value;
- project.discountrate = currency(zk, {
- precision: 4
- }).divide(100).value;
- _Http.basic({
- id: 20230705145104,
- content: {
- sa_salesforecastbillid: this.data.sa_salesforecastbillid,
- "ownertable": "sa_project",
- salesforecastproject: [{
- ownerid: project.sa_projectid,
- ownertable: "sa_project",
- discountrate: project.discountrate,
- sa_salesforecastprojectid: project.sa_salesforecastprojectid
- }]
- }
- }).then(res => {
- wx.showToast({
- title: res.code == '1' ? getApp().globalData.Language.getMapText('折扣修改成功') : res.msg,
- icon: "none"
- })
- if (res.code == '1') this.updateAmount();
- })
- },
- getProduct() {
- _Http.basic({
- "id": 20230705145004,
- "content": {
- nocache: true,
- "sa_salesforecastprojectid": this.data.project.sa_salesforecastprojectid,
- "sa_salesforecastbillid": this.data.project.sa_salesforecastbillid,
- pageSize: 9999,
- "where": {
- "condition": ""
- }
- }
- }).then(res => {
- if (res.code != '1') return wx.showToast({
- title: res.data,
- icon: "none"
- })
- console.log("产品", res)
- this.setData({
- productList: res.data.map(value => {
- if (value.attinfos.length != 0) {
- value.attinfos = file.fileList(value.attinfos)
- let image = value.attinfos.find(v => v.fileType == "image");
- value.cover = image ? image.cover : "";
- }
- value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
- value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
- value.showMP = CNY(value.marketprice)
- value.showOrderamount = CNY(value.orderamount)
- return value
- })
- })
- })
- },
- toAddProduct() {
- let project = this.data.project;
- wx.navigateTo({
- url: `/packageA/select/product/select?params=${JSON.stringify({
- "accesstoken": "1ede5d2594d778a5e652b5a267c90308",
- "id": 20230705145704,
- "content": {
- "pageNumber": 1,
- "pageSize": 20,
- "sa_salesforecastbillid":project.sa_salesforecastbillid,
- "sa_salesforecastprojectid":project.sa_salesforecastprojectid,
- "sa_projectid":project.sa_projectid,
- "where": {
- "condition": ""
- }
- }
- })}`,
- });
- getApp().globalData.handleSelect = this.handleAdd.bind(this);
- },
- handleAdd({
- list
- }) {
- let that = this,
- project = this.data.project;
- console.log(list)
- wx.showModal({
- title: getApp().globalData.Language.getMapText('提示'),
- content: getApp().globalData.Language.joint([{
- t: 1,
- v: '是否确认添加',
- r: " "
- }, {
- v: list.length,
- r: " "
- }, {
- t: 1,
- v: '件产品',
- r: "?"
- }]),
- cancelText: getApp().globalData.Language.getMapText('取消'),
- confirmText: getApp().globalData.Language.getMapText('确定'),
- complete: (res) => {
- if (res.confirm) _Http.basic({
- "id": 20230705145204,
- "content": {
- "sa_salesforecastbillid": project.sa_salesforecastbillid,
- "sa_salesforecastprojectid": project.sa_salesforecastprojectid,
- "salesforecast": list.map(v => {
- return {
- "itemid": v.itemid,
- "orderqty": v.qty,
- "orderamount": v.qty * v.price,
- "price": v.price,
- "sa_salesforecastid": 0
- }
- })
- }
- }).then(res => {
- console.log("添加产品", res)
- if (res.code != '1') return wx.showToast({
- title: res.data,
- icon: "none"
- });
- wx.showToast({
- title: getApp().globalData.Language.getMapText('添加成功'),
- icon: "none",
- mask: true
- });
- setTimeout(() => {
- wx.navigateBack()
- that.updateAmount()
- }, 300)
- })
- }
- })
- },
- /* 更新金额 */
- updateAmount() {
- const page = getCurrentPages().find(v => v.__route__ == 'packageA/finishforecast/detail');
- if (page) page.getDetail();
- this.getList(this.data.sa_salesforecastbillid, true, true)
- },
- }
- })
|