From e38c14de9637d22d0a35ae06bede82dcf31b64ec Mon Sep 17 00:00:00 2001
From: YM <479443481@qq.com>
Date: 星期二, 10 九月 2024 16:52:58 +0800
Subject: [PATCH] 1

---
 packageBookService/pages/bookServices/detail/buyResource/index.js |  104 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 83 insertions(+), 21 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/buyResource/index.js b/packageBookService/pages/bookServices/detail/buyResource/index.js
index 7e3cbad..a074c5d 100644
--- a/packageBookService/pages/bookServices/detail/buyResource/index.js
+++ b/packageBookService/pages/bookServices/detail/buyResource/index.js
@@ -19,8 +19,8 @@
     checkAllState: true,
     productLinkPath: '',
     refCode: '',
-    haider: false,
-    naData: false
+    naData: false,
+    bookRefCode: []
   },
 
   /**
@@ -86,10 +86,48 @@
     wx.navigateBack();
   },
 
+  // 鑾峰彇鎵�鏈夊瓙椤规暟閲�
+  getChildrenItem(data) {
+    let num = 0
+
+    function getNum(data) {
+      for (let index = 0; index < data.length; index++) {
+        const item = data[index];
+        if (item.sysType == 'CmsItem') {
+          num += 1
+        } else if (item.sysType == 'CmsFolder') {
+          if (item.children && item.children.length)
+            getNum(item.children)
+        }
+      }
+    }
+    getNum(data)
+    return num
+  },
+
+  // 缁櫬风洰褰曟坊鍔犲瓙椤规暟閲�
+  changeResourceChildren(list) {
+    const changeList = (list) => {
+      for (let index = 0; index < list.length; index++) {
+        const item = list[index];
+        if (item.sysType == 'CmsFolder' && item.children && item.children.length) {
+          item.childrenItem = this.getChildrenItem([item])
+          changeList(item.children)
+        } else if (item.sysType == 'CmsFolder' && item.children && !item.children.length) {
+          item.childrenItem = 0
+        } else if (item.sysType == 'CmsFolder' && !item.children) {
+          item.childrenItem = 0
+        }
+      }
+    }
+    changeList(list)
+    return list
+  },
+
   // 鎵佸钩鍖栨暟鎹浆鎹ree
   getTreeList(rootList, pathLength, newArr, path) {
     for (const item of rootList) {
-      if (item.productLinkPath.length == pathLength && item.productLinkPath.includes(path)) {
+      if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) {
         if (item.sysType == 'CmsItem') {
           if (item.selectType == 'webpage') {
             item.disabled = true
@@ -103,8 +141,12 @@
           }
         }
         // newArr.push(item)
-        // 鍦ㄦ彃鍏ヨ繃绋嬩腑瀵规暟鎹繘琛屾帓搴�
-        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
+        // 鍦ㄦ彃鍏ヨ繃绋嬩腑瀵规暟鎹繘琛屾帓搴�  骞朵笖鍘婚櫎宸茬粡棰嗗彇鍜岃喘涔扮殑
+        if (item.sysType == 'CmsFolder') {
+          newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
+        } else if (item.sysType == 'CmsItem' && this.resourceIsBuy(item)) {
+          newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
+        }
       }
     }
     //缁欐暟缁勯噷闈㈠啀娣诲姞涓�涓猚hildren鐨勭┖鏁扮粍
@@ -192,6 +234,7 @@
       itemFields: {
         SysType: 'CmsFolder',
         // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁�
+        learnSelectType: [],
         selectType: [],
         freeFile: [],
         file: [],
@@ -212,7 +255,6 @@
         return this.setData({
           noResources: true,
           loading: false,
-          haider: true,
         });
       }
       let list = []
@@ -237,16 +279,18 @@
           }
         });
         // 鏄剧ず 闇�瑕佽喘涔扮殑鍜岄渶瑕佸厤璐归鍙栫殑
-        const arr = res.datas.cmsDatas[0].datas.filter(item => this.resourceIsBuy(item))
-        if (!arr.length) {
-          return this.setData({
-            loading: false,
-            haider: true,
-            noData: true
-          })
-        }
-        this.getTreeList(arr, 17, list, '\\')
+        // const arr = res.datas.cmsDatas[0].datas.filter(item => this.resourceIsBuy(item))
+        // if (!arr.length) {
+        //   return this.setData({
+        //     loading: false,
+        //     haider: true,
+        //     noData: true
+        //   })
+        // }
+        const num = query.cmsPath.length + 6
+        this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\')
         list = this.ensureTreeConsistency(list)
+        list = this.changeResourceChildren(list)
         console.log('淇敼鍚庝簯', list);
         let result = [];
         if (type.refCode == "jsek_teachingResources") {
@@ -272,7 +316,6 @@
             learn: list,
             loading: false,
             openLearnids: result,
-            haider: true,
           });
         }
       }
@@ -314,7 +357,6 @@
           return this.setData({
             noResources: true,
             loading: false,
-            haider: true,
           });
         }
         //鏁欏璧勬簮 浜戝涔�
@@ -331,7 +373,6 @@
               this.setData({
                 teach: list,
                 loading: false,
-                haider: true
               });
               this.findChildIds(this.data.teach, (this.data.openTeachids = []));
             } else if (type.refCode == "jsek_cloudLearning") {
@@ -344,7 +385,6 @@
                 learn: list,
                 loading: false,
                 openLearnids: result,
-                haider: true
               });
             }
             console.log(list, '浜戝缈�');
@@ -356,7 +396,6 @@
           this.setData({
             test: res.datas.cmsDatas[0].datas,
             loading: false,
-            haider: true
           });
         } else {
           console.log("鍏朵粬");
@@ -480,12 +519,34 @@
       //   productLinkPath: this.data.productLinkPath,
       //   refCode: this.data.refCode,
       // });
+      // this.getResourceCode(
+      //   res.datas.id,
+      //   res.datas.rootCmsItemId
+      // )
       this.getResourceDataList({
         productLinkPath: this.data.productLinkPath,
         refCode: this.data.refCode,
       })
     });
 
+  },
+  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 => {
+      console.log('鍥句功璧勬簮', res.datas.cmsDatas[0].datas);
+    })
   },
   // 鑾峰彇宸茶喘涔板晢鍝�
   getShoppingCartProductGet() {
@@ -526,7 +587,7 @@
       if (isSHow) {
         return false;
       } else {
-        return data.saleMethod[0].price > 0 ? true : false;
+        return data.saleMethod[0].Price > 0 ? true : false;
       }
       return !isSHow;
     } else {
@@ -592,6 +653,7 @@
       this.setData({
         resourceClassList: JSON.parse(res[0].config).option,
       });
+
     });
   },
   checkAll() {

--
Gitblit v1.9.1