浏览代码

产品删除修改

zhaoxiaohai 3 年之前
父节点
当前提交
a08e0e73fb

+ 1 - 0
packageA/salesForecasting/detail.js

@@ -173,6 +173,7 @@ Page({
                     "id": 20220913154403,
                     "version": 1,
                     "content": {
+                        nocache: true,
                         "sa_salesforecastmodelid": that.data.detail.sa_salesforecastmodelid,
                         "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
                         sa_projectids

+ 83 - 7
packageA/salesForecasting/modules/project/index.js

@@ -1,4 +1,5 @@
-const _Http = getApp().globalData.http;
+const _Http = getApp().globalData.http,
+    file = require("../../../../utils/matchingFeilType");
 Component({
     data: {
         viewIndex: 0,
@@ -17,6 +18,8 @@ Component({
             "content": {
                 nocache: true,
                 "sa_salesforecastbillid": "",
+                pageNumber: 1,
+                pageTotal: 1,
                 "where": {
                     "condition": "",
                     "sa_projectid": ""
@@ -50,22 +53,39 @@ Component({
                         'param.content.where.sa_projectid': res.data[0].sa_projectid,
                         'param.content.sa_salesforecastbillid': id,
                     })
-                    this.getProduct();
+                    this.getProduct(true);
                 }
             })
         },
         /* 获取产品清单 */
-        getProduct() {
+        getProduct(init = false) {
             let param = this.data.param;
+            if (init) param.content.pageNumber = 1;
+            if (param.content.pageNumber > param.content.pageTotal) return;
             _Http.basic(param).then(res => {
                 console.log("产品列表", res)
                 if (res.msg != '成功') return wx.showToast({
                     title: res.msg,
                     icon: "none"
                 });
-                if (res.data.length == 1 && !res.data[0].itemname) res.data = [];
+                if (res.data.length == 1 && !res.data[0].itemname) {
+                    res.data = []
+                } else {
+                    res.data = 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);
+                        return value;
+                    })
+                }
                 this.setData({
-                    productList: res.data
+                    productList: res.pageNumber == 1 ? res.data : this.data.productList.concat(res.data),
+                    "param.content.pageNumber": res.pageNumber + 1,
+                    "param.content.pageTotal": res.pageTotal,
                 })
             })
         },
@@ -75,7 +95,7 @@ Component({
                 "param.content.where.sa_projectid": e.detail.name,
                 viewIndex: e.detail.index,
             });
-            this.getProduct();
+            this.getProduct(true);
         },
         /* 添加产品 */
         addProduct() {
@@ -121,12 +141,68 @@ Component({
                         })
                         if (res.msg != '成功') return;
                         setTimeout(() => {
-                            that.getProduct();
+                            that.getProduct(true);
                             wx.navigateBack();
                         }, 300)
                     })
                 }
             })
+        },
+        /* 生成修改队列 */
+        changeQueue({
+            detail
+        }) {
+            const that = this,
+                page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
+            _Http.basic({
+                "id": 20220906155003,
+                "version": 1,
+                "content": {
+                    "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
+                    "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
+                    "sa_projectid": that.data.param.content.where.sa_projectid,
+                    itemclassinfos: detail
+                }
+            }).then(res => {
+                console.log("项目修改产品", res)
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                })
+                let index = that.data.productList.findIndex(v => v.sa_salesforecastid == detail[0].sa_salesforecastid);
+                if (index != -1) that.data.productList[index] = {
+                    ...that.data.productList[index],
+                    ...detail[0]
+                }
+                that.setData({
+                    [`productList[${index}]`]: that.data.productList[index],
+                    [`productList[0].sumamount`]: res.data[0].sumamount,
+                })
+                console.log(that.data.productList[index])
+            })
+        },
+        /* 删除 */
+        deleteItem({
+            detail
+        }) {
+            _Http.basic({
+                "id": 20220906155103,
+                "version": 1,
+                "content": detail
+            }).then(res => {
+                console.log("删除产品", res);
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                });
+                this.setData({
+                    productList: this.data.productList.filter(v => v.sa_salesforecastid != detail.sa_salesforecastid)
+                });
+                wx.showToast({
+                    title: '删除成功',
+                    icon: "none"
+                })
+            })
         }
     }
 })

+ 2 - 2
packageA/salesForecasting/modules/project/index.wxml

@@ -2,11 +2,11 @@
     <van-tab title="{{item.projectname}}" wx:for="{{list}}" wx:key="index" name='{{item.sa_projectid}}' />
 </van-tabs>
 <view class="head">
-    <view class="count"><text style="margin-right: 15rpx; font-size: 30rpx;font-weight: 600; color: #333;">{{list[viewIndex].projectname}}</text>预测金额:<text style="color: #FF3B30;">¥99999999</text></view>
+    <view class="count"><text style="margin-right: 15rpx; font-size: 30rpx;font-weight: 600; color: #333;">{{list[viewIndex].projectname}}</text>预测金额:<text style="color: #FF3B30;">¥{{productList[0]?productList[0].sumamount:0}}</text></view>
     <view class="expand">
         <navigator url="#" class="but" bindtap="addProduct">
             <van-icon name="plus" />
         </navigator>
     </view>
 </view>
-<List list='{{productList}}' />
+<List list='{{productList}}' bindchangeQueue='changeQueue' binddeleteItem='deleteItem' />

+ 13 - 51
packageA/salesForecasting/modules/project/list/index.js

@@ -11,65 +11,23 @@ Component({
     methods: {
         onBlur(e) {
             let {
-                index,
-                name
+                index
             } = e.currentTarget.dataset,
-                detail = name == 'outqty' ? e.detail.value - 0 : (e.detail.value - 0).toFixed(2),
                 item = this.data.list[index];
-            switch (name) {
-                case "outqty":
-                    item.outqty = detail;
-                    //改变数量 现数量*现价
-                    item.outamount = (item.price * item.outqty).toFixed(2);
-                    break;
-                case "discountrate":
-                    if (detail >= 100) {
-                        item.discountrate = 100
-                    } else if (detail <= 0) {
-                        item.discountrate = 1
-                    } else {
-                        item.discountrate = detail;
-                    }
-                    //改变折扣 重新计算现价和总价
-                    item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
-                    item.outamount = (item.price * item.outqty).toFixed(2);
-                    console.log(item.price)
-                    break;
-                case "price":
-                    if (detail >= item.marketprice) {
-                        item.price = item.marketprice
-                    } else if (detail <= 0) {
-                        item.discountrate = 1;
-                        item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
-                    } else {
-                        item.price = detail;
-                    }
-                    //改变现价 重新计算总价和折扣
-                    item.outamount = (item.price * item.outqty).toFixed(2);
-                    item.discountrate = this.getPercent(item.price, item.marketprice).toFixed(2);
-                    break;
-            }
+            if (item.outqty == e.detail.value) return;
+            item.outqty = e.detail.value - 0;
+            item.outamount = (item.marketprice * item.outqty).toFixed(2);
             this.setData({
                 [`list[${index}]`]: item
             })
             let obj = {};
-            ["sa_quotedprice_itemsid", "itemid", "oldprice", "price", "discountrate", "outqty"].forEach(v => obj[v] = item[v]);
-            obj.discountrate = (obj.discountrate / 100).toFixed(4);
-            if (name != 'outqty') obj.price = 0;
-            this.triggerEvent("changeQueue", obj)
-        },
-        /* 计算百分比 */
-        getPercent(num, total) {
-            num = parseFloat(num);
-            total = parseFloat(total);
-            if (isNaN(num) || isNaN(total)) {
-                return "-";
-            }
-            return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100;
+            ["sa_salesforecastid", "itemid", "orderqty", "orderamount", "invoiceqty", "invoiceamount", "outqty", "outamount"].forEach(v => obj[v] = item[v]);
+            this.triggerEvent("changeQueue", [obj])
         },
         deleteProduct(e) {
             const {
-                sa_quotedprice_itemsid,
+                sa_salesforecastid,
+                sa_salesforecastbillid,
                 itemname
             } = e.currentTarget.dataset.item,
                 that = this;
@@ -79,7 +37,11 @@ Component({
                 complete: ({
                     confirm
                 }) => {
-                    if (confirm) that.triggerEvent("deleteItem", [sa_quotedprice_itemsid]);
+                    if (confirm) that.triggerEvent("deleteItem", {
+                        sa_salesforecastid,
+                        sa_projectid: 0,
+                        sa_salesforecastbillid
+                    });
                 }
             })
         },

+ 1 - 1
packageA/salesForecasting/modules/project/list/index.wxml

@@ -35,7 +35,7 @@
         <view class="row">
             <view style="margin-right: 40rpx;">
                 <view class="label">数量({{item.unitname}}):</view>
-                <input class="input" style="width: 180rpx;" type="digit" disabled="{{disabled}}" value="{{item.outqty}}" data-name="outqty" data-index="{{index}}" bindblur="onBlur" />
+                <input class="input" style="width: 180rpx;" type="digit" disabled="{{disabled}}" value="{{item.outqty}}" data-index="{{index}}" bindblur="onBlur" />
             </view>
             <view class="money">
                 金额:<text>¥{{item.outamount}}</text>