Selaa lähdekoodia

优化定制方法

xiaohaizhao 1 vuosi sitten
vanhempi
commit
4645845196

+ 20 - 20
packageA/activity/selectProduct/cart/index.js

@@ -28,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() {
@@ -239,6 +219,26 @@ 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)
 	},
 	/* 计算总价/产品领域分类 */

+ 5 - 1
packageA/activity/selectProduct/index.js

@@ -107,7 +107,11 @@ 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);
@@ -135,7 +139,6 @@ Page({
         resolve(true)
       })
     }
-    if (item) this.selectComponent("#Custom").onClick(item)
   },
   getList(init = false) {
     //init 用于初始化分页
@@ -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)

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

@@ -25,29 +25,6 @@ Component({
 	methods: {
 		init() {
 			this.getList()
-			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)
-					})
-				})
-			}
 			return true;
 		},
 		/* 获取列表 */
@@ -209,6 +186,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)