Explorar o código

Merge branch '促销购物车生成订单取消控制领域' into 楚楚/2.3.0

# Conflicts:
#	pages/index/collect/index.js
xiaohaizhao hai 1 ano
pai
achega
2b79428e3c

+ 63 - 52
packageA/activity/selectProduct/cart/index.js

@@ -15,6 +15,7 @@ Page({
 	data: {
 		list: [],
 		results: [], //选中结果
+		resultsList: [],
 		sa_brandid: null, //当前选中品牌id
 		classList: [], //生成订单时所选
 		sum: 0, //价格合
@@ -27,26 +28,6 @@ Page({
 		this.setData({
 			hidePrice: wx.getStorageSync('hidePrice'),
 		})
-		getApp().globalData.customizedProduct = (item, custom) => {
-			return new Promise((resolve) => {
-				_Http.basic({
-					"id": 20220924104302,
-					"content": {
-						"sa_shoppingcartid": item.sa_shoppingcartid,
-						"qty": item.qty,
-						...custom
-					},
-				}).then(res => {
-					console.log("修改定制", res)
-					wx.showToast({
-						title: res.msg != '成功' ? res.msg : '修改成功',
-						icon: "none"
-					});
-					this.getList()
-					resolve(true)
-				})
-			})
-		}
 	},
 	/* 获取列表 */
 	getList() {
@@ -77,11 +58,13 @@ Page({
 				let obj = allBrandList.find(s => s.sa_brandid == v.sa_brandid);
 				if (obj) {
 					obj.results.push(v.sa_shoppingcartid)
+					obj.resultsList.push(v)
 				} else {
 					allBrandList.push({
 						brandname: v.brandname,
 						sa_brandid: v.sa_brandid,
 						results: [v.sa_shoppingcartid],
+						resultsList: [v]
 					})
 				}
 				if (v.iscustomsize) v.customText = getCustomText(v);
@@ -92,28 +75,40 @@ Page({
 				allBrandList,
 				isGet: true
 			});
-			if (wx.getStorageSync('shopping1')) {
-				this.setData({
-					...wx.getStorageSync('shopping1')
-				});
-				this.computeSum();
-			}
+			if (wx.getStorageSync('shopping1')) this.setData({
+				...wx.getStorageSync('shopping1')
+			});
+			this.computeSum();
 		})
 	},
 	clickBut(e) {
-		this.data.classList.length >= 2 ? wx.showToast({
+		this.handleSubmit();
+		/* 	this.data.classList.length >= 2 ? wx.showToast({
 			title: '请选择订单领域(订单只允许同品牌/同领域的商品)',
 			icon: "none",
 			duration: 3000
 		}) : this.handleSubmit(0);
+ */
 	},
 	/* 提交 */
 	submit(e) {
-		this.handleSubmit(e.detail.value)
+		this.handleSubmit()
 	},
-	handleSubmit(index) {
-		let data = this.data.classList[index],
-			that = this;
+	handleSubmit() {
+		let that = this;
+		let items = that.data.resultsList.map(v => {
+			return {
+				"sa_orderitemsid": 0,
+				"itemid": v.itemid,
+				"sa_brandid": v.sa_brandid,
+				"qty": v.qty,
+				width: v.width || 0,
+				length: v.length || 0,
+				sa_shoppingcartid: v.sa_shoppingcartid || 0,
+				sa_promotion_itemsid: v.sa_promotion_itemsid
+			}
+		})
+		console.log("items", items)
 		wx.showModal({
 			title: '提示',
 			content: '是否确定生成促销订单',
@@ -129,20 +124,9 @@ Page({
 						"content": {
 							istool: 0,
 							type: "促销订单",
-							"tradefield": data.type, //必选
+							//"tradefield": data.type, 必选
 							...ids,
-							"items": data.list.map(v => {
-								return {
-									"sa_orderitemsid": 0,
-									"itemid": v.itemid,
-									"sa_brandid": v.sa_brandid,
-									"qty": v.qty,
-									width: v.width || 0,
-									length: v.length || 0,
-									sa_shoppingcartid: v.sa_shoppingcartid || 0,
-									sa_promotion_itemsid: v.sa_promotion_itemsid
-								}
-							})
+							items
 						}
 					}).then(res => {
 						console.log("转化订单", res)
@@ -154,6 +138,7 @@ Page({
 							icon: "none"
 						});
 						getApp().globalData.getCollectCount()
+						that.getList();
 						wx.showModal({
 							title: '提示',
 							content: '生成成功!是否立即前往',
@@ -165,10 +150,7 @@ Page({
 								}
 							}
 						});
-						that.getList();
 					})
-
-
 				}
 			}
 		})
@@ -181,20 +163,23 @@ Page({
 		if (isAll) {
 			this.setData({
 				sa_brandid: null,
-				results: []
+				results: [],
+				resultsList: []
 			})
 		} else {
 			//已选品牌产品情况下
 			if (this.data.sa_brandid) {
 				let obj = this.data.allBrandList.find(v => v.sa_brandid == this.data.sa_brandid)
 				this.setData({
-					results: obj.results
+					results: obj.results,
+					resultsList: obj.resultsList
 				})
 			} else {
 				if (this.data.allBrandList.length == 0) return;
 				this.setData({
 					sa_brandid: this.data.allBrandList[0].sa_brandid,
-					results: this.data.allBrandList[0].results
+					results: this.data.allBrandList[0].results,
+					resultsList: this.data.allBrandList[0].resultsList,
 				})
 			}
 		};
@@ -206,17 +191,21 @@ Page({
 			item
 		} = my ? e : e.currentTarget.dataset;
 		let results = this.data.results,
+			resultsList = this.data.resultsList,
 			sa_brandid = this.data.sa_brandid;
 		if (sa_brandid && sa_brandid != item.sa_brandid) return;
 		if (results.length == 0) {
 			results.push(item.sa_shoppingcartid);
+			resultsList.push(item)
 			sa_brandid = item.sa_brandid;
 		} else {
 			let index = results.findIndex(v => v == item.sa_shoppingcartid)
 			if (index == -1) {
 				results.push(item.sa_shoppingcartid);
+				resultsList.push(item)
 			} else {
 				results.splice(index, 1);
+				resultsList.splice(index, 1);
 				if (results.length == 0) sa_brandid = null;
 			}
 		};
@@ -230,18 +219,40 @@ Page({
 		const {
 			item
 		} = e.target.dataset;
+		getApp().globalData.customizedProduct = (item, custom) => {
+			return new Promise((resolve) => {
+				_Http.basic({
+					"id": 20220924104302,
+					"content": {
+						"sa_shoppingcartid": item.sa_shoppingcartid,
+						"qty": item.qty,
+						...custom
+					},
+				}).then(res => {
+					console.log("修改定制", res)
+					wx.showToast({
+						title: res.msg != '成功' ? res.msg : '修改成功',
+						icon: "none"
+					});
+					this.getList()
+					resolve(true)
+				})
+			})
+		}
 		if (item) this.selectComponent("#Custom").onClick(item)
 	},
 	/* 计算总价/产品领域分类 */
 	computeSum() {
 		let results = this.data.results,
+			resultsList = [],
 			sum = 0,
 			classList = [];
 		if (results.length) results = results.filter(v => {
 			let item = this.data.list.find(va => va.sa_shoppingcartid == v);
+
 			if (item) {
-				console.log(item.gradeprice)
 				sum = currency(sum).add(currency(item.qty).multiply(item.gradeprice)).value;
+				resultsList.push(item)
 				/* 领域分类 */
 				let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);
 				if (index == -1) {
@@ -267,12 +278,12 @@ Page({
 			let brand = this.data.allBrandList.find(v => v.sa_brandid == sa_brandid)
 			isAll = brand.results.length == results.length
 		}
-		console.log(sum)
 		this.setData({
 			sum: CNY(sum),
 			isAll,
 			results,
 			sa_brandid,
+			resultsList,
 			classList
 		});
 	},

+ 5 - 4
packageA/activity/selectProduct/cart/index.wxml

@@ -21,7 +21,8 @@
 					<view class="exp">品牌:{{item.brandname ||" --"}}</view>
 					<view class="exp">领域:{{item.tradefield_shoppingcart ||" --"}}</view>
 					<view class="exp" wx:if="{{item.iscustomsize}}" data-item="{{item}}" catch:tap="customization" style="color:#085CDF;">
-						{{item.customText}}<van-icon name="arrow-down" />
+						{{item.customText}}
+						<van-icon name="arrow-down" />
 					</view>
 					<view class="price" style="bottom: {{item.iscustomsize?'40rpx':'0rpx'}};">{{handleHide.query(item.showPrice,hidePrice)}}/{{item.unitname}}</view>
 				</view>
@@ -53,10 +54,10 @@
 				{{logistics}}
 			</view>
 		</view>
-		<picker wx:if="{{classList.length>=2}}" range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
+		<!-- 	<picker wx:if="{{classList.length>=2}}" range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
 			<van-button custom-class='but' disabled='{{!results.length}}' loading='{{loading}}' loading-text="生成中..." bind:click="clickBut">生成订单</van-button>
-		</picker>
-		<van-button wx:else custom-class='but' disabled='{{!results.length}}' loading='{{loading}}' loading-text="生成中..." bind:click="clickBut">生成订单</van-button>
+		</picker> wx:else -->
+		<van-button custom-class='but' disabled='{{!results.length}}' loading='{{loading}}' loading-text="生成中..." bind:click="clickBut">生成订单</van-button>
 	</view>
 </view>
 

+ 32 - 28
packageA/activity/selectProduct/index.js

@@ -36,34 +36,6 @@ Page({
       idname: options.idname || this.data.idname
     });
     this.getList()
-    getApp().globalData.customizedProduct = (item, custom) => {
-      item = getItem(getItem(Object.assign(item, custom)), 'newOldPrice', 'oldprice');
-      item.customText = getCustomText(item);
-
-      return new Promise((resolve) => {
-        let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]),
-          resultList = this.data.resultList,
-          result = this.data.result;
-        if (index != -1) this.data.list[index] = item;
-        let i = resultList.findIndex(v => v[this.data.idname] == item[this.data.idname]);
-        if (item.pitchOn) {
-          if (i == -1) {
-            resultList.push(item);
-            result.push(item[this.data.idname])
-          } else {
-            resultList[i] = item;
-          }
-        } else {
-          resultList[i] = item;
-        }
-        this.setData({
-          list: this.data.list,
-          result,
-          resultList
-        })
-        resolve(true)
-      })
-    }
   },
   onShow() {
     this.getCollectCount()
@@ -135,8 +107,39 @@ Page({
       item
     } = e.target.dataset;
     item.pitchOn = false;
+    this.bindChangeFun();
     if (item) this.selectComponent("#Custom").onClick(item)
   },
+
+  bindChangeFun() {
+    getApp().globalData.customizedProduct = (item, custom) => {
+      item = getItem(getItem(Object.assign(item, custom)), 'newOldPrice', 'oldprice');
+      item.customText = getCustomText(item);
+      return new Promise((resolve) => {
+        let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]),
+          resultList = this.data.resultList,
+          result = this.data.result;
+        if (index != -1) this.data.list[index] = item;
+        let i = resultList.findIndex(v => v[this.data.idname] == item[this.data.idname]);
+        if (item.pitchOn) {
+          if (i == -1) {
+            resultList.push(item);
+            result.push(item[this.data.idname])
+          } else {
+            resultList[i] = item;
+          }
+        } else {
+          resultList[i] = item;
+        }
+        this.setData({
+          list: this.data.list,
+          result,
+          resultList
+        })
+        resolve(true)
+      })
+    }
+  },
   getList(init = false) {
     //init 用于初始化分页
     if (init.detail != undefined) init = init.detail;
@@ -207,6 +210,7 @@ Page({
         if (item.iscustomsize == 1) {
           if ((item.widthschemeid && !item.width) || (item.lengthschemeid && !item.length)) {
             item.pitchOn = true;
+            this.bindChangeFun();
             if (item) this.selectComponent("#Custom").onClick(item)
           } else {
             result.push(id)

+ 1 - 3
packageA/favorites/index.js

@@ -51,9 +51,6 @@ Page({
     const {
       item
     } = e.target.dataset;
-    if (item) this.selectComponent("#Custom").onClick(item)
-  },
-  onShow() {
     //修改定制项产品
     getApp().globalData.customizedProduct = (item, custom) => {
       let obj = {
@@ -87,6 +84,7 @@ Page({
         })
       })
     }
+    if (item) this.selectComponent("#Custom").onClick(item)
   },
   /* 获取列表 */
   getList() {

+ 23 - 0
pages/index/collect/index.js

@@ -256,6 +256,29 @@ Component({
 			const {
 				item
 			} = e.target.dataset;
+			getApp().globalData.customizedProduct = (item, custom) => {
+				return new Promise((resolve) => {
+					wx.showLoading({
+						title: '修改中...',
+					})
+					_Http.basic({
+						"id": 20220924104302,
+						"content": {
+							"sa_shoppingcartid": item.sa_shoppingcartid,
+							"qty": item.qty,
+							...custom
+						},
+					}).then(res => {
+						console.log("修改定制", res)
+						wx.showToast({
+							title: res.msg != '成功' ? res.msg : '修改成功',
+							icon: "none"
+						});
+						this.getList()
+						resolve(true)
+					})
+				})
+			}
 			if (item) this.selectComponent("#Custom").onClick(item)
 		},
 		/* 计算总价/产品领域分类 */

+ 18 - 14
select/product/index.js

@@ -35,20 +35,6 @@ Page({
 			newPrice: options.newprice || "price", //红色价格
 		});
 		this.getList();
-		getApp().globalData.customizedProduct = (item, custom) => {
-			return new Promise((resolve) => {
-				item = Object.assign(item, custom)
-				item.customText = getCustomText(item);
-				let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]);
-				if (index != -1) this.data.list[index] = item;
-				if (item.pitchOn) this.data.result.push(item[this.data.idname])
-				this.setData({
-					list: this.data.list,
-					result: this.data.result
-				})
-				resolve(true)
-			})
-		}
 	},
 	getList(init = false) {
 		//init 用于初始化分页
@@ -98,8 +84,25 @@ Page({
 			item
 		} = e.target.dataset;
 		item.pitchOn = false;
+		this.bindChangeFun()
 		if (item) this.selectComponent("#Custom").onClick(item)
 	},
+	bindChangeFun(){
+		getApp().globalData.customizedProduct = (item, custom) => {
+			return new Promise((resolve) => {
+				item = Object.assign(item, custom)
+				item.customText = getCustomText(item);
+				let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]);
+				if (index != -1) this.data.list[index] = item;
+				if (item.pitchOn) this.data.result.push(item[this.data.idname])
+				this.setData({
+					list: this.data.list,
+					result: this.data.result
+				})
+				resolve(true)
+			})
+		}
+	},
 	/* 选中 */
 	changeResult(e) {
 		let {
@@ -114,6 +117,7 @@ Page({
 				if (item.iscustomsize == 1) {
 					if ((item.widthschemeid && item.width == 0) || (item.lengthschemeid && item.length == 0)) {
 						item.pitchOn = true;
+						this.bindChangeFun()
 						if (item) this.selectComponent("#Custom").onClick(item)
 					} else {
 						result.push(id)