From 0555dd7dc2edc553030b7a6d03d6a1cda4b1e336 Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期三, 20 三月 2024 15:41:58 +0800
Subject: [PATCH] 111

---
 packageDomain/pages/sampleBookList/index.js |  138 ++++++++++++++++++++++++++++++---------------
 1 files changed, 91 insertions(+), 47 deletions(-)

diff --git a/packageDomain/pages/sampleBookList/index.js b/packageDomain/pages/sampleBookList/index.js
index 30be704..c43b0aa 100644
--- a/packageDomain/pages/sampleBookList/index.js
+++ b/packageDomain/pages/sampleBookList/index.js
@@ -63,6 +63,7 @@
     electronicBookList: [], //鏍蜂功鍗曠數瀛愪功
     paperBookCount: 0, //绾歌川涔﹀墿浣欐鏁�
     ebookCount: 0, //鐢靛瓙涔﹀墿浣欐鏁�
+    num: 0,
   },
 
   /**
@@ -117,7 +118,7 @@
       })
     }
     this.getIconTypeList();
-    this.getBookList(false);
+
     // 鑾峰彇閲嶇偣椤圭洰
     this.getProjectList('bookClassification');
     //鏂板舰鎬佹暀鏉�
@@ -133,14 +134,18 @@
     }
     if (wx.getStorageSync("paperBookList")) {
       this.setData({
-        paperBookList: wx.getStorageSync("paperBookList")
+        paperBookList: wx.getStorageSync("paperBookList"),
       })
     }
     if (wx.getStorageSync("electronicBookList")) {
       this.setData({
-        electronicBookList: wx.getStorageSync("electronicBookList")
+        electronicBookList: wx.getStorageSync("electronicBookList"),
       })
     }
+    this.setData({
+      num: this.data.paperBookList.length + this.data.electronicBookList.length
+    })
+    this.getBookList(false);
   },
 
   /**
@@ -299,7 +304,6 @@
         this.setData({
           'newTextBook.options': options,
         });
-        console.log('閲嶇偣椤圭洰', this.data.newTextBook);
       }
     });
   },
@@ -389,6 +393,7 @@
                 })
               })
             }
+
             if (that.data.alreadyElectronicBookList.length > 0) {
               that.data.alreadyElectronicBookList.forEach((eBook) => {
                 eBook.content.forEach((eBookItem) => {
@@ -546,7 +551,6 @@
   },
   // 鎼滅储鍥句功
   searchBook(e) {
-    console.log(e.detail.value);
     this.setData({
       searchValue: e.detail.value,
     });
@@ -572,13 +576,15 @@
       }
     }
     app.MG.ugc.getTopicMessageList(data).then((res) => {
+      let list = [];
       res.datas.map((item) => {
         if (item.content) {
           item.content = JSON.parse(item.content)
         }
+        list.push(item)
       })
       this.setData({
-        alreadyPaperBookList: res.datas,
+        alreadyPaperBookList: list,
       });
     })
   },
@@ -596,27 +602,30 @@
     }
     app.MG.ugc.getTopicMessageList(data).then((res) => {
       let list = []
-      res.datas.map((item) => {
-        if (item.feedBack) {
-          item.feedBack = JSON.parse(item.feedBack)
-          if (item.feedBack.endDate) {
-            let times = new Date(item.feedBack.endDate + ' 23:59:59').getTime()
-            let currentDate = new Date().getTime()
-            if (times < currentDate) {
-              item.isExpiry = true
+      if (res.datas.length > 0) {
+        res.datas.map((item) => {
+          if (item.feedBack) {
+            item.feedBack = JSON.parse(item.feedBack)
+            if (item.feedBack.endDate) {
+              let times = new Date(item.feedBack.endDate + ' 23:59:59').getTime()
+              let currentDate = new Date().getTime()
+              if (times < currentDate) {
+                item.isExpiry = true
+              }
             }
           }
-        }
-        if (item.content) {
-          item.content = JSON.parse(item.content)
-        }
-        if (item.state != 'Reject') {
-          list.push(item)
-        }
-      })
-      this.setData({
-        alreadyElectronicBookList: list,
-      });
+          if (item.content) {
+            item.content = JSON.parse(item.content)
+          }
+          if (item.state != 'Reject') {
+            list.push(item)
+          }
+        })
+        this.setData({
+          alreadyElectronicBookList: list,
+        });
+        this.getBookList(false);
+      }
     })
   },
 
@@ -681,12 +690,12 @@
         })
         return
       }
-
       if (item.paperChecked) {
-        if (this.data.paperBookList.length > 0) {
-          this.data.paperBookList.forEach((obj, index) => {
+        let pList = this.data.paperBookList;
+        if (pList.length > 0) {
+          pList.forEach((obj, index) => {
             if (obj.id == item.id) {
-              this.data.paperBookList.splice(index, 1);
+              pList.splice(index, 1);
             }
           })
         }
@@ -703,7 +712,11 @@
           icon: 'none',
           duration: 1000,
         })
-        wx.setStorageSync("paperBookList", JSON.stringify(this.data.paperBookList));
+        this.setData({
+          paperBookList: pList,
+          num: pList.length + this.data.electronicBookList.length
+        })
+        wx.setStorageSync("paperBookList", JSON.stringify(pList));
         return
       }
       if (role == 'Teacher') {
@@ -757,10 +770,11 @@
         return
       }
       if (item.electronChecked) {
-        if (this.data.electronicBookList) {
-          this.data.electronicBookList.forEach((obj, index) => {
+        let eList = this.data.electronicBookList;
+        if (eList.length > 0) {
+          eList.forEach((obj, index) => {
             if (obj.id == item.id) {
-              this.data.electronicBookList.splice(index, 1);
+              eList.splice(index, 1);
             }
           })
         }
@@ -777,7 +791,11 @@
           icon: 'none',
           duration: 1000,
         })
-        wx.setStorageSync("electronicBookList", JSON.stringify(this.data.electronicBookList));
+        this.setData({
+          electronicBookList: eList,
+          num: eList.length + this.data.paperBookList.length
+        })
+        wx.setStorageSync("electronicBookList", eList);
         return
       }
       if (role == 'Teacher') {
@@ -830,6 +848,8 @@
           }
         })
       }
+    } else {
+      item.electronChecked = false
     }
   },
   getSelectBookCount(item) {
@@ -889,16 +909,28 @@
               duration: 1000,
             })
             this.setData({
-              electronicBookList: [...this.data.electronicBookList, ...[item]]
+              electronicBookList: [...this.data.electronicBookList, ...[itemAttr]],
+              num: this.data.electronicBookList.length + this.data.paperBookList.length
             })
-            wx.setStorageSync("electronicBookList", JSON.stringify(this.data.electronicBookList));
+            wx.setStorageSync("electronicBookList", this.data.electronicBookList);
           } else {
+            let list = this.data.electronicBookList;
+            list.forEach((obj, index) => {
+              if (obj.id == item.id) {
+                list.splice(index, 1);
+              }
+            })
             item.electronChecked = false
             wx.showToast({
-              title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�",
+              title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�",
               icon: "none",
               duration: 1000,
             })
+            this.setData({
+              electronicBookList: list,
+              num: list.length + this.data.paperBookList.length
+            })
+            wx.setStorageSync("electronicBookList", list);
           }
         } else {
           wx.showToast({
@@ -907,9 +939,10 @@
             duration: 1000,
           })
           this.setData({
-            electronicBookList: [...this.data.electronicBookList, ...[item]]
+            electronicBookList: [itemAttr],
+            num: 1 + this.data.paperBookList.length
           })
-          wx.setStorageSync("electronicBookList", JSON.stringify(this.data.electronicBookList));
+          wx.setStorageSync("electronicBookList", [itemAttr]);
         }
       } else {
         item.electronChecked = false
@@ -945,17 +978,28 @@
               duration: 1000,
             })
             this.setData({
-              paperBookList: [...this.data.paperBookList, ...[item]]
+              paperBookList: [...this.data.paperBookList, ...[itemAttr]],
+              num: this.data.paperBookList.lenght + this.data.electronicBookList.length
             })
-            wx.setStorageSync("paperBookList", JSON.stringify(this.data.paperBookList));
-            console.log(this.data.paperBookList, "3")
+            wx.setStorageSync("paperBookList", this.data.paperBookList);
           } else {
+            let list = this.data.paperBookList;
+            list.forEach((obj, index) => {
+              if (obj.id == item.id) {
+                list.splice(index, 1);
+              }
+            })
             item.paperChecked = false
             wx.showToast({
-              title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�",
-              icon: 'none',
+              title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�",
+              icon: "none",
               duration: 1000,
             })
+            this.setData({
+              paperChecked: list,
+              num: list.length + this.data.electronicBookList.length
+            })
+            wx.setStorageSync("paperBookList", list);
           }
         } else {
           item.paperChecked = true;
@@ -965,10 +1009,10 @@
             duration: 1000,
           })
           this.setData({
-            paperBookList: [item]
+            paperBookList: [itemAttr],
+            num: 1 + this.data.electronicBookList.length
           })
-          wx.setStorageSync("paperBookList", JSON.stringify(this.data.paperBookList));
-          console.log(this.data.paperBookList, "4")
+          wx.setStorageSync("paperBookList", [itemAttr]);
         }
       } else {
         item.paperChecked = false

--
Gitblit v1.9.1