From cb15c57d0ff984f5a100cf25d560fb0a69c00984 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期二, 16 四月 2024 18:21:05 +0800
Subject: [PATCH] 音频bug4

---
 packageBookService/pages/bookServices/detail/components/tree/index.js |  621 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 414 insertions(+), 207 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js
index 89245ce..ef5aa5a 100644
--- a/packageBookService/pages/bookServices/detail/components/tree/index.js
+++ b/packageBookService/pages/bookServices/detail/components/tree/index.js
@@ -1,31 +1,33 @@
-const util = require('./components/util') // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず
+const util = require("./components/util"); // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず
 import {
   loginInfo
-} from '../../../../../../assets/js/login'
-const app = getApp()
+} from "../../../../../../assets/js/login";
+const app = getApp();
 Component({
-  // checked: false,
-
   properties: {
     treeList: {
+      type: Array,
+      value: [],
+    },
+    learnList: {
       type: Array,
       value: []
     },
     bookInfo: {
       type: Object,
-      value: {}
+      value: {},
     },
     buyIds: {
       type: Array,
-      value: []
+      value: [],
     },
     tab: {
       type: String,
-      value: ''
+      value: "",
     },
     applyState: {
       type: String,
-      value: ''
+      value: "",
     },
     openIds: {
       type: Array,
@@ -42,52 +44,49 @@
     superior: {
       type: Boolean,
       value: false,
-    }
+    },
+    checkAllState: {
+      type: Boolean,
+    },
   },
   data: {
-    sonPurchaseSaleMethodId: '',
+    sonPurchaseSaleMethodId: "",
     superiorPurchaseSaleMethodId: [],
     activeValues: [1, 2],
-    webpageSrc: '',
+    webpageSrc: "",
     cloudShoppingCart: [],
     selectAll: [],
-    shoppingCart: true
+    shoppingCart: true,
+    stop: false,
+    cart: true
   },
-  ready() {
-    this.setData({
-
-    })
-    console.log('鍑嗗');
-  },
+  ready() {},
 
   onLoad() {
     this.setData({
-      sonPurchaseSaleMethodId: []
-    })
-    console.log(this.data.sonPurchaseSaleMethodId, 'sonPurchaseSaleMethodId789');
+      sonPurchaseSaleMethodId: [],
+    });
   },
   observers: {
-    'openIds': function (newValue) {
-      // var myEventDetail = {
-      // }
-      // var myEventOption = {
-      //   bubbles: true,
-      //   composed: true
-      // }
-      // this.triggerEvent('handleTree', myEventDetail, myEventOption)
-    }
+    treeList: function (newValue) {
+      const list = [];
+      let checked = "";
+      this.properties.treeList.forEach((item) => {
+        if (item.children && item.children.length > 0) {
+          list.push(...this.flattenTree([item]));
+        }
+      });
+      const flag = list.findIndex((item) => item.checked == true);
+    },
   },
 
   methods: {
-
     handleList(tree) {
       for (let index = 0; index < tree.length; index++) {
         const item = tree[index];
-        if (item.sysType == 'CmsItem' && !item.checked) {
-
-        }
+        if (item.sysType == "CmsItem" && !item.checked) {}
         if (item.children && item.children.length > 0) {
-          this.handleList(item.children)
+          this.handleList(item.children);
         }
       }
     },
@@ -100,111 +99,192 @@
     handleCheck(data) {
       for (let index = 0; index < data.length; index++) {
         const element = data[index];
-        element.checked = true
+        element.checked = true;
         if (element.childrenCount && element.type == "productFolder") {
-          handleCheck(element.children)
+          handleCheck(element.children);
         }
       }
     },
     downloadTeach(e) {
-      const value = e.currentTarget.dataset.value
+      const value = e.currentTarget.dataset.value;
       var myEventDetail = {
         value,
-      } // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟
+      }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟
       var myEventOption = {
         bubbles: true,
-        composed: true
-      } // 瑙﹀彂浜嬩欢鐨勯�夐」
-      this.triggerEvent('downloadTeach', myEventDetail, myEventOption)
-
+        composed: true,
+      }; // 瑙﹀彂浜嬩欢鐨勯�夐」
+      this.triggerEvent("downloadTeach", myEventDetail, myEventOption);
     },
     // 鍒ゆ柇璧勬簮鏄惁璐拱
     resourceIsBuy(data) {
       if (data.saleMethod && data.saleMethod.length) {
-        if (data.saleMethod[0].State == 'Disable') return false
-        const isSHow = this.properties.buyIds.some((item) => item == data.saleMethod[0].Id)
-        return !isSHow
+        if (data.saleMethod[0].State == "Disable") return false;
+        const isSHow = this.properties.buyIds.some(
+          (item) => item == data.saleMethod[0].Id
+        );
+        return !isSHow;
       } else {
-        return false
+        return false;
       }
     },
     // 璺宠浆闊宠棰戞挱鏀惧櫒
     goPlayer(e) {
       // 妫�鏌ョ櫥褰曠姸鎬�
-      const token = wx.getStorageSync(app.config.tokenKey)
-      if (!token) {
-        loginInfo(app, (data) => {
-          // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋�
-          if (data) {
-            // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue
-          } else {
-            // 鍑虹幇閿欒锛岃繑鍥瀎alse
-          }
-        })
-      } else {
-        const item = e.currentTarget.dataset.item
-        const parent = e.currentTarget.dataset.parent
-        let url
+      const token = wx.getStorageSync(app.config.tokenKey);
+
+      if (token) {
+        const item = e.currentTarget.dataset.item;
+        const parent = e.currentTarget.dataset.parent;
+        const parentProductLinkPath = parent ? parent.productLinkPath : wx.getStorageSync('teachResourcesPath')
+        const parentName = parent ? parent.name : '鏁欏璧勬簮'
+        let url;
         if (this.properties.isShowCheck && this.resourceIsBuy(item)) {
-          return wx.showToast({
-            icon: 'error',
-            title: "璇峰厛璐拱璧勬簮"
-          })
+          return false;
         }
-        if (item.selectType == 'video' || item.learnSelectType == 'video') {
-          url = '/packageDomain/pages/resourceDetails/myVideo/index'
-        } else if (item.selectType == 'audio' || item.learnSelectType == 'audio') {
-          url = '/packageDomain/pages/resourceDetails/myAudio/index'
-        } else if (item.selectType == 'picture' || item.selectType == 'zip') {
-          url = '/packageDomain/pages/resourceDetails/document/index'
+        if (item.selectType == "video" || item.learnSelectType == "video") {
+          url = "/packageDomain/pages/resourceDetails/myVideo/index";
+        } else if (
+          item.selectType == "audio" ||
+          item.learnSelectType == "audio"
+        ) {
+          url = "/packageDomain/pages/resourceDetails/myAudio/index";
+        } else if (item.selectType == "picture" || item.selectType == "zip") {
+          url = "/packageDomain/pages/resourceDetails/document/index";
         }
-        if (this.properties.tab == 'jsek_cloudLearning' && this.resourceIsBuy(item)) {
+        if (
+          this.properties.tab == "jsek_cloudLearning" &&
+          this.resourceIsBuy(item)
+        ) {
           return wx.showToast({
-            icon: 'error',
-            title: '璇峰厛璐拱璇ヨ祫婧�',
-          })
+            icon: "error",
+            title: item.saleMethod[0].Price > 0 ?
+              "璇峰厛璐拱璇ヨ祫婧�" : "璇峰厛鐐瑰嚮棰嗗彇鏌ョ湅鎸夐挳",
+          });
         }
         wx.navigateTo({
-          url: `${url}?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parent.productLinkPath}&parentName=${parent.name}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}`,
-        })
-        if (item.selectType == 'document' || item.selectType == 'pdf') {
-          const fileLink = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file
-          console.log(fileLink, 'fileLink');
+          url: `${url}?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parentProductLinkPath}&parentName=${parentName}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}&formPath=${this.properties.tab}`,
+        });
+
+
+        if (item.selectType == "document" || item.selectType == "pdf") {
+          const fileLink =
+            app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file;
+          console.log(fileLink, "fileLink");
           //鎻愮ず鍔犺浇涓�
-          util.showLoading()
+          util.showLoading();
           // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB
           wx.downloadFile({
-            url: fileLink, // 鍦板潃宸叉墦鐮侊紝鑷繁鎹釜鍏朵粬鐨勫湴鍧�锛�"https://www.xxxxx.com/file/娴嬭瘯閫氱煡.pdf"锛�
+            url: fileLink,
             success: function (res) {
-              console.log(res, "wx.downloadFile success res")
+              console.log(res, "wx.downloadFile success res");
               if (res.statusCode != 200) {
-                util.hideLoadingWithErrorTips()
-                return false
+                util.hideLoadingWithErrorTips();
+                return false;
               }
-              var Path = res.tempFilePath //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢�
+              var Path = res.tempFilePath; //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢�
               wx.openDocument({
                 filePath: Path,
                 showMenu: true,
                 success: function (res) {
-                  console.log('鎵撳紑鎴愬姛');
-                  util.hideLoading()
-                }
-              })
+                  console.log("鎵撳紑鎴愬姛");
+                  util.hideLoading();
+                },
+              });
             },
             fail: function (err) {
               console.log(err, "wx.downloadFile fail err");
-              util.hideLoadingWithErrorTips()
-            }
-          })
+              util.hideLoadingWithErrorTips();
+            },
+          });
         }
-        if (item.selectType == 'webpage') {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+        // if (item.selectType == "document" || item.selectType == "pdf") {
+        //   const fileLink = app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file;
+
+        //   let filePath = wx.env.USER_DATA_PATH + '/' + item.name
+        //   console.log(filePath, 'filePath');
+        //   //鎻愮ず鍔犺浇涓�
+        //   util.showLoading();
+        //   // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB
+        //   wx.downloadFile({
+        //     url: fileLink,
+        //     success: function (res) {
+
+        //       if (res.statusCode != 200) {
+        //         util.hideLoadingWithErrorTips();
+        //         return false;
+        //       }
+        //       var Path = res.tempFilePath; //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢�
+
+        //       wx.saveFile({
+        //         tempFilePath: Path,
+        //         success: function (res) {
+        //           var savedFilePath = res.savedFilePath;
+        //           // 灏嗘枃浠朵繚瀛樹负 item.name
+        //           wx.saveFile({
+        //             tempFilePath: savedFilePath,
+        //             filePath: wx.env.USER_DATA_PATH + '/' + item.name,
+        //             success: function (res) {
+        //               wx.openDocument({
+        //                 filePath: res.savedFilePath,
+        //                 showMenu: true,
+        //                 success: function (res) {
+        //                   util.hideLoading();
+        //                 },
+        //               });
+        //             },
+        //             fail: function (err) {
+        //               util.hideLoadingWithErrorTips();
+        //             }
+        //           });
+        //         },
+        //         fail: function (err) {
+        //           util.hideLoadingWithErrorTips();
+        //         }
+        //       });
+        //     },
+        //     fail: function (err) {
+        //       util.hideLoadingWithErrorTips();
+        //     },
+        //   });
+        // }
+
+
+
+
+
+        if (item.selectType == "webpage") {
           this.setData({
-            webpageSrc: item.jsek_link
-          })
-          console.log(this.data.webpageSrc, 'webpageSrc');
+            webpageSrc: item.jsek_link,
+          });
+          console.log(this.data.webpageSrc, "webpageSrc");
         }
       }
     },
+
     // 鎷垮埌鎵�鏈夐」
     getAllChildren(id) {
       let result = [];
@@ -212,13 +292,13 @@
       function findChildren(item) {
         if (item.id === id) {
           if (item.children && item.children.length > 0) {
-            item.children.forEach(child => {
+            item.children.forEach((child) => {
               findChildren(child);
             });
           }
         } else {
           if (item.children && item.children.length > 0) {
-            item.children.forEach(child => {
+            item.children.forEach((child) => {
               findChildren(child);
             });
           }
@@ -227,8 +307,8 @@
           result.push(...item.children);
         }
       }
-      console.log(this.properties.treeList, 'this.properties.treeList');
-      this.properties.treeList.forEach(item => {
+      console.log(this.properties.treeList, "this.properties.treeList");
+      this.properties.treeList.forEach((item) => {
         findChildren(item);
       });
       return result;
@@ -240,25 +320,24 @@
       function flatten(node) {
         result.push(node);
         if (node.children && node.children.length > 0) {
-          node.children.forEach(child => {
+          node.children.forEach((child) => {
             flatten(child);
           });
         }
       }
-      tree.forEach(node => {
-
+      tree.forEach((node) => {
         flatten(node);
       });
       // console.log(result, 'result');
-      return result
+      return result;
     },
 
     // 鍙樹负true
-    findAndUpdateItemsByIds(tree, ids) {
+    findAndUpdateItemsByIds(tree, ids, state) {
       function findAndUpdate(node) {
         if (ids.includes(node.id)) {
           // console.log(node, 'node');
-          node.checked = !node.checked // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+          node.checked = state; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
         }
         if (node.children && node.children.length > 0) {
           for (let child of node.children) {
@@ -266,9 +345,7 @@
           }
         }
       }
-
       for (let node of tree) {
-
         findAndUpdate(node); // 瀵规瘡涓《灞傝妭鐐规墽琛屾煡鎵惧拰鏇存柊鎿嶄綔
       }
       // console.log(tree, 'tree345');
@@ -277,13 +354,13 @@
 
     checkResoucrceInfo(tree, id) {
       function findAndUpdate(node) {
-        if (node.sysType == 'CmsFolder' && node.children.length > 0) {
+        if (node.sysType == "CmsFolder" && node.children.length > 0) {
           for (let index = 0; index < node.children.length; index++) {
             const element = node.children[index];
-            findAndUpdate(element)
+            findAndUpdate(element);
           }
         } else if (id == node.id && node.sysType == "CmsItem") {
-          node.checked = !node.checked // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+          node.checked = !node.checked; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
         }
       }
       for (let node of tree) {
@@ -291,153 +368,283 @@
       }
       return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍
     },
-
+    // 鍏ㄩ��
     checkAll() {
-      const ids = []
-      const list = []
-      let checked = ''
-      this.properties.treeList.forEach(item => {
+      const ids = [];
+      const list = [];
+      let checked = "";
+      this.properties.treeList.forEach((item) => {
         if (item.children && item.children.length > 0) {
-          list.push(...this.flattenTree([item]))
+          list.push(...this.flattenTree([item]));
         }
-      })
-      list.forEach(item => {
-        ids.push(item.id)
+      });
+      list.forEach((item) => {
+        ids.push(item.id);
+        checked = item.checked;
+      });
+      // const flag =
+      //   list.findIndex((item) => item.checked == false) > -1 ? true : false;
+      const flag = this.properties.checkAllState;
+      // const updataList = this.findAndUpdateItemsByIds(
+      //   this.properties.treeList,
+      //   ids,
+      //   flag
+      // );
+      // this.setData({
+      //   treeList: updataList,
+      // });
 
-        checked = item.checked
-      })
+      var myEventDetail = {
+        ids,
+        flag,
+      }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟
+      var myEventOption = {
+        bubbles: true,
+        composed: true,
+      }; // 瑙﹀彂浜嬩欢鐨勯�夐」
+      this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
 
-
-      const updataList = this.findAndUpdateItemsByIds(this.properties.treeList, ids);
-
-      console.log(checked, 'list');
       if (!checked) {
         this.setData({
-          selectAll: list
-        })
-
+          selectAll: list,
+        });
       }
-
-      this.setData({
-        treeList: updataList
-      })
+      var myEventDetail = {
+        value: !flag,
+      }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟
+      var myEventOption = {
+        bubbles: true,
+        composed: true,
+      }; // 瑙﹀彂浜嬩欢鐨勯�夐」
+      this.triggerEvent("changeCheckAll", myEventDetail, myEventOption);
     },
 
     // 绔犺妭鍕鹃��
     checkResourceTitle(e) {
+      const flag = e.detail.checked;
       // 杩欎釜鏃跺�檆hecked鐨勫�兼槸fals
-      let checkResourceTitleList = []
-      const item = e.currentTarget.dataset.item
-      //
-      let list = this.flattenTree([item])
-      let ids = []
-      list.forEach(item => {
-        ids.push(item.id)
-      })
-      // console.log(list, 'list789');
-      const updatedTreeList = this.findAndUpdateItemsByIds(this.properties.treeList, ids);
-      this.setData({
-        treeList: updatedTreeList // 鏇存柊 treeList 鏁版嵁
+      let checkResourceTitleList = [];
+      const item = e.currentTarget.dataset.item;
+      const parent = this.findParentById(this.properties.learnList, item.id)
+      let childrenList
+      let flagNum
+      if (parent) childrenList = parent.children.filter(citem => citem.id !== item.id)
+      if (childrenList) flagNum = childrenList.findIndex(item => item.checked == false)
+      let list = this.flattenTree([item]);
+      let ids = [];
+      list.forEach((item) => {
+        if (item.sysType == 'CmsFolder' || (item.sysType == 'CmsItem' && item.saleMethod.length))
+          ids.push(item.id);
       });
-      console.log(list, 'list.checked');
-      if (!list.checked) {
-
-
-        this.setData({
-          superiorPurchaseSaleMethodId: list
-        })
-
+      var myEventDetail = {
+        ids,
+        flag,
+      }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟
+      var myEventOption = {
+        bubbles: true,
+        composed: true,
+      }; // 瑙﹀彂浜嬩欢鐨勯�夐」
+      this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
+      if (flagNum == -1) {
+        let checkedState
+        var myEventDetail = {
+          ids: [parent.id],
+          flag,
+        }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟
+        var myEventOption = {
+          bubbles: true,
+          composed: true,
+        }; // 瑙﹀彂浜嬩欢鐨勯�夐」
+        this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
       }
-
-      // console.log(this.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId');
-      list.forEach(items => {
-        console.log(items.checked, 'itesasd');
+      if (!list.checked) {
+        this.setData({
+          superiorPurchaseSaleMethodId: list,
+        });
+      }
+      list.forEach((items) => {
+        console.log(items.checked, "itesasd");
         if (!items.checked) {
           this.setData({
-            cloudShoppingCart: items
-          })
+            cloudShoppingCart: items,
+          });
         }
-      })
+      });
+      this.setData({
+        openIds: this.data.openIds,
+      });
     },
     // 瀛愰」鍕鹃��
     checkResource(e) {
-      const citem = e.currentTarget.dataset.item
-      console.log(citem, '5648');
-      const updataList = this.checkResoucrceInfo(this.properties.treeList, citem.id)
-      console.log(citem.checked, 'citem.checked');
+      const citem = e.currentTarget.dataset.item;
+      const parent = e.currentTarget.dataset.parent
+      let outermost
+      if (parent) outermost = this.findParentById(this.properties.learnList, parent.id)
+      const childrenList = parent.children.filter(item => item.id !== citem.id && item.saleMethod.length)
+      const flag = childrenList.findIndex(item => item.checked == false)
+      // 鏀瑰彉璇ラ」checked
+      var myEventDetail = {
+        id: citem.id
+      };
+      var myEventOption = {
+        bubbles: true,
+        composed: true,
+      };
+      this.triggerEvent("changeResourceChecked", myEventDetail, myEventOption);
+      // 閫氳繃鍒ゆ柇,鑱旈�氱埗绾hecked
+      if (flag == -1) {
+        let checkedState
+        citem.checked == false ? checkedState = true : checkedState = false
+        var myEventDetail = {
+          ids: [parent.id],
+          flag: checkedState,
+        };
+        var myEventOption = {
+          bubbles: true,
+          composed: true,
+        };
+        this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
+      }
+      // 鑱旈�氭渶澶栧眰绾hecked ,濡傛灉鏈変竴涓彇娑堝嬀閫�,涓斿綋鍓嶆渶澶栧眰鍕鹃��,鍒欏彇娑堟渶澶栧眰鐨勫嬀閫�
+      if (citem.checked && outermost && outermost.checked) {
+        var myEventDetail = {
+          ids: [outermost.id],
+          flag: false,
+        };
+        var myEventOption = {
+          bubbles: true,
+          composed: true,
+        };
+        this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
+      }
+      // 鑱旈�氭渶澶栧眰绾hecked, 濡傛灉鎵�鏈夊瓙椤瑰嬀閫�, 涓斿綋鍓嶆渶澶栧眰鏈嬀閫�, 鍒欏姞涓婃渶澶栧眰鐨勫嬀閫�
+      if (!citem.checked && outermost) {
+        let allchildren = this.flattenTree([outermost])
+        allchildren = allchildren.filter(item => item.sysType == 'CmsItem' && item.id !== citem.id && item.saleMethod.length)
+        const satate = allchildren.findIndex(item => item.checked == false)
+        if (satate == -1) {
+          var myEventDetail = {
+            ids: [outermost.id],
+            flag: true,
+          };
+          var myEventOption = {
+            bubbles: true,
+            composed: true,
+          };
+          this.triggerEvent("changeListChecked", myEventDetail, myEventOption);
+        }
+      }
       if (!citem.checked) {
         //閫変腑鐨勬椂鍊欐坊鍔爄d
-        let sonPurchaseSaleMethodId = this.data.sonPurchaseSaleMethodId || []
-        console.log(this.properties.paymentPage, 'this.properties.paymentPage');
+        let sonPurchaseSaleMethodId = this.data.sonPurchaseSaleMethodId || [];
         if (this.properties.paymentPage) {
-          console.log(789987);
-          sonPurchaseSaleMethodId = []
-          this.properties.paymentPage = false
+          sonPurchaseSaleMethodId = [];
+          this.properties.paymentPage = false;
         }
         if (!this.properties.paymentPage) {
-          sonPurchaseSaleMethodId.push(citem.saleMethod[0].Id)
+          sonPurchaseSaleMethodId.push(citem.saleMethod[0].Id);
         }
         this.setData({
-          sonPurchaseSaleMethodId: sonPurchaseSaleMethodId
-        })
-        console.log(this.data.sonPurchaseSaleMethodId);
+          sonPurchaseSaleMethodId: sonPurchaseSaleMethodId,
+        });
       } else {
         // 鍙栨秷閫変腑鐨勬椂鍊欏垹闄d
       }
-      this.setData({
-        treeList: updataList,
-      })
     },
     // 鍔犲叆璐墿杞�
     async onCloudShoppingCart(e) {
+      let shoppingCartGetId = [];
 
-      let shoppingCartGetId = []
-      const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id
+      const item = e.currentTarget.dataset.item
+      console.log(item.isShopCar);
+      const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id;
       console.log(saleMethodId);
       let query = {
         start: 0,
         size: 999,
         filterList: [],
-        searchList: []
-      }
+        searchList: [],
+      };
 
-      const res = await app.MG.store.getShoppingCartProductList(query)
-      res.datas.forEach(item => {
-        shoppingCartGetId.push(item.saleMethod.id)
-      })
+      const res = await app.MG.store.getShoppingCartProductList(query);
+      res.datas.forEach((item) => {
+        shoppingCartGetId.push(item.saleMethod.id);
+      });
       if (shoppingCartGetId.includes(saleMethodId)) {
         console.log(111);
+        // this.data.updateShoppingCartHidden();
+        // this.data.updateCloudLearning();
 
         wx.showToast({
-          icon: 'error',
-          title: '宸叉坊鍔�',
-        })
+          icon: "error",
+          title: "宸叉坊鍔�",
+        });
         this.setData({
-          shoppingCart: false
-        })
+          shoppingCart: false,
+        });
       } else {
         let query = {
           requests: [{
             saleMethodId: saleMethodId,
             storeEventId: null,
             // agentCode: '鐢靛瓙涔�'
-          }]
+          }, ],
+        };
+        const addRes = await app.MG.store.addShoppingCart(query);
+        console.log(addRes, "addRes");
+        if (addRes) {
+          wx.showToast({
+            icon: "success",
+            title: "娣诲姞鎴愬姛",
+          });
+          item.isShopCar = false
+          this.triggerEvent("updateCloudLearning")
         }
-        const addRes = await app.MG.store.addShoppingCart(query)
-        console.log(addRes, 'addRes');
-        wx.showToast({
-          icon: 'success',
-          title: '娣诲姞鎴愬姛',
-        })
-      }
 
+      }
     },
+    sadd() {
+      this.triggerEvent("updateShoppingCartHidden");
+      this.triggerEvent("updateCloudLearning");
+    },
+    findParentById(arr, id) {
+      for (let i = 0; i < arr.length; i++) {
+        const item = arr[i];
+        // 妫�鏌ュ綋鍓嶉」鏄惁鍖归厤锛堝嵆瀹冩槸涓嶆槸鎴戜滑瑕佹壘鐨勯」锛�  
+        if (item.id === id) {
+          // 濡傛灉褰撳墠椤瑰氨鏄垜浠鎵剧殑椤癸紝鍒欏畠娌℃湁鐖剁骇锛岃繑鍥� null  
+          return null;
+        }
+        // 閫掑綊鏌ユ壘褰撳墠椤圭殑瀛愰」  
+        const child = this.findChildById(item.children, id);
+        if (child) {
+          // 濡傛灉鍦ㄥ瓙椤逛腑鎵惧埌鍖归厤鐨勯」锛岃繑鍥炲綋鍓嶉」浣滀负鐖剁骇  
+          return item;
+        }
+      }
+      // 濡傛灉娌℃湁鎵惧埌鍖归厤鐨勭埗椤癸紝杩斿洖 null  
+      return null;
+    },
+
+    // 杈呭姪鍑芥暟锛岀敤浜庨�掑綊鏌ユ壘瀛愰」  
+    findChildById(children, id) {
+      if (!children) {
+        return null;
+      }
+      for (let i = 0; i < children.length; i++) {
+        const child = children[i];
+        if (child.id === id) {
+          // 濡傛灉鎵惧埌鍖归厤鐨勯」锛岃繑鍥炲畠  
+          return child;
+        }
+        // 閫掑綊妫�鏌ュ瓙椤圭殑瀛愰」  
+        const subChild = this.findChildById(child.children, id);
+        if (subChild) {
+          return subChild;
+        }
+      }
+      // 濡傛灉娌℃湁鎵惧埌鍖归厤鐨勯」锛岃繑鍥� null  
+      return null;
+    }
   },
-  onCheckAllChange(e) {
-    // debugger
-    // console.log('checkbox', e.detail.value);
-    // this.setData({
-    //   checkAllValues: event.detail,
-    // });
-  },
-})
\ No newline at end of file
+});
\ No newline at end of file

--
Gitblit v1.9.1