From af2e38d1d72633d03afdb6e75f8d30b7ef0d0aee Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 29 七月 2024 15:24:30 +0800
Subject: [PATCH] 图书详情页添加对云学习目录整体购买的判断

---
 packageBookService/pages/bookServices/detail/index.js |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 111 insertions(+), 4 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 94b0dc2..4214b0e 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -81,6 +81,7 @@
     electronicBookList: [], //鏍蜂功鍗曠數瀛愪功
     paperBookCount: 0, //绾歌川涔﹀墿浣欐鏁�
     ebookCount: 0, //鐢靛瓙涔﹀墿浣欐鏁�
+    resourceCodeList: [], // 璧勬簮refcode鍒楄〃
     userInfo: {},
     pageLoading: true,
     fileInfo: {
@@ -387,6 +388,7 @@
       },
     };
     app.MG.store.getProductDetail(query).then(async (res) => {
+      this.getResourceCode(id, res.datas.rootCmsItemId)
       this.setData({
         bookDetail: res.datas,
         buyIdList: res.datas.purchasedSaleMethodIdList,
@@ -459,6 +461,27 @@
 
       });
     });
+  },
+  getResourceCode(bookId, cmsId) {
+    let query = {
+      path: '*',
+      queryType: '*',
+      productId: bookId,
+      cmsPath: cmsId,
+      itemFields: {
+        SysType: 'Cms'
+      },
+      pading: {
+        start: 99,
+        size: 0
+      }
+    }
+    app.MG.store.getProductDetail(query).then((res) => {
+      this.setData({
+        resourceCodeList: res.datas.cmsDatas[0].datas
+      })
+      // console.log('鍥句功璧勬簮', res.datas.cmsDatas[0].datas)
+    })
   },
   //璇锋眰瀛愬晢鍝佺殑鏂囦欢
   getSubTtem() {
@@ -927,7 +950,19 @@
             learnPath: type.productLinkPath
           })
           const dataList = res.datas.cmsDatas[0].datas
-          if (dataList.length) {
+          // 鍏堝垽鏂槸鍚﹀惁涔颁簯瀛︿範鏁翠釜鐩綍
+          let couldId = null
+          let codeData = null
+          if (this.data.resourceCodeList.length) {
+            codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning')
+            if (codeData && codeData.saleMethod && codeData.saleMethod.length)
+              couldId = codeData.saleMethod[0].Id
+          }
+          if (couldId) {
+            this.setData({
+              isGoBuyResource: this.data.buyIdList.indexOf(couldId) > -1 ? false : true
+            })
+          } else if (dataList.length) {
             const tag = dataList.findIndex(item => item.saleMethod.length && item.saleMethod[0].Price > 0)
             this.setData({
               isGoBuyResource: tag > -1 ? true : false
@@ -947,6 +982,10 @@
         let result = [];
         if (type.refCode == "jsek_teachingResources") {
           this.findChildIds(list, result);
+          const newUSeList = this.deleteTreeData(list, result)
+          console.log('鏍戝墧闄�', result, newUSeList);
+          console.log('鏍戝姞涓�', this.increaseTreeData(list, newUSeList, 16094));
+
           this.setData({
             openTeachids: result,
             loading: false,
@@ -1586,7 +1625,16 @@
   },
   // 鍒ゆ柇璧勬簮鏄惁璐拱
   resourceIsBuy(data) {
-    if (data.saleMethod && data.saleMethod.length) {
+    let couldId = null
+    let codeData = null
+    if (this.data.resourceCodeList.length) {
+      codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning')
+      if (codeData && codeData.saleMethod && codeData.saleMethod.length)
+        couldId = codeData.saleMethod[0].Id
+    }
+    if (couldId) {
+      return this.data.buyIdList.indexOf(couldId) > -1 ? false : true
+    } else if (data.saleMethod && data.saleMethod.length) {
       const isSHow = this.data.buyIdList.some(
         (item) => item == data.saleMethod[0].Id
       );
@@ -1632,7 +1680,16 @@
   },
   // 鍒ゆ柇璧勬簮鍔犲叆璐墿杞︽寜閽槸鍚︽樉绀�
   isShoppingCart(data) {
-    if (data.saleMethod && data.saleMethod.length) {
+    let couldId = null
+    let codeData = null
+    if (this.data.resourceCodeList.length) {
+      codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning')
+      if (codeData && codeData.saleMethod && codeData.saleMethod.length)
+        couldId = codeData.saleMethod[0].Id
+    }
+    if (couldId) {
+      return this.data.buyIdList.indexOf(couldId) > -1 ? false : true
+    } else if (data.saleMethod && data.saleMethod.length) {
       if (data.saleMethod[0].Price <= 0) return false;
       // 鍐嶅垽鏂槸鍚﹁喘涔�
       const isBuy = this.data.buyIdList.some(
@@ -2448,4 +2505,54 @@
       teach: tree,
     });
   },
-});
\ No newline at end of file
+
+  // 鍓旈櫎鏍戠粨鏋勫浣欙紝鍙繚鐣欏垵濮嬮渶瑕佸睍寮�鐨�
+  // 绗竴姝ワ細淇濈暀鏍戠粨鏋勫墠涓ゅ眰锛屽苟灏嗗睍寮�椤瑰姞鍏ユ暟缁�
+  deleteTreeData(list, openids) {
+    let resultList = []
+    for (let index = 0; index < list.length; index++) {
+      const item = list[index];
+      for (let cindex = 0; cindex < item.children.length; cindex++) {
+        const citem = item.children[cindex];
+        citem.children = []
+      }
+      resultList.push(item)
+    }
+    for (let index = 0; index < openids.length; index++) {
+      const id = openids[index];
+      // 灞曞紑椤瑰姞鍏ユ暟缁�
+      this.increaseTreeData(list, resultList, id)
+    }
+    return resultList
+  },
+  // 浼犻�抜ds锛屽皢闇�瑕佸睍寮�鐨刬d鐨刢hildren 璧嬪��
+  increaseTreeData(treeList, list, openid) {
+
+    let num = 0;
+    // let useData = treeList.find(item => item.id == openid)
+    for (let index = 0; index < treeList.length; index++) {
+      const item = treeList[index];
+      if (item.id == openid && num >= 3) {
+        debugger
+        let useArr = item.children ? item.children : []
+        changeList(list, openid, useArr)
+      } else {
+        num += 1
+        this.increaseTreeData(item.children, list, openid)
+      }
+    }
+    // 閫掑綊鍓嶄袱灞傦紝鎵惧嚭闇�瑕佸睍寮�鐨�
+    const changeList = (isList, id, childrenList) => {
+      for (let dindex = 0; dindex < isList.length; dindex++) {
+        const ditem = isList[cindex];
+        if (ditem.id == id) {
+          diitem.children = childrenList
+          return true
+        } else {
+          changeList(ditem.children, id, childrenList)
+        }
+      }
+    }
+    return list
+  }
+})
\ No newline at end of file

--
Gitblit v1.9.1