From d61a31af1b8a220af669c818f11b6a13c1fb8dba Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 26 三月 2024 16:15:36 +0800
Subject: [PATCH] 图书详情页布局调整

---
 packageBookService/pages/bookServices/detail/index.js |   74 +++++++++++++++++++++++++-----------
 1 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index bc9ec6c..e04604d 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, //鍟嗗搧鎴栧瓙鍟嗗搧鏄惁璐拱
@@ -180,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) {
@@ -281,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) => {
@@ -589,22 +592,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);
             } 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 {
             // 鏃犳暟鎹�
@@ -654,7 +661,8 @@
         isDownload: [],
         jsek_resourceBrief: [],
         jsek_link: [],
-        accessType: []
+        accessType: [],
+        learnSelectType: []
       },
       pading: {
         start: 0,
@@ -794,8 +802,6 @@
     });
   },
 
-
-
   async buyBook() {
     if (!this.data.expire) {
       let bookOrdersId = ''
@@ -832,7 +838,7 @@
   },
 
   // 鑾峰彇鏁欏璧勬簮涓嬭浇鏄惁鐢宠閫氳繃
-  getApplyInfo(id) {
+  async getApplyInfo(id) {
     // 鑾峰彇褰撳墠鏃堕棿
     const currentDate = new Date()
     let query = {
@@ -845,7 +851,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 {
@@ -901,13 +907,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) {
@@ -929,13 +945,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('璇峰厛杩涜鏁欏笀璁よ瘉锛�', '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', {
@@ -1301,7 +1317,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 => {
@@ -1426,6 +1441,7 @@
   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') {
@@ -1453,6 +1469,12 @@
           })
         }
       }
+    } else {
+      wx.showToast({
+        title: "璇ヤ功涓嶈兘鐢宠鐢靛瓙鏍蜂功",
+        icon: 'none',
+        duration: 1000,
+      })
     }
   },
   //鐢宠绾歌川鏍蜂功
@@ -1477,6 +1499,12 @@
           })
         }
       }
+    } else {
+      wx.showToast({
+        title: "璇ヤ功涓嶈兘鐢宠绾歌川鏍蜂功",
+        icon: 'none',
+        duration: 1000,
+      })
     }
   },
   //鑾峰彇褰撳墠宸茬敵璇锋鏁帮紙绾歌川锛�

--
Gitblit v1.9.1