From aa2c08b3be23a01d44205b2c19d21a2bf53f944f Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 01 四月 2024 16:15:38 +0800
Subject: [PATCH] 图书服务列表、详情页bug修改

---
 packageBookService/pages/bookServices/detail/components/tree/index.js |  344 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 236 insertions(+), 108 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js
index 85c10dc..29c18a5 100644
--- a/packageBookService/pages/bookServices/detail/components/tree/index.js
+++ b/packageBookService/pages/bookServices/detail/components/tree/index.js
@@ -1,6 +1,7 @@
-
-import Message from 'tdesign-miniprogram/message/message';
 const util = require('./components/util') // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず
+import {
+  loginInfo
+} from '../../../../../../assets/js/login'
 const app = getApp()
 Component({
   // checked: false,
@@ -29,30 +30,71 @@
     openIds: {
       type: Array,
       value: [],
-    }
-    ,
+    },
     isShowCheck: {
+      type: Boolean,
+      value: false,
+    },
+    paymentPage: {
+      type: Boolean,
+      value: false,
+    },
+    superior: {
       type: Boolean,
       value: false,
     }
   },
   data: {
+    sonPurchaseSaleMethodId: '',
+    superiorPurchaseSaleMethodId: [],
     activeValues: [1, 2],
     webpageSrc: '',
-    cloudShoppingCart: []
+    cloudShoppingCart: [],
+    selectAll: []
   },
-  onShow() {
+  ready() {
+    this.setData({
+
+    })
+    console.log('鍑嗗');
   },
 
+  onLoad() {
+    this.setData({
+      sonPurchaseSaleMethodId: []
+    })
+    console.log(this.data.sonPurchaseSaleMethodId, 'sonPurchaseSaleMethodId789');
+  },
+  observers: {
+    'openIds': function (newValue) {
+      // var myEventDetail = {
+      // }
+      // var myEventOption = {
+      //   bubbles: true,
+      //   composed: true
+      // }
+      // this.triggerEvent('handleTree', myEventDetail, myEventOption)
+    }
+  },
 
   methods: {
+
+    handleList(tree) {
+      for (let index = 0; index < tree.length; index++) {
+        const item = tree[index];
+        if (item.sysType == 'CmsItem' && !item.checked) {
+
+        }
+        if (item.children && item.children.length > 0) {
+          this.handleList(item.children)
+        }
+      }
+    },
     // 鑺傜偣灞曞紑
     handleChange(e) {
-      // console.log(this.properties.treeList, 'this.properties.treeList');
       this.setData({
-        activeValues: e.detail.value,
+        openIds: e.detail.value,
       });
-      // console.log('浼犻��', this.properties.buyIds);
     },
     handleCheck(data) {
       for (let index = 0; index < data.length; index++) {
@@ -87,75 +129,80 @@
     },
     // 璺宠浆闊宠棰戞挱鏀惧櫒
     goPlayer(e) {
-      if (this.properties.isShowCheck) return true
-      const item = e.currentTarget.dataset.item
-      const parent = e.currentTarget.dataset.parent
-      let url
-      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)) {
-        return wx.showToast({
-          icon: 'error',
-          title: '璇峰厛璐拱璇ヨ祫婧�',
-        })
-      }
-      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');
-        //鎻愮ず鍔犺浇涓�
-        util.showLoading()
-        // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB
-        wx.downloadFile({
-          url: fileLink, // 鍦板潃宸叉墦鐮侊紝鑷繁鎹釜鍏朵粬鐨勫湴鍧�锛�"https://www.xxxxx.com/file/娴嬭瘯閫氱煡.pdf"锛�
-          success: function (res) {
-            console.log(res, "wx.downloadFile success res")
-            if (res.statusCode != 200) {
-              util.hideLoadingWithErrorTips()
-              return false
-            }
-            var Path = res.tempFilePath //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢�
-            wx.openDocument({
-              filePath: Path,
-              showMenu: true,
-              success: function (res) {
-                console.log('鎵撳紑鎴愬姛');
-                util.hideLoading()
-              }
-            })
-          },
-          fail: function (err) {
-            console.log(err, "wx.downloadFile fail err");
-            util.hideLoadingWithErrorTips()
+      // 妫�鏌ョ櫥褰曠姸鎬�
+      const token = wx.getStorageSync(app.config.tokenKey)
+      if (!token) {
+        loginInfo(app, (data) => {
+          // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋�
+          if (data) {
+            // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue
+          } else {
+            // 鍑虹幇閿欒锛岃繑鍥瀎alse
           }
         })
-
-
-      }
-
-      if (item.selectType == 'webpage') {
-        console.log(11);
-        this.setData({
-          webpageSrc: item.jsek_link
+      } else {
+        if (this.properties.isShowCheck) return true
+        const item = e.currentTarget.dataset.item
+        const parent = e.currentTarget.dataset.parent
+        let url
+        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)) {
+          return wx.showToast({
+            icon: 'error',
+            title: '璇峰厛璐拱璇ヨ祫婧�',
+          })
+        }
+        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}`,
         })
-        console.log(this.data.webpageSrc, 'webpageSrc');
+        if (item.selectType == 'document' || item.selectType == 'pdf') {
+          const fileLink = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file
+          console.log(fileLink, 'fileLink');
+          //鎻愮ず鍔犺浇涓�
+          util.showLoading()
+          // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB
+          wx.downloadFile({
+            url: fileLink, // 鍦板潃宸叉墦鐮侊紝鑷繁鎹釜鍏朵粬鐨勫湴鍧�锛�"https://www.xxxxx.com/file/娴嬭瘯閫氱煡.pdf"锛�
+            success: function (res) {
+              console.log(res, "wx.downloadFile success res")
+              if (res.statusCode != 200) {
+                util.hideLoadingWithErrorTips()
+                return false
+              }
+              var Path = res.tempFilePath //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢�
+              wx.openDocument({
+                filePath: Path,
+                showMenu: true,
+                success: function (res) {
+                  console.log('鎵撳紑鎴愬姛');
+                  util.hideLoading()
+                }
+              })
+            },
+            fail: function (err) {
+              console.log(err, "wx.downloadFile fail err");
+              util.hideLoadingWithErrorTips()
+            }
+          })
+        }
+        if (item.selectType == 'webpage') {
+          this.setData({
+            webpageSrc: item.jsek_link
+          })
+          console.log(this.data.webpageSrc, 'webpageSrc');
+        }
       }
-
-
-
     },
     // 鎷垮埌鎵�鏈夐」
     getAllChildren(id) {
       let result = [];
+
       function findChildren(item) {
         if (item.id === id) {
           if (item.children && item.children.length > 0) {
@@ -182,15 +229,11 @@
     },
     // 鎷垮埌褰撳墠椤瑰瓙椤�
     flattenTree(tree) {
-
       let result = [];
 
       function flatten(node) {
-
         result.push(node);
-
         if (node.children && node.children.length > 0) {
-
           node.children.forEach(child => {
             flatten(child);
           });
@@ -209,7 +252,7 @@
       function findAndUpdate(node) {
         if (ids.includes(node.id)) {
           // console.log(node, 'node');
-          node.checked = !node.checked  // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+          node.checked = !node.checked // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
         }
         if (node.children && node.children.length > 0) {
           for (let child of node.children) {
@@ -233,10 +276,8 @@
             const element = node.children[index];
             findAndUpdate(element)
           }
-        }
-        else if (id == node.id && node.sysType == "CmsItem") {
-          debugger
-          node.checked = !node.checked  // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+        } else if (id == node.id && node.sysType == "CmsItem") {
+          node.checked = !node.checked // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
         }
       }
       for (let node of tree) {
@@ -245,20 +286,64 @@
       return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍
     },
 
+    checkAll() {
+      const ids = []
+      const list = []
+      let checked = ''
+      this.properties.treeList.forEach(item => {
+        if (item.children && item.children.length > 0) {
+          list.push(...this.flattenTree([item]))
+        }
+      })
+      list.forEach(item => {
+        ids.push(item.id)
+
+        checked = item.checked
+      })
+
+
+      const updataList = this.findAndUpdateItemsByIds(this.properties.treeList, ids);
+
+      console.log(checked, 'list');
+      if (!checked) {
+        this.setData({
+          selectAll: list
+        })
+
+      }
+
+      this.setData({
+        treeList: updataList
+      })
+    },
+
     // 绔犺妭鍕鹃��
     checkResourceTitle(e) {
       // 杩欎釜鏃跺�檆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 鏁版嵁
+        treeList: updatedTreeList // 鏇存柊 treeList 鏁版嵁
       });
-      console.log(list, 'list');
+      console.log(list, 'list.checked');
+      if (!list.checked) {
+
+
+        this.setData({
+          superiorPurchaseSaleMethodId: list
+        })
+
+      }
+
+      // console.log(this.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId');
       list.forEach(items => {
         console.log(items.checked, 'itesasd');
         if (!items.checked) {
@@ -267,42 +352,85 @@
           })
         }
       })
-      this.onCloudShoppingCart()
     },
     // 瀛愰」鍕鹃��
     checkResource(e) {
       const citem = e.currentTarget.dataset.item
-      this.checkResoucrceInfo(this.properties.treeList, citem.id)
+      console.log(citem, '5648');
+      const updataList = this.checkResoucrceInfo(this.properties.treeList, citem.id)
+      console.log(citem.checked, 'citem.checked');
+      if (!citem.checked) {
+        //閫変腑鐨勬椂鍊欐坊鍔爄d
+        let sonPurchaseSaleMethodId = this.data.sonPurchaseSaleMethodId || []
+        console.log(this.properties.paymentPage, 'this.properties.paymentPage');
+        if (this.properties.paymentPage) {
+          console.log(789987);
+          sonPurchaseSaleMethodId = []
+          this.properties.paymentPage = false
+        }
+        if (!this.properties.paymentPage) {
+          sonPurchaseSaleMethodId.push(citem.saleMethod[0].Id)
+        }
+        this.setData({
+          sonPurchaseSaleMethodId: sonPurchaseSaleMethodId
+        })
+        console.log(this.data.sonPurchaseSaleMethodId);
+      } else {
+        // 鍙栨秷閫変腑鐨勬椂鍊欏垹闄d
+      }
+      this.setData({
+        treeList: updataList,
+      })
     },
     // 鍔犲叆璐墿杞�
-    async onCloudShoppingCart() {
-      let requests = []
-      const item = this.data.cloudShoppingCart
-      console.log(item, 'item');
-      item.forEach((items) => {
-        if (items.saleMethod.length) {
-          requests.push({
-            saleMethodId: items.saleMethod[0].Id,
-            count: 1
-          })
-        }
-      })
+    async onCloudShoppingCart(e) {
+
+      let shoppingCartGetId = []
+      const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id
+      console.log(saleMethodId);
       let query = {
-        remarks: '浜戝涔�',
-        requests
+        start: 0,
+        size: 999,
+        filterList: [],
+        searchList: []
       }
-      // 鏌ヨ璁㈠崟
-      let initOrderRes = await app.MG.store.initOrder(query)
-      let parameter = {
-        orderNum: initOrderRes.orderNumber
+
+      const res = await app.MG.store.getShoppingCartProductList(query)
+      res.datas.forEach(item => {
+        shoppingCartGetId.push(item.saleMethod.id)
+      })
+      if (shoppingCartGetId.includes(saleMethodId)) {
+        console.log(111);
+
+        wx.showToast({
+          icon: 'error',
+          title: '宸叉坊鍔�',
+        })
+
+      } else {
+        let query = {
+          requests: [{
+            saleMethodId: saleMethodId,
+            storeEventId: null,
+            // agentCode: '鐢靛瓙涔�'
+          }]
+        }
+        const addRes = await app.MG.store.addShoppingCart(query)
+        console.log(addRes, 'addRes');
+        wx.showToast({
+          icon: 'success',
+          title: '娣诲姞鎴愬姛',
+        })
+
       }
-      const confirmOrderRes = await app.MG.store.confirmOrder(parameter)
-      // if (confirmOrderRes.orderNumber) {
-      //   wx.navigateTo({
-      //     url: `/pages/cart/paymentPage/index?orderNumber=${confirmOrderRes.orderNumber}`,
-      //   })
-      //   requests = []
-      // }
+
     },
   },
+  onCheckAllChange(e) {
+    // debugger
+    // console.log('checkbox', e.detail.value);
+    // this.setData({
+    //   checkAllValues: event.detail,
+    // });
+  },
 })
\ No newline at end of file

--
Gitblit v1.9.1