From 9e5a84a4e41d7ab2cb820c7f77122f69a9d036dd Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 26 三月 2024 20:15:09 +0800
Subject: [PATCH] 图书列表、详情代码修改

---
 packageBookService/pages/bookServices/detail/index.js |  274 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 202 insertions(+), 72 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 500be20..69057b1 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -34,6 +34,7 @@
     openTeachids: [],
     openLearnids: [],
     openTestids: [],
+    applyResourceState: false,  // 鐢宠鏁欏璧勬簮鎸夐挳闃叉姈
     resourceClassList: [], // 璧勬簮鎵�灞炲垎绫�
     applyState: "",  // 鏁欏璧勬簮鐢宠鐘舵��
     deadline: "",  // 鏁欏璧勬簮鐢宠鏈夋晥鏃ユ湡
@@ -53,7 +54,6 @@
       mockList: [] // 鐢ㄦ埛缁勫嵎鎻愪氦淇℃伅
     },
     flag: true,
-    applyResourceLoading: false,
     noResources: false,
     selectedIds: "",//鍟嗗搧鎴栧瓙鍟嗗搧閿�鍞柟寮�
     bookBuy: false, //鍟嗗搧鎴栧瓙鍟嗗搧鏄惁璐拱
@@ -67,6 +67,16 @@
     paperBookCount: 0, //绾歌川涔﹀墿浣欐鏁�
     ebookCount: 0, //鐢靛瓙涔﹀墿浣欐鏁�
     userInfo: {},
+    fileInfo: {
+      bookName: "",
+      fileType: "",
+      md5: "",
+      freePage: ""
+    },  //闃呰鍣ㄦ暟鎹�
+    buyResourceData: {
+      productLinkPath: '',
+      refCode: '',
+    }
   },
 
 
@@ -157,7 +167,7 @@
    * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
    */
   onReachBottom() {
-    if (this.data.tabValue == 'jesk_note') {
+    if (this.data.tabValue == 'jsek_note') {
       const child = this.selectComponent('#note')
       child.onReachBottom()
     }
@@ -170,7 +180,7 @@
   // 鏍煎紡鍖栨棩鏈�
   formatDate(dateString) {
     if (!dateString) {
-      return 'Invalid date';
+      return '';
     }
     const match = dateString.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
     if (!match) {
@@ -271,9 +281,12 @@
       });
       this.getSubTtem();
       // 鑾峰彇鍥句功鍒嗙被
-      const iconType = JSON.parse(res.datas.bookClassification)[0][0];
-      const classType = JSON.parse(res.datas.bookClassification)[0][1];
-      const className = await this.getBookClass(iconType, classType)
+      let className = ''
+      if (Array.isArray(res.datas.bookClassification) && res.datas.bookClassification.length) {
+        const iconType = JSON.parse(res.datas.bookClassification)[0][0];
+        const classType = JSON.parse(res.datas.bookClassification)[0][1];
+        className = await this.getBookClass(iconType, classType)
+      }
       // 鑾峰彇缁勫嵎閿�鍞甶d
       if (res.datas.saleMethod && res.datas.saleMethod.length) {
         res.datas.saleMethod.forEach((item) => {
@@ -352,12 +365,42 @@
           this.setData({
             noFile: true
           });
+          if (res.datas[0].bookshelf_pdf) {
+            this.setData({
+              "fileInfo.bookName": this.data.bookDetail.name,
+              "fileInfo.fileType": 'pdf',
+              "fileInfo.md5": res.datas[0].bookshelf_pdf,
+              "fileInfo.freePage": res.datas[0].bookshelf_probationPage,
+            });
+          } 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,
+            });
+          }
         }
       } else {
         if (this.data.bookDetail.pdf || this.data.bookDetail.protectedEpub) {
           this.setData({
             noFile: true
           });
+          if (this.data.bookDetail.pdf) {
+            this.setData({
+              "fileInfo.bookName": this.data.bookDetail.name,
+              "fileInfo.fileType": 'pdf',
+              "fileInfo.md5": this.data.bookDetail.pdf,
+              "fileInfo.freePage": this.data.bookDetail.probationPage,
+            });
+          } else if (this.data.bookDetail.protectedEpub) {
+            this.setData({
+              "fileInfo.bookName": this.data.bookDetail.name,
+              "fileInfo.fileType": 'epub',
+              "fileInfo.md5": this.data.bookDetail.protectedEpub,
+              "fileInfo.freePage": this.data.bookDetail.freeEpubPage,
+            });
+          }
         }
         this.setData({
           selectedIds: this.data.bookDetail.defaultSaleMethodId,
@@ -453,6 +496,12 @@
     if (e.detail.label == '鏁欏璧勬簮' || e.detail.label == '浜戝涔�' || e.detail.label == '浜戞祴璇�') {
       const checkData = this.data.cmsDatas.find(item => item.refCode == e.detail.value)
       if (checkData) {
+        if (e.detail.value == 'jsek_cloudLearning') {
+          this.setData({
+            'buyResourceData.productLinkPath': checkData.productLinkPath,
+            'buyResourceData.refCode': checkData.refCode
+          })
+        }
         if ((e.detail.value == 'jsek_teachingResources' && !this.data.teach.length)
           || (e.detail.value == 'jsek_cloudLearning' && !this.data.learn.length)
           || (e.detail.value == 'questionBank' && !this.data.test.length)) {
@@ -470,6 +519,12 @@
       if (token) {
         child.changeLoading()
         child.getNoteList()
+      }
+
+    } else if (e.detail.label == '鐢靛瓙涔�') {
+      const child = this.selectComponent('#eBook')
+      if (child) {
+        child.getProgress()
       }
 
     }
@@ -536,22 +591,26 @@
               item.checked = false
             })
             const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+            let result = []
             if (type.refCode == 'jsek_teachingResources') {
+              this.findChildIds(list, result)
               this.setData({
                 teach: list,
-                loading: false
+                loading: false,
+                openTeachids: result
               })
-              this.findChildIds(this.data.teach, this.data.openTeachids = [])
+              console.log('鏁欏璧勬簮', this.data.teach, this.data.applyState);
             } else if (type.refCode == 'jsek_cloudLearning') {
-              res.datas.cmsDatas[0].datas.forEach(item => {
-                item.checked = false
-              })
-              const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+              // res.datas.cmsDatas[0].datas.forEach(item => {
+              //   item.checked = false
+              // })
+              // const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+              this.findChildIds(list, result)
               this.setData({
                 learn: list,
-                loading: false
+                loading: false,
+                openLearnids: result
               })
-              this.findChildIds(this.data.learn, this.data.openLearnids = [])
             }
           } else {
             // 鏃犳暟鎹�
@@ -601,7 +660,8 @@
         isDownload: [],
         jsek_resourceBrief: [],
         jsek_link: [],
-        accessType: []
+        accessType: [],
+        learnSelectType: []
       },
       pading: {
         start: 0,
@@ -644,12 +704,12 @@
     for (let i = 0; i < data.length; i++) {
       if (index < 3) {
         const item = data[i]
-        if (item.childrenFolderCount > 0) {
+        if (item.children && item.children.length > 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) {
+              if (item.children && item.children.length > 0) {
                 result.push(childrenItme.id)
                 index += 1
               }
@@ -657,7 +717,7 @@
               break
             }
           }
-        } else if (item.childrenCount > 0) {
+        } else if (item.children && item.children.length > 0) {
           result.push(item.id)
           index += 1
         }
@@ -669,54 +729,65 @@
 
   // 鍥句功娣诲姞璐墿杞�
   async addBookShopcCar() {
-    const token = wx.getStorageSync('jsek-token')
-    if (!token) {
-      return wx.getUserProfile({
-        desc: '鐢ㄦ埛鐧诲綍',
-        success: (res) => {
-          console.log(res);
+
+    if (!this.data.expire) {
+
+      const token = wx.getStorageSync('jsek-token')
+      if (!token) {
+        return wx.getUserProfile({
+          desc: '鐢ㄦ埛鐧诲綍',
+          success: (res) => {
+            console.log(res);
+          }
+        })
+      }
+
+      const shoppingCartGetId = []
+
+      let query = {
+        start: 0,
+        size: 9999,
+        filterList: [],
+        searchList: []
+      }
+      const res = await app.MG.store.getShoppingCartProductList(query)
+      res.datas.forEach((item) => {
+        shoppingCartGetId.push(item.saleMethod.id)
+      })
+      console.log(shoppingCartGetId, 'shoppingCartGetId');
+      console.log(this.data.selectedIds, '閿�鍞柟寮廼d');
+      const determine = shoppingCartGetId.some((item) => item == this.data.selectedIds)
+      console.log(determine);
+      if (!determine) {
+        let query = {
+          requests: [
+            {
+              saleMethodId: this.data.selectedIds,
+              storeEventId: null,
+              agentCode: '鐢靛瓙涔�'
+            }
+          ]
         }
+        const addRes = app.MG.store.addShoppingCart(query)
+        this.showSuccessToast()
+
+      } else {
+        Toast({
+          context: this,
+          selector: '#t-toast',
+          message: '宸叉坊鍔�',
+          theme: 'success',
+          direction: 'column',
+        });
+      }
+    } else {
+      wx.showToast({
+        title: "鍟嗗搧涓嶅湪鏈夋晥鏈�",
+        icon: 'none',
+        duration: 1000,
       })
     }
 
-    const shoppingCartGetId = []
-
-    let query = {
-      start: 0,
-      size: 999,
-      filterList: [],
-      searchList: []
-    }
-    const res = await app.MG.store.getShoppingCartProductList(query)
-    res.datas.forEach((item) => {
-      shoppingCartGetId.push(item.saleMethod.id)
-    })
-    console.log(shoppingCartGetId, 'shoppingCartGetId');
-    console.log(this.data.selectedIds, '閿�鍞柟寮廼d');
-    const determine = shoppingCartGetId.some((item) => item == this.data.selectedIds)
-    console.log(determine);
-    if (!determine) {
-      let query = {
-        requests: [
-          {
-            saleMethodId: this.data.selectedIds,
-            storeEventId: null,
-            agentCode: '鐢靛瓙涔�'
-          }
-        ]
-      }
-      const addRes = app.MG.store.addShoppingCart(query)
-      this.showSuccessToast()
-
-    } else {
-      Toast({
-        context: this,
-        selector: '#t-toast',
-        message: '宸叉坊鍔�',
-        theme: 'success',
-        direction: 'column',
-      });
-    }
 
   },
 
@@ -729,8 +800,6 @@
       direction: 'column',
     });
   },
-
-
 
   async buyBook() {
     if (!this.data.expire) {
@@ -768,7 +837,7 @@
   },
 
   // 鑾峰彇鏁欏璧勬簮涓嬭浇鏄惁鐢宠閫氳繃
-  getApplyInfo(id) {
+  async getApplyInfo(id) {
     // 鑾峰彇褰撳墠鏃堕棿
     const currentDate = new Date()
     let query = {
@@ -781,7 +850,7 @@
       appRefCode: app.config.appRefCode,
       topicIdOrRefCode: 'productDownLoad'
     }
-    app.MG.ugc.getTopicMessageList(query).then((res) => {
+    await app.MG.ugc.getTopicMessageList(query).then((res) => {
       const applyResource = res.datas.find((item) => {
         let content = []
         try {
@@ -837,13 +906,23 @@
       }
     })
     this.setData({
-      applyResourceLoading: false
+      applyResourceState: false,
     })
+    wx.hideLoading()
   },
   // 鐢宠鏁欏璧勬簮
   applyResource() {
+    if (this.data.applyResourceState) {
+      return wx.showToast({
+        icon: 'error',
+        title: '璇峰嬁閲嶅鐐瑰嚮',
+      })
+    }
     this.setData({
-      applyResourceLoading: true
+      applyResourceState: true
+    })
+    wx.showLoading({
+      title: '鍔犺浇涓�',
     })
     // let role = userStore.userInfo ? userStore.userInfo.role : null
     // if (role) {
@@ -865,13 +944,13 @@
         }
       ])
     }
-    app.MG.ugc.newTopicMessage(query).then((res) => {
+    app.MG.ugc.newTopicMessage(query).then(async (res) => {
       if (res) {
         wx.showToast({
           title: '鐢宠宸叉彁浜わ紝璇峰緟瀹℃牳閫氳繃鍚庝笅杞�',
         })
       }
-      this.getApplyInfo(this.data.bookDetail.id)
+      await this.getApplyInfo(this.data.bookDetail.id)
     })
     //   } else {
     //     ElMessageBox.confirm('璇峰厛杩涜鏁欏笀璁よ瘉锛�', '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', {
@@ -1237,7 +1316,6 @@
         keys: [this.data.bookId]
       })
       .then((res) => {
-        console.log(JSON.parse(res[0].value));
         if (res && res.length) {
           const mock = JSON.parse(res[0].value)
           mock.forEach(item => {
@@ -1342,11 +1420,27 @@
     }
   },
 
+  goRead() {
+    if (!this.data.noFile) {
+      wx.showToast({
+        title: '鏆傛棤闃呰鏂囦欢',
+        icon: 'none',
+        duration: 2000
+      })
+      return false;
+    }
+    wx.navigateTo({
+      url: '/packageBookService/pages/components/webView/index?md5=' + this.data.fileInfo.md5 + '&fileName=' + this.data.fileInfo.bookName + '&fileType=' + this.data.fileInfo.fileType + '&freePage=' + this.data.fileInfo.freePage
+    })
+
+  },
+
   //鏍蜂功鐢宠
   //鐢宠鐢靛瓙鏍蜂功
   appplyElectronicBook() {
     console.log(this.data.bookDetail)
     if (this.data.bookDetail.isApplyBook == 2 || this.data.bookDetail.isApplyBook == 4) {
+
       let role = this.data.userInfo != null ? this.data.userInfo.role : null
       if (role) {
         if (role == 'Teacher') {
@@ -1374,6 +1468,12 @@
           })
         }
       }
+    } else {
+      wx.showToast({
+        title: "璇ヤ功涓嶈兘鐢宠鐢靛瓙鏍蜂功",
+        icon: 'none',
+        duration: 1000,
+      })
     }
   },
   //鐢宠绾歌川鏍蜂功
@@ -1398,6 +1498,12 @@
           })
         }
       }
+    } else {
+      wx.showToast({
+        title: "璇ヤ功涓嶈兘鐢宠绾歌川鏍蜂功",
+        icon: 'none',
+        duration: 1000,
+      })
     }
   },
   //鑾峰彇褰撳墠宸茬敵璇锋鏁帮紙绾歌川锛�
@@ -1616,5 +1722,29 @@
       url: "/packageDomain/pages/sampleBookList/applicationForm/index",
     });
   },
-
+  handleTree() {
+    // const child = this.selectComponent('#teach-tree')
+    let tree
+    // let openIds = child.data.openIds
+    if (this.data.tabValue == 'jsek_teachingResources') {
+      tree = this.data.teach
+    } else {
+      tree = this.data.learn
+    }
+    for (let index = 0; index < tree.length; index++) {
+      const item = tree[index];
+      if (item.children && item.children.length > 0) {
+        const num = this.data.openTeachids.findIndex(citem => item.id == citem)
+        if (num >= 0) {
+          item.open = true
+        } else {
+          item.open = false
+        }
+        this.handleTree(item.children)
+      }
+    }
+    this.setData({
+      teach: tree
+    })
+  },
 })

--
Gitblit v1.9.1