Explorar o código

防止设置定制项方法丢失

xiaohaizhao hai 1 ano
pai
achega
af1b8c2c4e
Modificáronse 2 ficheiros con 29 adicións e 31 borrados
  1. 28 28
      packageA/activity/selectProduct/index.js
  2. 1 3
      packageA/favorites/index.js

+ 28 - 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,6 +107,34 @@ Page({
       item
     } = e.target.dataset;
     item.pitchOn = false;
+
+    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)
+      })
+    }
     if (item) this.selectComponent("#Custom").onClick(item)
   },
   getList(init = false) {

+ 1 - 3
packageA/favorites/index.js

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