From f16f827b03d7b148e6ea4a52b66d14c577f1d0ca Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期四, 11 七月 2024 14:07:26 +0800
Subject: [PATCH] url

---
 packageBookService/pages/bookServices/detail/index.js |  198 +++++++++++++++++++++++++-----------------------
 1 files changed, 103 insertions(+), 95 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 3ee1ff3..a101f1d 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -16,6 +16,7 @@
     options: {
       id: "",
       name: "",
+      storeInfo: '',
     },
     bookDetail: {},
     bookClass: [],
@@ -37,6 +38,8 @@
     openTeachids: [],
     openLearnids: [],
     openTestids: [],
+    isGoBuyResource: true,
+    learnPath: '',
     applyResourceState: false, // 鐢宠鏁欏璧勬簮鎸夐挳闃叉姈
     resourceClassList: [], // 璧勬簮鎵�灞炲垎绫�
     applyState: "", // 鏁欏璧勬簮鐢宠鐘舵��
@@ -177,6 +180,7 @@
       options: {
         id: options.id,
         name: options.name,
+        storeInfo: options.storeInfo,
       },
     });
     wx.setNavigationBarTitle({
@@ -346,6 +350,7 @@
       "mockData.count": 0,
     });
     const query = {
+      storeInfo: this.data.options.storeInfo,
       path: "*",
       queryType: "*",
       productId: id,
@@ -384,6 +389,7 @@
       this.setData({
         bookDetail: res.datas,
         buyIdList: res.datas.purchasedSaleMethodIdList,
+        pageLoading: false
       });
       if (res.datas.cmsDatas && res.datas.cmsDatas.length) {
         this.setData({
@@ -444,7 +450,7 @@
         "bookDetail.paperPrice": this.numFormat(
           this.data.bookDetail.paperPrice
         ),
-        pageLoading: false,
+
       });
       console.log("鍥句功淇℃伅", this.data.bookClass);
     });
@@ -507,14 +513,14 @@
               "fileInfo.bookName": this.data.bookDetail.name,
               "fileInfo.fileType": "pdf",
               "fileInfo.md5": res.datas[0].bookshelf_pdf,
-              "fileInfo.freePage": res.datas[0].bookshelf_probationPage,
+              "fileInfo.freePage": res.datas[0].bookshelf_probationPage ? res.datas[0].bookshelf_probationPage : 30,
             });
           } else if (res.datas[0].bookshelf_protectedEpub) {
             this.setData({
               "fileInfo.bookName": this.data.bookDetail.name,
               "fileInfo.fileType": "epub",
               "fileInfo.md5": res.datas[0].bookshelf_protectedEpub,
-              "fileInfo.freePage": res.datas[0].bookshelf_freeEpub,
+              "fileInfo.freePage": res.datas[0].bookshelf_freeEpub ? res.datas[0].bookshelf_freeEpub : 30,
             });
           }
         }
@@ -528,7 +534,7 @@
               "fileInfo.bookName": this.data.bookDetail.name,
               "fileInfo.fileType": "pdf",
               "fileInfo.md5": this.data.bookDetail.pdf,
-              "fileInfo.freePage": this.data.bookDetail.probationPage,
+              "fileInfo.freePage": this.data.bookDetail.probationPage ? this.data.bookDetail.probationPage : 30,
             });
           } else if (this.data.bookDetail.protectedEpub) {
 
@@ -536,7 +542,7 @@
               "fileInfo.bookName": this.data.bookDetail.name,
               "fileInfo.fileType": "epub",
               "fileInfo.md5": this.data.bookDetail.protectedEpub,
-              "fileInfo.freePage": this.data.bookDetail.freeEpubPage,
+              "fileInfo.freePage": this.data.bookDetail.freeEpubPage ? this.data.bookDetail.freeEpubPage : 30,
             });
           }
         }
@@ -638,6 +644,8 @@
       this.setData({
         showIndex: '1'
       })
+    console.log(this.data.bookDetail.icon, '0111111');
+    console.log(this.data.bookDetail.name, '45688');
   },
   // 璺宠浆缃戝簵
   goShop(e) {
@@ -683,9 +691,7 @@
         //   this.getResourceData(checkData);
         // }
         if ((e.detail.value == "jsek_teachingResources" && !this.data.teach.length) || (e.detail.value == "jsek_cloudLearning" && !this.data.learn.length)) {
-          if (e.detail.value == "jsek_teachingResources") {
-            wx.setStorageSync('teachResourcesPath', checkData.productLinkPath)
-          }
+          wx.setStorageSync('teachResourcesPath', checkData.productLinkPath)
           this.getResourceDataList(checkData)
         } else if (e.detail.value == "questionBank" && !this.data.test.length) {
           this.getResourceData(checkData);
@@ -746,7 +752,7 @@
     return num
   },
 
-  // 缁櫬风洰褰曟坊鍔犲瓙椤规暟閲�
+  // 缁欑洰褰曟坊鍔犲瓙椤规暟閲�
   changeResourceChildren(list) {
     const changeList = (list) => {
       for (let index = 0; index < list.length; index++) {
@@ -766,7 +772,7 @@
   },
 
   // 鎵佸钩鍖栨暟鎹浆鎹ree
-  getTreeList(rootList, pathLength, newArr, path) {
+  getTreeList(rootList, pathLength, newArr, path, addNum) {
     for (const item of rootList) {
       // 姝ゅ鍘熸湰 item.productLinkPath.length == pathLength 浣� productLinkPath 闀垮害涓埆涔﹀瓨鍦�4銆�5浣嶄氦閿�
       if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) {
@@ -784,13 +790,13 @@
         }
         // newArr.push(item)
         // 鍦ㄦ彃鍏ヨ繃绋嬩腑瀵规暟鎹繘琛屾帓搴�
-        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item)
+        newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item, addNum)
       }
     }
     //缁欐暟缁勯噷闈㈠啀娣诲姞涓�涓猚hildren鐨勭┖鏁扮粍
     for (const i of newArr) {
       i.children = []
-      this.getTreeList(rootList, pathLength + 6, i.children, i.productLinkPath)
+      this.getTreeList(rootList, pathLength + addNum, i.children, i.productLinkPath, addNum)
       if (i.children.length == 0) {
         delete i.children
       }
@@ -815,9 +821,9 @@
   },
 
   // 鎺掑簭鏁扮粍 鎸夌収productLinkPath
-  insertAndSortObjectsByProductLinkPath(array, newObj) {
+  insertAndSortObjectsByProductLinkPath(array, newObj, addNum) {
     // 鏌ユ壘鏂板璞″簲璇ユ彃鍏ョ殑浣嶇疆  
-    let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - 6, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - 6, obj.productLinkPath.length)));
+    let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - addNum, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - addNum, obj.productLinkPath.length)));
 
     // 濡傛灉娌℃湁鎵惧埌鍚堥�傜殑浣嶇疆锛屽垯鏀惧湪鏁扮粍鏈熬  
     if (insertIndex === -1) {
@@ -828,10 +834,10 @@
     // 娴嬭瘯6 姝e紡5
     // 瀵规暟缁勮繘琛屾帓搴�  
     array.sort((a, b) => {
-      if (Number(a.productLinkPath.substring(a.productLinkPath.length - 5, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - 5, b.productLinkPath.length))) {
+      if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) {
         return -1;
       }
-      if (Number(a.productLinkPath.substring(a.productLinkPath.length - 5, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - 5, b.productLinkPath.length))) {
+      if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) {
         return 1;
       }
       // a must be equal to b  
@@ -850,6 +856,7 @@
     let query = {
       path: '*',
       queryType: '*',
+      storeInfo: this.data.options.storeInfo,
       productId: this.data.bookDetail.id,
       cmsPath: type.productLinkPath,
       cmsType: '*',
@@ -900,8 +907,25 @@
             }
           }
         });
-        const num = query.cmsPath.length + 6
-        this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\')
+        if (type.refCode == "jsek_cloudLearning") {
+          this.setData({
+            learnPath: type.productLinkPath
+          })
+          const dataList = res.datas.cmsDatas[0].datas
+          if (dataList.length) {
+            const tag = dataList.findIndex(item => item.saleMethod.length && item.saleMethod[0].Price > 0)
+            this.setData({
+              isGoBuyResource: tag > -1 ? true : false
+            })
+          } else {
+            this.setData({
+              isGoBuyResource: false
+            })
+          }
+        }
+        const addNum = query.cmsPath.length > 12 ? 7 : query.cmsPath.length > 14 ? 8 : 6
+        const num = query.cmsPath.length + addNum
+        this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\', addNum)
         list = this.ensureTreeConsistency(list)
         list = this.changeResourceChildren(list)
         console.log('淇敼鍚庝簯', list);
@@ -943,8 +967,10 @@
     let query = {
       path: "*",
       queryType: "*",
+      storeInfo: this.data.options.storeInfo,
       productId: this.data.bookDetail.id,
       cmsPath: type.productLinkPath,
+      cmsType: '*',
       itemFields: {
         SysType: "CmsFolder",
         // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁�
@@ -965,67 +991,46 @@
     app.MG.store
       .getProductDetail(query)
       .then(async (res) => {
-        if (!res.datas.cmsDatas[0].datas.length) {
-          return this.setData({
-            noResources: true,
-            loading: false,
-          });
-        }
         // 浜戞祴璇曪紝閫掑綊璇锋眰閲屽眰鏁版嵁
         if (type.refCode == "questionBank") {
-          const data = res.datas.cmsDatas[0].datas.filter(
-            (item) => item.refCode == "jsek_questionBank"
-          );
-          if (data.length) return this.getResourceData(data[0]);
-        }
-        //鏁欏璧勬簮 浜戝涔�
-        if (
-          type.refCode == "jsek_teachingResources" ||
-          type.refCode == "jsek_cloudLearning"
-        ) {
-          if (res.datas.cmsDatas[0].datas.length > 0) {
-            res.datas.cmsDatas[0].datas.forEach((item) => {
-              item.checked = false;
-            });
-            const list = await this.getAllResource(res.datas.cmsDatas[0].datas);
-            let result = [];
-            if (type.refCode == "jsek_teachingResources") {
-              this.findChildIds(list, result);
+          let data = []
+          let result = [];
+          if (this.data.options.storeInfo == 'jsek_jslx') {
+            data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder');
+            if (data.length > 0) {
               this.setData({
-                teach: list,
+                test: data,
                 loading: false,
                 openTeachids: result,
               });
-            } else if (type.refCode == "jsek_cloudLearning") {
-              let arr = this.handleTreeData(list).filter(
-                (item) => item.saleMethod[0]
-              );
-              let freeIds = arr.filter((item) => {
-                return item.saleMethod[0].Price == 0;
-              });
-              if (!freeIds.length)
-                this.setData({
-                  isshowDrawBtn: false,
-                });
-              this.findChildIds(list, result);
+            } else {
               this.setData({
-                learn: list,
+                noResources: true,
                 loading: false,
-                openLearnids: result,
               });
             }
-            console.log(list, '浜戝缈�789');
           } else {
-            // 鏃犳暟鎹�
+            data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder' && item.childrenFolderCount > 0);
+            if (data.length > 0) {
+              let list = []
+              // 娴嬭瘯 6浣�// 姝e紡 5浣�//  娴嬭瘯璋冪敤浼�20锛屽唴閮�7  姝e紡璋冪敤浼�17 鍐呴儴浼�6
+              const addNum = query.cmsPath.length > 12 ? 7 : query.cmsPath.length > 14 ? 8 : 6
+              const num = query.cmsPath.length + addNum
+              this.getTreeList(data, num, list, '\\', addNum)
+              list = this.ensureTreeConsistency(list)
+              this.findChildIds(list[0].children, result);
+              this.setData({
+                test: list[0].children,
+                loading: false,
+                openTeachids: result,
+              });
+            } else {
+              this.setData({
+                noResources: true,
+                loading: false,
+              });
+            }
           }
-        } else if (type.refCode == "jsek_questionBank") {
-          // const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
-          this.setData({
-            test: res.datas.cmsDatas[0].datas,
-            loading: false,
-          });
-        } else {
-          console.log("鍏朵粬");
         }
       })
       .catch((e) => {
@@ -1050,6 +1055,7 @@
     let query = {
       path: "*",
       queryType: "*",
+      storeInfo: this.data.options.storeInfo,
       productId: this.data.bookDetail.id,
       cmsPath: path,
       itemFields: {
@@ -1119,30 +1125,33 @@
   // 鑾峰彇灞曞紑椤�
   findChildIds(data, result) {
     let index = 0
-    for (let i = 0; i < data.length; i++) {
-      if (index < 3) {
-        const item = data[i]
-        if (item.childrenFolderCount > 0) {
-          result.push(item.id)
-          for (let j = 0; j < item.children.length; j++) {
-            if (index < 3) {
-              const childrenItme = item.children[j]
-              if (item.childrenCount > 0) {
-                result.push(childrenItme.id)
-                index += 1
+    if (data)
+      for (let i = 0; i < data.length; i++) {
+        if (index < 3) {
+          const item = data[i]
+          if (item.childrenFolderCount > 0) {
+            result.push(item.id)
+            if (item.children) {
+              for (let j = 0; j < item.children.length; j++) {
+                if (index < 3) {
+                  const childrenItme = item.children[j]
+                  if (item.childrenCount > 0) {
+                    result.push(childrenItme.id)
+                    index += 1
+                  }
+                } else {
+                  break
+                }
               }
-            } else {
-              break
             }
+          } else if (item.childrenCount > 0) {
+            result.push(item.id)
+            index += 1
           }
-        } else if (item.childrenCount > 0) {
-          result.push(item.id)
-          index += 1
+        } else {
+          break
         }
-      } else {
-        break
       }
-    }
   },
 
   // 鍥句功娣诲姞璐墿杞�
@@ -1214,7 +1223,6 @@
       // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉
       const res = await app.MG.store.initOrder(query);
       // 鑾峰彇璁㈠崟鍙峰苟璧嬪�肩粰 orderNumber.value
-      console.log(res, 'res456');
       bookOrdersId = res.orderNumber;
       // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪
       if (bookOrdersId) {
@@ -1562,7 +1570,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 {
@@ -1686,19 +1694,19 @@
         };
         // 纭璁㈠崟
         const confirmOrderRes = await app.MG.store.confirmOrder(parameter);
-        console.log(confirmOrderRes.orderNumber, 'confirmOrderRes.orderNumber');
-
         if (confirmOrderRes.orderNumber) {
           child.changeReceive(false);
           wx.showToast({
             title: "棰嗗彇鎴愬姛",
           });
           this.getBookInfo(this.data.bookId);
+          this.getResourceDataList({
+            refCode: 'jsek_cloudLearning',
+            productLinkPath: this.data.learnPath
+          })
           this.setData({
             successOrderNumber: confirmOrderRes.orderNumber
           })
-
-
         }
       } catch (error) {
         console.log(error);
@@ -2026,7 +2034,6 @@
         this.data.bookDetail.id,
 
     });
-    debugger
   },
 
   //鏍蜂功鐢宠
@@ -2093,7 +2100,7 @@
         const smBook = list.find(item => item.content[0].id == this.data.bookDetail.id)
         console.log('宸茬敵璇�', smBook);
         if (smBook && smBook.state == 'Normal') {
-          const flag = new Date(JSON.parse(smBook.feedBack).endDate + '23:59:59').getTime() > new Date().getTime()
+          const flag = new Date(smBook.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime()
           if (flag) {
             this.setData({
               applicationState: 'Normal'
@@ -2203,7 +2210,8 @@
             });
             return false;
           } else if (isApply.state == 'Normal') {
-            const flag = new Date(JSON.parse(isApply.feedBack).endDate + '23:59:59').getTime() > new Date().getTime()
+            console.log(isApply.state, "isApply.state")
+            const flag = new Date(isApply.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime()
             if (flag) {
               wx.showToast({
                 title: "璇ヤ功宸茬敵璇凤紒",

--
Gitblit v1.9.1