Jelajahi Sumber

订单适配套餐逻辑

xiaohaizhao 11 bulan lalu
induk
melakukan
be4ebbb2fe

+ 84 - 60
packageA/activity/bindingProduct/index.js

@@ -27,6 +27,7 @@ Page({
     submitQty: 1,
   },
   onLoad(options) {
+    console.log(options)
     if (options.params) {
       let params = JSON.parse(options.params);
       if (!params.content.pageNumber || !params.content.pageTotal) {
@@ -49,9 +50,20 @@ Page({
         try {
           packageList = res.data.find(v => v.value == params.content.packagetype).subvalues
         } catch (error) {}
-        if (packageList.length) params.content.where.packagetypemx = packageList[0];
+        let getListPa = "";
+        if (options.getListPa) getListPa = JSON.parse(options.getListPa);
+        getListPa.content.pageNumber = 1;
+        getListPa.content.pageSize = 9999;
+        delete getListPa.content.pageTotal;
+        if (packageList.length) {
+          params.content.where.packagetypemx = packageList[0];
+          getListPa.content.where = {
+            packagetypemx: packageList[0]
+          }
+        }
         this.setData({
           params,
+          getListPa,
           butText: options.butText || '生成订单',
           packageList
         });
@@ -100,60 +112,77 @@ Page({
       })
     }.bind(this)
   },
-  getList(init = false) {
+  async getList(init = false) {
     //init 用于初始化分页
     if (init.detail != undefined) init = init.detail;
     let params = this.data.params;
     if (init) params.content.pageNumber = 1
     params.content.pageSize = 9999;
     if (params.content.pageNumber > params.content.pageTotal) return;
-    _Http.basic(params).then(res => {
-      console.log("选择产品列表", res)
-      this.selectComponent('#ListBox').RefreshToComplete();
-      this.selectComponent("#ListBox").setHeight(".search", this);
-      if (res.msg != '成功') return wx.showToast({
-        title: res.msg,
-        icon: "none"
-      })
-      const CNY = num => currency(num, {
-        symbol: "¥",
-        precision: 2
-      }).format();
-      let newPrice = this.data.newPrice,
-        oldPrice = this.data.oldPrice;
-      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");
-          if (image) {
-            try {
-              value.cover = image.subfiles.find(v => v.type == "thumbnail").url;
-            } catch (error) {
-              value.cover = image.url;
-            }
+
+    let res = {},
+      submitQty = 1,
+      CompleteCustomization = false;
+    if (this.data.getListPa) {
+      this.data.getListPa.content.where.packagetypemx = params.content.where.packagetypemx;
+      res = await _Http.basic(this.data.getListPa);
+      CompleteCustomization = true;
+      if (!res.data.length) {
+        res = await _Http.basic(params);
+        CompleteCustomization = false;
+      }
+    } else {
+      res = await _Http.basic(params);
+      console.log("params", res)
+    }
+    console.log("选择产品列表", res)
+    this.selectComponent('#ListBox').RefreshToComplete();
+    this.selectComponent("#ListBox").setHeight(".search", this);
+    if (res.msg != '成功') return wx.showToast({
+      title: res.msg,
+      icon: "none"
+    })
+    const CNY = num => currency(num, {
+      symbol: "¥",
+      precision: 2
+    }).format();
+    let newPrice = this.data.newPrice,
+      oldPrice = this.data.oldPrice;
+    if (res.data.length) submitQty = res.data[0].qty / res.data[0].orderminqty;
+    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");
+        if (image) {
+          try {
+            value.cover = image.subfiles.find(v => v.type == "thumbnail").url;
+          } catch (error) {
+            value.cover = image.url;
           }
         }
-        if (value.islimit == 0) value.groupqty = 0;
-        if (newPrice) value.newPrice = CNY(value[newPrice] || 0);
-        if (oldPrice) value.oldPrice = CNY(value[oldPrice] || 0);
-        //value.orderminqty = value.packageqty || value.orderminqty; 起订量优先取包装数量
-        if (!value.saledqty) value.saledqty = 0;
-        value.maxQty = value.groupqty == 0 ? "" : value.groupqty - value.saledqty; //有限购 设置最高可订购数量
-        value.qty = value.orderminqty;
-        if (value.iscustomsize) {
-          value.customText = getCustomText(value);
-        }
-        return value;
-      })
-      this.setData({
-        'params.content.pageNumber': res.pageNumber + 1,
-        'params.content.pageTotal': res.pageTotal,
-        'params.content.total': res.total,
-        list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
-        loading: false
-      })
-      this.handleSearch()
+      }
+      if (value.islimit == 0) value.groupqty = 0;
+      if (newPrice) value.newPrice = CNY(value[newPrice] || 0);
+      if (oldPrice) value.oldPrice = CNY(value[oldPrice] || 0);
+      //value.orderminqty = value.packageqty || value.orderminqty; 起订量优先取包装数量
+      if (!value.saledqty) value.saledqty = 0;
+      value.maxQty = value.groupqty == 0 ? "" : value.groupqty - value.saledqty; //有限购 设置最高可订购数量
+      value.qty = value.orderminqty;
+      if (value.iscustomsize) {
+        value.customText = getCustomText(value);
+        value.CompleteCustomization = CompleteCustomization;
+      }
+      return value;
+    })
+    this.setData({
+      'params.content.pageNumber': res.pageNumber + 1,
+      'params.content.pageTotal': res.pageTotal,
+      'params.content.total': res.total,
+      submitQty,
+      list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
+      loading: false
     })
+    this.handleSearch()
   },
   tabsChange(e) {
     this.setData({
@@ -171,21 +200,12 @@ Page({
   },
   /* 提交 */
   submit() {
-    let itemname = '';
-
-    let list = this.data.list.map(v => {
-      v.qty = v.qty * this.data.submitQty;
-      if (v.iscustomsize && itemname == '' && !v.CompleteCustomization) {
-        itemname = v.itemname
-      };
-      return v
-    })
-
-    if (itemname) {
+    const customsize = this.data.list.find(v => (v.iscustomsize && !v.CompleteCustomization));
+    if (customsize) {
       let that = this;
       return wx.showModal({
         title: '提示',
-        content: `请先完成"${itemname}"产品的定制化信息`,
+        content: `请先完成"${customsize.itemname}"产品的定制化信息`,
         // confirmText: "查看产品",
         showCancel: false,
         complete: ({
@@ -193,7 +213,7 @@ Page({
         }) => {
           if (confirm) {
             /* that.setData({
-              condition: itemname
+              condition: customsize.itemname
             })
             that.handleSearch() */
           }
@@ -212,7 +232,11 @@ Page({
         return;
       }
       getApp().globalData.handleSelect && getApp().globalData.handleSelect({
-        list
+        list: this.data.list.map(v => {
+          v.qty = v.qty * this.data.submitQty;
+          console.log(this.data.submitQty);
+          return v
+        })
       }).then(res => {
         resolve()
         this.setData({

+ 1 - 1
packageA/activity/bindingProduct/index.wxml

@@ -27,7 +27,7 @@
 				</view>
 				<view class="exp">特征码:{{item.signaturecode ||" --"}}</view>
 				<view class="exp">
-					包装数量:{{item.packageqty}} ({{item.unitname}})
+					包装数量:{{item.packageqty}} ({{item.unitname || item.unit}})
 				</view>
 				<view class="exp">可购数量:{{item.groupqty==0?'不限购':(item.groupqty-item.saledqty)<=0?'已售罄':item.maxQty}} </view>
 				</view>

+ 1 - 1
packageA/orderForm/detail.wxml

@@ -65,7 +65,7 @@
 </view>
 <view style="height: 20rpx;" />
 <Yl_FunTabs list='{{tabsList}}' active='{{tabsActive}}' bind:onChenge="tabsChange">
-    <Product slot='产品明细' privacyFieldC='{{privacyFieldC}}' id='Product' disabled="{{detail.status!='新建'}}" sa_order_v='{{detail.sa_order_v}}' bind:returnProductCount='getProductCount' />
+    <Product slot='产品明细' privacyFieldC='{{privacyFieldC}}' id='Product' disabled="{{detail.status!='新建'}}" packagetype='{{detail.packagetype}}' sa_order_v='{{detail.sa_order_v}}' bind:returnProductCount='getProductCount' />
     <Yl_Attachment slot='附件' id='Yl_Attachment' ownertable="sa_order" ownerid="{{detail.sa_orderid}}" disabled="{{detail.status!='新建'}}" />
     <Progress slot='订单进度' id='Progress' hidePrice='{{hidePrice.hidePrice("订单进度",privacyFieldC)}}' />
     <Consignment slot='出库单' id='Consignment' />

+ 105 - 80
packageA/orderForm/modules/product/index.js

@@ -22,7 +22,10 @@ Component({
         },
         privacyFieldC: {
             type: Array
-        }
+        },
+        packagetype: {
+            type: String
+        },
     },
     data: {
         content: {
@@ -129,7 +132,7 @@ Component({
             let that = this;
             wx.showModal({
                 title: '提示',
-                content: `是否确认删除“${detail.itemname}”?`,
+                content: that.data.packagetype ? '该商品为套餐商品,删除后该套餐下的商品会全部删除,确定删除嘛?' : `是否确认删除“${detail.itemname}”?`,
                 complete: (res) => {
                     if (res.confirm) _Http.basic({
                         "id": 20221109093702,
@@ -145,32 +148,59 @@ Component({
                             title: res.msg,
                             icon: "none"
                         });
-                        that.setData({
-                            list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
-                        });
-                        this.triggerEvent("returnProductCount", this.data.content.total - 1)
-                        this.updateThePrice();
+                        if (that.data.packagetype) {
+                            that.getList(sa_orderid, true)
+                        } else {
+                            that.setData({
+                                list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
+                            });
+                            that.triggerEvent("returnProductCount", that.data.content.total - 1)
+                        }
+                        that.updateThePrice();
                     })
                 }
             })
         },
         /* 去添加产品 */
         addProduct() {
-            let detail = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail,
-                id = '';
-            switch (detail.type) {
-                case '促销订单':
-                    id = 20230107182302;
-                    break;
-                case '标准订单':
-                    id = 20221109153502;
-                    break;
-                case '特殊订单':
-                    id = 20221109153502;
-                    break;
-            }
-            wx.navigateTo({
-                url: `${detail.type=='促销订单'?'/packageA/activity/selectProduct/index':'/select/product/index'}?params=${JSON.stringify({
+            if (this.data.packagetype) {
+                wx.navigateTo({
+                    url: '/packageA/activity/bindingProduct/index?params=' + JSON.stringify({
+                        "id": 20230107182302,
+                        "version": 1,
+                        "content": {
+                            nocache: true,
+                            sa_orderid, //订单ID
+                            packagetype: this.data.packagetype,
+                            "where": {
+                                "condition": "",
+                                packagetypemx: "",
+                            }
+                        }
+                    }) + "&butText=添加套餐&getListPa=" + JSON.stringify({
+                        "id": "20221109093902",
+                        content: this.data.content
+                    }),
+                });
+
+                getApp().globalData.handleSelect = this.handleInsert.bind(this);
+
+            } else {
+                let detail = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail,
+                    id = '';
+                switch (detail.type) {
+                    case '促销订单':
+                        id = 20230107182302;
+                        break;
+                    case '标准订单':
+                        id = 20221109153502;
+                        break;
+                    case '特殊订单':
+                        id = 20221109153502;
+                        break;
+                }
+                wx.navigateTo({
+                    url: `${detail.type=='促销订单'?'/packageA/activity/selectProduct/index':'/select/product/index'}?params=${JSON.stringify({
 					"id":id,
 					"content": {
 						nocache:true,
@@ -181,16 +211,17 @@ Component({
 						}
 					}
 				})}&butText=添加产品`
-            });
-            this.setData({
-                type: detail.type
-            })
-            getApp().globalData.handleSelect = this.handleSelect.bind(this);
+                });
+                this.setData({
+                    type: detail.type
+                })
+                getApp().globalData.handleSelect = this.handleSelect.bind(this);
+            }
+
         },
         /* 处理新增产品 */
         handleSelect(detail) {
             let that = this;
-
             _Http.basic({
                 "id": 2024020201095102,
                 "content": {
@@ -203,7 +234,6 @@ Component({
                     title: res.msg,
                     icon: "none"
                 });
-
                 if (res.data.items.length) {
                     if (res.data.isrepeat) {
                         wx.showModal({
@@ -231,63 +261,58 @@ Component({
                     title: '提示',
                     content: `是否确认添加${detail.result.length}件商品?`,
                     complete: (res) => {
-                        if (res.confirm) _Http.basic({
-                            "id": 20221109093602,
-                            content: {
-                                ...that.data.base,
-                                "items": detail.list.map(v => {
-                                    return {
-                                        sa_orderitemsid: 0,
-                                        "itemid": v.itemid, //商品ID
-                                        "qty": v.qty, //数量
-                                        "width": v.width || 0,
-                                        "length": v.length || 0,
-                                        price: that.data.type == '工具订单' ? v.marketprice : v.contractprice,
-                                        sa_promotion_itemsid: v.sa_promotion_itemsid || 0
-                                    }
-                                })
-                            }
-                        }).then(s => {
-                            console.log('新增产品', s)
-                            wx.showToast({
-                                title: s.msg == '成功' ? '添加成功' : s.msg,
-                                icon: "none"
-                            });
-                            if (s.msg == '成功') setTimeout(() => {
-                                that.getList(sa_orderid, true);
-                                wx.navigateBack();
-                                that.updateThePrice();
-                            }, 300)
-                        })
+                        if (res.confirm) that.handleInsert(detail).bind(that)
                     }
                 });
             }
-
-
         },
+        handleInsert({
+            list
+        }) {
+            return new Promise((resolve) => {
+                _Http.basic({
+                    "id": 20221109093602,
+                    content: {
+                        ...this.data.base,
+                        "items": list.map(v => {
+                            return {
+                                sa_orderitemsid: v.sa_orderitemsid || 0,
+                                itemid: v.itemid, //商品ID
+                                qty: v.qty, //数量
+                                width: v.width || 0,
+                                length: v.length || 0,
+                                cheek: v.cheek,
+                                color: v.color,
+                                material: v.material,
+                                spec: v.spec,
+                                custom: v.custom,
+                                price: this.data.type == '工具订单' ? v.marketprice : v.contractprice,
+                                sa_promotion_itemsid: v.sa_promotion_itemsid || 0
+                            }
+                        })
+                    }
+                }).then(s => {
+                    console.log('新增产品', s)
+                    resolve(s.msg == '成功')
+                    wx.showToast({
+                        title: s.msg == '成功' ? '操作成功' : s.msg,
+                        icon: "none",
+                        mask: s.msg == '成功'
+                    });
+                    if (s.msg == '成功') {
+                        this.getList(sa_orderid, true);
+                        this.updateThePrice();
+                        setTimeout(() => {
+                            wx.navigateBack();
+                        }, 300)
+                    }
+                })
+            })
+        },
+
         /* 使用接口更新总价 */
         updateThePrice() {
-            // _Http.basic({
-            //     "id": 20230105101102,
-            //     "content": {
-            //         sa_orderid
-            //     },
-            // }).then(res => {
-            //     console.log("修改列表总价", res)
-            //     if (res.msg != '成功') return wx.showToast({
-            //         title: `产品总价更新失败`,
-            //         icon: "none"
-            //     });
-            //     let page = getCurrentPages()[getCurrentPages().length - 1];
-            //     if (page) {
-            //         this.setData({
-            //             "detail.amount": CNY(res.data.amount)
-            //         })
-            //         page.setLogisticsMsg();
-            //     }
-            // })
-            let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail');
-            page.getDetail();
+            getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').getDetail();
         }
     }
 })

+ 1 - 1
packageA/orderForm/modules/product/index.wxml

@@ -6,4 +6,4 @@
     </navigator>
   </view>
 </view>
-<List list='{{list}}' privacyFieldC="{{privacyFieldC}}" disabled='{{disabled}}' bindchangeProduct='changeProduct' binddeleteItem="deleteItem" />
+<List list='{{list}}' packagetype="{{packagetype}}" privacyFieldC="{{privacyFieldC}}" disabled='{{disabled}}' bindchangeProduct='changeProduct' binddeleteItem="deleteItem" />

+ 9 - 23
packageA/orderForm/modules/product/list/index.js

@@ -16,7 +16,10 @@ Component({
 		},
 		privacyFieldC: {
 			type: Array
-		}
+		},
+		packagetype: {
+			type: String
+		},
 	},
 	options: {
 		addGlobalClass: true
@@ -28,7 +31,6 @@ Component({
 				name,
 				index
 			} = e.currentTarget.dataset;
-			console.log(e)
 			if (name == 'qty') {
 				if (data.orderminqty > e.detail.value) {
 					wx.showToast({
@@ -64,27 +66,14 @@ Component({
 				saleprice: data.saleprice,
 				defaultprice: data.defaultprice,
 				sa_promotion_itemsid: data.sa_promotion_itemsid || 0,
+				cheek: v.cheek,
+				color: v.color,
+				material: v.material,
+				spec: v.spec,
+				custom: v.custom,
 				// sa_orderitems_v: data.sa_orderitems_v || "",
 				index
 			})
-			//
-		},
-		changeDate(e) {
-			let {
-				data
-			} = e.currentTarget.dataset;
-			this.triggerEvent("changeProduct", {
-				sa_orderitemsid: data.sa_orderitemsid,
-				itemid: data.itemid,
-				qty: data.qty,
-				remarks: data.remarks,
-				needdate: e.detail.value || "",
-				deliverydate: data.deliverydate || "",
-				price: currency(data.price).value,
-				defaultprice: data.defaultprice,
-				sa_promotion_itemsid: data.sa_promotion_itemsid || 0,
-				// sa_orderitems_v: data.sa_orderitems_v || ""
-			})
 		},
 		deleteProduct(e) {
 			this.triggerEvent("deleteItem", e.currentTarget.dataset.item)
@@ -94,9 +83,6 @@ Component({
 				title: '当前状态不可编辑!',
 				icon: "none"
 			})
-		},
-		customization() {
-
 		}
 	}
 })

+ 1 - 1
packageA/orderForm/modules/product/list/index.wxml

@@ -38,7 +38,7 @@
         <view class="row">
             <view>
                 <view class="label">数量<text wx:if="{{item.auxunit}}">({{item.auxunit}})</text>:</view>
-                <input disabled='{{disabled}}' bindtap="isEdit" class="input" style="width: 180rpx;" type="digit" value="{{item.qty}}" data-index="{{index}}" data-name="qty" data-data="{{item}}" bindblur="onBlur" />
+                <input disabled='{{disabled || packagetype}}' bindtap="isEdit" class="input" style="width: 180rpx;" type="digit" value="{{item.qty}}" data-index="{{index}}" data-name="qty" data-data="{{item}}" bindblur="onBlur" />
             </view>
             <view class="money">
                 金额:<text>{{handleHide.verify(item.showAmount,"产品明细",privacyFieldC)}}元</text>

+ 7 - 0
project.private.config.json

@@ -10,6 +10,13 @@
   "condition": {
     "miniprogram": {
       "list": [
+        {
+          "name": "套餐订单",
+          "pathName": "packageA/orderForm/detail",
+          "query": "id=343021",
+          "launchMode": "default",
+          "scene": null
+        },
         {
           "name": "选择套餐",
           "pathName": "packageA/activity/bindingProduct/index",