From e6a156a6a8bb6f1d3a17e9310269f53c56e10b42 Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期一, 08 四月 2024 22:29:26 +0800
Subject: [PATCH] 问题修改

---
 packageDomain/pages/sampleBookList/index.js |  128 +++++++++++++++++++++++++++++++-----------
 1 files changed, 94 insertions(+), 34 deletions(-)

diff --git a/packageDomain/pages/sampleBookList/index.js b/packageDomain/pages/sampleBookList/index.js
index 746250a..eb4db74 100644
--- a/packageDomain/pages/sampleBookList/index.js
+++ b/packageDomain/pages/sampleBookList/index.js
@@ -145,11 +145,7 @@
       this.setData({
         userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
       })
-      this.getAlreadyPBookList()
-      this.getAlreadyEBookList()
-      // 鑾峰彇鐢宠娆℃暟
-      this.getSelectPaperBookCount()
-      this.getSelectBookCount()
+
     }
   },
 
@@ -164,19 +160,32 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
    */
   onShow() {
-    if (wx.getStorageSync("paperBookList")) {
-      this.setData({
-        paperBookList: wx.getStorageSync("paperBookList"),
-      })
-    }
-    if (wx.getStorageSync("electronicBookList")) {
-      this.setData({
-        electronicBookList: wx.getStorageSync("electronicBookList"),
-      })
-    }
     this.setData({
-      num: this.data.paperBookList.length + this.data.electronicBookList.length
+      page: 1,
+      paperBookList: [],
+      electronicBookList: []
     })
+    this.getAlreadyPBookList()
+    this.getAlreadyEBookList()
+    // 鑾峰彇鐢宠娆℃暟
+    this.getSelectPaperBookCount()
+    this.getSelectBookCount()
+    console.log(this.data.electronicBookList.length, this.data.paperBookList.length, 1)
+    if (wx.getStorageSync("paperBookList") || wx.getStorageSync("electronicBookList")) {
+      if (wx.getStorageSync("paperBookList")) {
+        this.setData({
+          paperBookList: wx.getStorageSync("paperBookList"),
+        })
+      }
+      if (wx.getStorageSync("electronicBookList")) {
+        this.setData({
+          electronicBookList: wx.getStorageSync("electronicBookList"),
+        })
+      }
+      this.setData({
+        num: this.data.paperBookList.length + this.data.electronicBookList.length
+      })
+    }
     this.getBookList(false);
   },
   goBack() {
@@ -184,7 +193,7 @@
   },
 
   // 鑾峰彇绾歌川涔﹀墿浣欐鏁�
-  getSelectPaperBookCount(item) {
+  getSelectPaperBookCount() {
     app.MG.app
       .getTicketResult({
         ticketRefCodeOrGuid: 'paperSampleBookapplyNum',
@@ -197,7 +206,7 @@
       })
   },
   // 鑾峰彇鐢靛瓙涔﹀墿浣欐鏁�
-  getSelectBookCount(item) {
+  getSelectBookCount() {
     app.MG.app
       .getTicketResult({
         ticketRefCodeOrGuid: 'electronicSampleBookapplyNum',
@@ -278,6 +287,7 @@
         'stairList.options': options,
         'stairList.value': this.data.stairCode,
       });
+      console.log(this.data.stairList.options)
     });
   },
   // 鑾峰彇涓�绾у垎绫讳笅浜岀骇鍒嗙被
@@ -410,6 +420,8 @@
         author: [],
         isbn: [],
         publicationDate: [],
+        pdf: [],
+        protectedEpub: [],
         isApplyBook: [],
         'isApplyBook>': ['1'],
         ...searchObj,
@@ -429,26 +441,30 @@
             }
             if (that.data.alreadyPaperBookList.length > 0) {
               that.data.alreadyPaperBookList.forEach((pBook) => {
-                pBook.content.forEach((pBookItem) => {
-                  if (pBookItem.id === item.id && pBook.state == 'WaitAudit') {
-                    item.paperDisabled = true
-                    item.paperChecked = true
-                  }
-                  if (pBookItem.id === item.id && pBook.state == 'Normal') {
-                    item.paperDisabled = false
-                  }
-                })
+                if (pBook.content.length > 0) {
+                  pBook.content.forEach((pBookItem) => {
+                    if (pBookItem.id === item.id && pBook.state == 'WaitAudit') {
+                      item.paperDisabled = true
+                      item.paperChecked = true
+                    }
+                    if (pBookItem.id === item.id && pBook.state == 'Normal') {
+                      item.paperDisabled = false
+                    }
+                  })
+                }
               })
             }
 
             if (that.data.alreadyElectronicBookList.length > 0) {
               that.data.alreadyElectronicBookList.forEach((eBook) => {
-                eBook.content.forEach((eBookItem) => {
-                  if (eBookItem.id === item.id && !eBook.isExpiry && eBook.state != 'Reject') {
-                    item.electronDisabled = true
-                    item.electronChecked = true
-                  }
-                })
+                if (eBook.content.length > 0) {
+                  eBook.content.forEach((eBookItem) => {
+                    if (eBookItem.id === item.id && !eBook.isExpiry && eBook.state != 'Reject') {
+                      item.electronDisabled = true
+                      item.electronChecked = true
+                    }
+                  })
+                }
               })
             }
             if (that.data.paperBookList.length > 0) {
@@ -481,6 +497,9 @@
           })
         } else {
           that.setData({
+            bookList: [],
+            pageTotalCount: 0,
+            bottomLoading: false,
             skeletonLoding: false,
             loading: false
           })
@@ -793,14 +812,55 @@
   },
 
   //閫夋嫨鐢靛瓙鏍蜂功
-  onChangeElectron(e) {
+  async onChangeElectron(e) {
     const item = e.currentTarget.dataset.book;
+    console.log(item)
     const index = this.data.bookList.findIndex(citem => citem.id == item.id)
     let role = this.data.userInfo != null ? this.data.userInfo.role : null
     if (role && role == 'Teacher') {
       // 鏄暀甯�
       if (e.detail.checked) {
         // 鐐瑰嚮閫変腑
+        //鍟嗗搧鏈夋棤鐢靛瓙涔�
+        const obj = {
+          path: '*',
+          queryType: 'SubProduct',
+          sort: {
+            type: 'Desc',
+            field: 'CreateDate'
+          },
+          paging: {
+            start: 0,
+            size: 1
+          },
+          mainProductId: item.id,
+          fields: {
+            bookshelf_pdf: [],
+            bookshelf_protectedEpub: [],
+          }
+        }
+        const res = await app.MG.store.getProductList(obj)
+        if (res.datas.length > 0) {
+          if (!res.datas[0].bookshelf_pdf && !res.datas[0].bookshelf_protectedEpub) {
+            wx.showToast({
+              title: "鏆傛棤鐢靛瓙涔︽枃浠�,璇疯仈绯荤鐞嗗憳!",
+              icon: 'none',
+              duration: 1000,
+            })
+            return false;
+          }
+        } else {
+          if (!item.pdf && !item.protectedEpub) {
+            wx.showToast({
+              title: "鏆傛棤鐢靛瓙涔︽枃浠�,璇疯仈绯荤鐞嗗憳!",
+              icon: 'none',
+              duration: 1000,
+            })
+            return false;
+          }
+        }
+
+        //鐢宠娆℃暟
         if (this.data.ebookCount == 0) {
           wx.showToast({
             title: "鎮ㄧ殑鐢靛瓙鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",

--
Gitblit v1.9.1