From 097cdcd70b1d95f5fc581ea2bedc4faeba8259f2 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期五, 15 三月 2024 18:36:24 +0800
Subject: [PATCH] fix: 购物车的样式

---
 pages/bookServices/detail/components/tree/index.js |  183 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 178 insertions(+), 5 deletions(-)

diff --git a/pages/bookServices/detail/components/tree/index.js b/pages/bookServices/detail/components/tree/index.js
index a0386a7..3b1bd8a 100644
--- a/pages/bookServices/detail/components/tree/index.js
+++ b/pages/bookServices/detail/components/tree/index.js
@@ -1,5 +1,6 @@
 
 import Message from 'tdesign-miniprogram/message/message';
+const util = require('./components/util') // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず
 const app = getApp()
 Component({
   properties: {
@@ -22,14 +23,25 @@
     applyState: {
       type: String,
       value: ''
+    },
+    openTeachids: {
+      type: Array,
+      value: ''
+    },
+    openLearnids: {
+      type: Array,
+      value: ""
     }
   },
   data: {
-    activeValues: [0]
+    activeValues: [0],
+    webpageSrc: ''
   },
   onShow() {
 
   },
+
+
   methods: {
     // 鑺傜偣灞曞紑
     handleChange(e) {
@@ -48,7 +60,6 @@
       }
     },
     downloadTeach(e) {
-      console.log('鐐瑰嚮浜�', e);
       const value = e.currentTarget.dataset.value
       var myEventDetail = {
         value,
@@ -58,6 +69,7 @@
         composed: true
       } // 瑙﹀彂浜嬩欢鐨勯�夐」
       this.triggerEvent('downloadTeach', myEventDetail, myEventOption)
+
     },
     // 鍒ゆ柇璧勬簮鏄惁璐拱
     resourceIsBuy(data) {
@@ -72,12 +84,173 @@
     goPlayer(e) {
       const item = e.currentTarget.dataset.item
       const parent = e.currentTarget.dataset.parent
-      console.log(this.properties.bookInfo);
+      //   "pages/resourceDetails/myAudio/index",
+      // "pages/resourceDetails/myVideo/index",
+      // "pages/resourceDetails/document/index",
+
+
+
+      let url
+      if (item.selectType == 'video') {
+        url = '/pages/resourceDetails/myVideo/index'
+      } else if (item.selectType == 'audio') {
+        url = '/pages/resourceDetails/myAudio/index'
+      } else if (item.selectType == 'picture' || item.selectType == 'zip') {
+        url = '/pages/resourceDetails/document/index'
+      }
+
+      // else {
+      //   
+      // }
       wx.navigateTo({
-        url: `/pages/resourceDetails/myVideo/index?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}`,
+        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(item.productLinkPath, parent.productLinkPath, parent.name, item.id, this.properties.bookInfo.id, this.properties.bookInfo.name, this.properties.bookInfo.rootCmsItemId, 'add');
+
+      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') {
+        console.log(11);
+        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) {
+            item.children.forEach(child => {
+              findChildren(child);
+            });
+          }
+        } else {
+          if (item.children && item.children.length > 0) {
+            item.children.forEach(child => {
+              findChildren(child);
+            });
+          }
+        }
+        if (item.children && item.children.length > 0) {
+          result.push(...item.children);
+        }
+      }
+      console.log(this.properties.treeList);
+      this.properties.treeList.forEach(item => {
+        findChildren(item);
+      });
+      return result;
+    },
+    // 鎷垮埌褰撳墠椤瑰瓙椤�
+    flattenTree(tree) {
+      let result = [];
+      function flatten(node) {
+        result.push(node);
+        if (node.children && node.children.length > 0) {
+          node.children.forEach(child => {
+            flatten(child);
+          });
+        }
+      }
+      tree.forEach(node => {
+        flatten(node);
+      });
+      return result
+    },
+    findAndUpdateItemById(tree, id) {
+      function findAndUpdate(node) {
+        if (node.id === id) {
+          node.check = true; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+          return true; // 杩斿洖 true 琛ㄧず鎵惧埌浜嗙洰鏍囬」
+        }
+        if (node.children && node.children.length > 0) {
+          for (let child of node.children) {
+            if (findAndUpdate(child)) {
+              return true; // 濡傛灉鍦ㄥ瓙鑺傜偣涓壘鍒颁簡鐩爣椤癸紝鍒欑洿鎺ヨ繑鍥� true
+            }
+          }
+        }
+        return false; // 琛ㄧず鏈壘鍒扮洰鏍囬」
+      }
+
+      for (let node of tree) {
+        if (findAndUpdate(node)) {
+          break; // 濡傛灉鍦ㄩ《灞傝妭鐐逛腑鎵惧埌浜嗙洰鏍囬」锛岀洿鎺ラ��鍑哄惊鐜�
+        }
+      }
+    },
+    // 鍙樹负true
+    findAndUpdateItemsByIds(tree, ids) {
+      function findAndUpdate(node) {
+        if (ids.includes(node.id)) {
+          node.checked = true; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true
+        }
+        if (node.children && node.children.length > 0) {
+          for (let child of node.children) {
+            findAndUpdate(child); // 閫掑綊澶勭悊瀛愯妭鐐�
+          }
+        }
+      }
+
+      for (let node of tree) {
+        findAndUpdate(node); // 瀵规瘡涓《灞傝妭鐐规墽琛屾煡鎵惧拰鏇存柊鎿嶄綔
+      }
+      return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍
+    },
+    // 绔犺妭鍕鹃��
+    checkResourceTitle(e) {
+      const item = e.currentTarget.dataset.item
+      console.log(item, 'item');
+      let list = this.flattenTree([item])
+      let ids = []
+      list.forEach(item => {
+        ids.push(item.id)
+      })
+      const tab = this.findAndUpdateItemsByIds([item], ids)
+      console.log(ids, tab);
     }
+  },
+  onCloudShoppingCart() {
+    console.log(this.properties.treeList);
+  },
+  oncheckbox() {
+    console.log(111);
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1