From 04c7b0163caeae4ab1c5da62e301fa993101cfad Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 31 三月 2025 10:40:45 +0800
Subject: [PATCH] bug修改

---
 packageDomain/pages/sampleBookList/index.js |  943 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 439 insertions(+), 504 deletions(-)

diff --git a/packageDomain/pages/sampleBookList/index.js b/packageDomain/pages/sampleBookList/index.js
index ab27b30..2db2783 100644
--- a/packageDomain/pages/sampleBookList/index.js
+++ b/packageDomain/pages/sampleBookList/index.js
@@ -1,3 +1,6 @@
+import {
+  loginInfo
+} from '../../../assets/js/login';
 const app = getApp();
 Page({
 
@@ -11,7 +14,6 @@
     userInfo: null,
     path: '*',
     pathList: [],
-
     bookList: [],
     //楂樼骇鍒嗙被
     iconList: {
@@ -21,20 +23,13 @@
     //涓�绾у垎绫�
     stairList: {
       value: '',
-      options: [],
+      options: [{
+        value: "",
+        label: "涓�绾у垎绫�",
+      }],
     },
     //浜岀骇鍒嗙被
     secondList: {
-      value: [],
-      options: [],
-    },
-    //閲嶇偣椤圭洰
-    majorProjectList: {
-      value: [],
-      options: [],
-    },
-    //鏂板舰鎬佹暀鏉�
-    newTextBook: {
       value: [],
       options: [],
     },
@@ -43,10 +38,33 @@
       name: '',
       code: '',
     },
-
     stairCode: '', // 涓�绾у垎绫婚�変腑椤�
     secondCode: '', // 浜岀骇鍒嗙被閫変腑椤�
     sort: '', // 鎺掑簭
+    sortList: {
+      value: "default",
+      options: [{
+          value: "default",
+          label: "榛樿鎺掑簭",
+        },
+        {
+          value: "name-asc",
+          label: "鍚嶇О姝e簭",
+        },
+        {
+          value: "name-desc",
+          label: "鍚嶇О鍊掑彊",
+        },
+        {
+          value: "time-asc",
+          label: "鍑虹増鏃堕棿姝e簭",
+        },
+        {
+          value: "time-desc",
+          label: "鍑虹増鏃堕棿鍊掑彊",
+        },
+      ],
+    },
     //鍒嗛〉
     page: 1,
     limit: 10,
@@ -64,28 +82,32 @@
     paperBookCount: 0, //绾歌川涔﹀墿浣欐鏁�
     ebookCount: 0, //鐢靛瓙涔﹀墿浣欐鏁�
     num: 0,
+    x: 280,
+    y: 300,
+    scrollTop: 0
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
+    let that = this;
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
-    this.setData({
+    that.setData({
       barHeight: systInfo.statusBarHeight,
       navBarHeight: navBarHeight,
     });
     // 鎼滅储璧嬪��
     if (options && options.searchValue) {
-      this.setData({
+      that.setData({
         searchValue: options.searchValue,
       });
     }
     // 楂樼骇鍒嗙被璧嬪��
     if (options && options.assortCode) {
-      this.setData({
+      that.setData({
         assortCheck: {
           name: options.assorName,
           code: options.assortCode,
@@ -93,13 +115,13 @@
         },
       });
     }
-    if (this.data.assortCheck.code) {
+    if (that.data.assortCheck.code) {
       // 鑾峰彇涓�绾у垎绫�
-      this.getStairList(this.data.assortCheck.code);
+      ththatis.getStairList(that.data.assortCheck.code);
     }
     // 涓�绾у垎绫诲拰path璧嬪��
     if (options && options.assortCode && options.stairCode) {
-      this.setData({
+      that.setData({
         'stairList.value': options.stairCode,
         stairCode: options.stairCode,
         path: `${options.assortCode}\\${options.stairCode}`,
@@ -107,45 +129,30 @@
     }
     // 浜岀骇鍒嗙被璧嬪��
     if (options && options.secondCode) {
-      this.setData({
+      that.setData({
         secondCode: options.secondCode,
         pathList: [{
           Path: options.secondCode,
           Type: '*',
           StoreRefCode: app.config.goodsStore,
-        }
-        ],
+        }],
       })
     }
-    this.getIconTypeList();
+    that.getIconTypeList();
 
-    // 鑾峰彇閲嶇偣椤圭洰
-    this.getProjectList('bookClassification');
-    //鏂板舰鎬佹暀鏉�
-    this.getProjectList('newFormsTextbooks');
-    if (wx.getStorageSync(app.config.tokenKey)) {
-      this.getAlreadyPBookList()
-      this.getAlreadyEBookList()
-    }
-    if (wx.getStorageSync(app.config.userInfoKey)) {
-      this.setData({
+    // 妫�鏌ョ櫥褰曠姸鎬�
+    const token = wx.getStorageSync(app.config.tokenKey)
+    if (token) {
+      that.setData({
         userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
       })
-    }
-    if (wx.getStorageSync("paperBookList")) {
+      const paperBookList = wx.getStorageSync('paperBookList') ? JSON.parse(wx.getStorageSync('paperBookList')).length : 0
+      const electronicBookList = wx.getStorageSync('electronicBookList') ? JSON.parse(wx.getStorageSync('electronicBookList')).length : 0
       this.setData({
-        paperBookList: wx.getStorageSync("paperBookList"),
+        num: paperBookList + electronicBookList
       })
     }
-    if (wx.getStorageSync("electronicBookList")) {
-      this.setData({
-        electronicBookList: wx.getStorageSync("electronicBookList"),
-      })
-    }
-    this.setData({
-      num: this.data.paperBookList.length + this.data.electronicBookList.length
-    })
-    this.getBookList(false);
+    that.getBookList(false)
   },
 
   /**
@@ -159,31 +166,108 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
    */
   onShow() {
+    let that = this;
+    const token = wx.getStorageSync(app.config.tokenKey)
+    if (!token) {
+      loginInfo(app, (data) => {
+        if (data) {
+          that.setData({
+            userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
+          })
+          that.getAlreadyPBookList()
+          that.getAlreadyEBookList()
+          that.getSelectPaperBookCount()
+          that.getSelectBookCount()
+        } else {
+          wx.switchTab({
+            url: '/pages/home/home',
+          })
+        }
+      })
+    }
+    if (wx.getStorageSync("paperBookList") || wx.getStorageSync("electronicBookList")) {
+      if (wx.getStorageSync("paperBookList")) {
+        that.setData({
+          paperBookList: JSON.parse(wx.getStorageSync("paperBookList")),
+        })
+      }
+      if (wx.getStorageSync("electronicBookList")) {
+        that.setData({
+          electronicBookList: JSON.parse(wx.getStorageSync("electronicBookList")),
+        })
+      }
+      that.setData({
+        num: Number(that.data.paperBookList.length) + Number(that.data.electronicBookList.length)
+      })
+    }
+    // that.getBookList(false);
+    that.dataRebuild(that.data.bookList)
+  },
+  onHide() {
+    const query = wx.createSelectorQuery()
+    query.select('#scrollView').scrollOffset(res => {
+      console.log(1, res);
+      this.setData({
+        scrollTop: res.scrollTop
+      })
+      console.log('闅愯棌', this.data.scrollTop);
+    }).exec()
 
   },
   goBack() {
     wx.navigateBack();
   },
+
+  // 鑾峰彇绾歌川涔﹀墿浣欐鏁�
+  getSelectPaperBookCount() {
+    app.MG.app
+      .getTicketResult({
+        ticketRefCodeOrGuid: 'paperSampleBookapplyNum',
+        roleId: this.data.userInfo.roleId
+      })
+      .then((res) => {
+        this.setData({
+          paperBookCount: res.totalCount - res.usedCount
+        })
+      })
+  },
+  // 鑾峰彇鐢靛瓙涔﹀墿浣欐鏁�
+  getSelectBookCount() {
+    app.MG.app
+      .getTicketResult({
+        ticketRefCodeOrGuid: 'electronicSampleBookapplyNum',
+        roleId: this.data.userInfo.roleId
+      })
+      .then((res) => {
+        this.setData({
+          ebookCount: res.totalCount - res.usedCount
+        })
+      })
+  },
   //鑾峰彇楂樼骇鍒嗙被
   getIconTypeList() {
     let query = {
       path: '*',
-      filterList: [
-        {
-          value: 'Normal',
-          field: 'state'
-        }
-      ],
+      filterList: [{
+        value: 'Normal',
+        field: 'state'
+      }],
       queryType: '\\',
       searchList: [],
       size: '5',
       start: '0',
       storeRefCode: app.config.goodsStore,
-      sort: { type: 'Asc', field: 'LinkOrder' }
+      sort: {
+        type: 'Asc',
+        field: 'LinkOrder'
+      }
     }
     app.MG.store.getStoreChannelList(query).then((res) => {
-      let list = [];
-      if (res.datas.length > 0) (
+      let list = [{
+        value: "",
+        label: "鎬诲垎绫�",
+      }];
+      if (res.datas.length > 0)(
         res.datas.forEach((item) => {
           item.value = item.refCode;
           item.label = item.name;
@@ -198,7 +282,7 @@
       )
       this.setData({
         'iconList.options': list,
-        'iconList.value': this.data.assortCode,
+        'iconList.value': this.data.assortCheck.code,
       });
     })
   },
@@ -212,10 +296,16 @@
       size: '30',
       start: '0',
       storeRefCode: app.config.goodsStore,
-      sort: { type: 'Asc', field: 'LinkOrder' },
+      sort: {
+        type: 'Asc',
+        field: 'LinkOrder'
+      },
     };
     app.MG.store.getStoreChannelList(query).then(async (res) => {
-      let options = [];
+      let options = [{
+        value: "",
+        label: "涓�绾у垎绫�",
+      }];
       if (res.datas.length > 0) {
         for (let index = 0; index < res.datas.length; index++) {
           let item = res.datas[index];
@@ -242,7 +332,10 @@
       size: '30',
       start: '0',
       storeRefCode: app.config.goodsStore,
-      sort: { type: 'Asc', field: 'LinkOrder' },
+      sort: {
+        type: 'Asc',
+        field: 'LinkOrder'
+      },
     };
     app.MG.store.getStoreChannelList(query).then((res) => {
       if (res.datas.length > 0) {
@@ -263,50 +356,7 @@
       })
     });
   },
-  // 鑾峰彇閲嶇偣椤圭洰
-  getProjectList(type) {
-    const options = [];
-    const arr = [];
-    let array = [];
-    const query = {
-      refCodes: [type],
-    };
-    app.MG.store.getProductTypeField(query).then((res) => {
-      array = JSON.parse(res[0].config).option;
-      for (let index = 0; index < array.length; index++) {
-        const element = array[index];
-        if (element.child) {
-          for (let index = 0; index < element.child.length; index++) {
-            const item = element.child[index];
-            arr.push(item);
-          }
-        }
-      }
-      if (type == 'bookClassification') {
-        for (let index = 0; index < arr.length; index++) {
-          const element = arr[index];
-          options.push({
-            value: element.value,
-            label: element.name,
-          });
-        }
-        this.setData({
-          'majorProjectList.options': options,
-        });
-      } else if (type == 'newFormsTextbooks') {
-        for (let index = 0; index < arr.length; index++) {
-          const element = arr[index];
-          options.push({
-            value: element.value,
-            label: element.name,
-          });
-        }
-        this.setData({
-          'newTextBook.options': options,
-        });
-      }
-    });
-  },
+
   // 鑾峰彇鍥句功鍒楄〃
   getBookList(isReachBottom) {
     let that = this;
@@ -322,17 +372,43 @@
         queryType: '*',
       };
     }
-    if (that.data.sort) {
+    if (this.data.sortList.value == "name-asc") {
       sort = {
-        Name: that.data.sort,
-        BaseType: '',
+        Name: "Asc",
+        BaseType: "",
       };
-    } else {
+    } else if (this.data.sortList.value == "name-desc") {
       sort = {
-        type: 'Desc',
-        field: 'ViewCount',
+        Name: "Desc",
+        BaseType: "",
+      };
+    } else if (this.data.sortList.value == "time-asc") {
+      sort = {
+        PublicationDate: "Asc",
+        BaseType: "DateTime",
+      };
+    } else if (this.data.sortList.value == "time-desc") {
+      sort = {
+        PublicationDate: "Desc",
+        BaseType: "DateTime",
+      };
+    } else if (this.data.sortList.value == "default") {
+      sort = {
+        field: "order",
+        type: "Desc",
       };
     }
+    // if (that.data.sort) {
+    //   sort = {
+    //     Name: that.data.sort,
+    //     BaseType: '',
+    //   };
+    // } else {
+    //   sort = {
+    //     type: 'Desc',
+    //     field: 'ViewCount',
+    //   };
+    // }
     // 鎼滅储
     let searchObj = {};
     if (that.data.searchValue) {
@@ -345,12 +421,10 @@
     }
     const query = {
       ...pathObj,
-      filterList: [
-        {
-          value: 'Normal',
-          field: 'state',
-        },
-      ],
+      filterList: [{
+        value: 'Normal',
+        field: 'state',
+      }, ],
       sort,
       paging: {
         start: that.data.page * that.data.limit - that.data.limit,
@@ -360,6 +434,8 @@
         author: [],
         isbn: [],
         publicationDate: [],
+        pdf: [],
+        protectedEpub: [],
         isApplyBook: [],
         'isApplyBook>': ['1'],
         ...searchObj,
@@ -368,55 +444,7 @@
     app.MG.store.getProductList(query).then((res) => {
       try {
         if (res.datas.length > 0) {
-          res.datas.forEach((item) => {
-            item.paperDisabled = false
-            item.paperChecked = false
-            item.electronDisabled = false
-            item.electronChecked = false
-            if (item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1) {
-              item.electronDisabled = true
-              item.electronChecked = true
-            }
-            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 (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 (that.data.paperBookList.length > 0) {
-              for (let i = 0; i < that.data.paperBookList.length; i++) {
-                if (that.data.paperBookList[i].id == item.id) {
-                  item.paperChecked = true
-                }
-              }
-            }
-            if (that.data.electronicBookList.length > 0) {
-              for (let i = 0; i < that.data.electronicBookList.length; i++) {
-                if (that.data.electronicBookList[i].id == item.id) {
-                  item.electronChecked = true
-                }
-              }
-            }
-          });
-          let list = res.datas;
+          let list = this.dataRebuild(res.datas);
           //瑙﹀簳鍔犺浇鏂版暟鎹苟淇濈暀鑰佹暟鎹�
           if (isReachBottom) {
             list = [...this.data.bookList, ...list] //灏嗘柊鏁版嵁鍔犲叆鑰佹暟鎹腑
@@ -427,12 +455,10 @@
             bottomLoading: false,
             isMoreData: list.length > 0 ? false : true,
             skeletonLoding: false,
-            loading: false
           })
         } else {
           that.setData({
             skeletonLoding: false,
-            loading: false
           })
         }
       } catch (error) {
@@ -440,16 +466,76 @@
       }
     });
   },
+  dataRebuild(list) {
+    let that = this;
+    console.log(list, 123)
+    list.forEach((item) => {
+      item.paperDisabled = false
+      item.paperChecked = false
+      item.electronDisabled = false
+      item.electronChecked = false
+      if (item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1) {
+        item.electronDisabled = true
+        item.electronChecked = true
+      }
+      if (that.data.alreadyPaperBookList.length > 0) {
+        that.data.alreadyPaperBookList.forEach((pBook) => {
+          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) => {
+          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) {
+        for (let i = 0; i < that.data.paperBookList.length; i++) {
+          if (that.data.paperBookList[i].id == item.id) {
+            item.paperChecked = true
+          }
+        }
+      }
+      if (that.data.electronicBookList.length > 0) {
+        for (let i = 0; i < that.data.electronicBookList.length; i++) {
+          if (that.data.electronicBookList[i].id == item.id) {
+            item.electronChecked = true
+          }
+        }
+      }
+    });
+    return list
+  },
+
+
   //楂樼骇鍒嗙被閫夋嫨
   onChangeIcon(e) {
     this.setData({
-      assortCheck: {
-        code: e.detail.value,
-      },
+      skeletonLoding: true,
+      bookList: [],
+      'assortCheck.code': e.detail.value,
       stairCode: '',
       secondCode: '',
       path: `${e.detail.value}`,
       'iconList.value': e.detail.value,
+
     });
     this.getBookList(false);
     this.getStairList(this.data.assortCheck.code);
@@ -457,21 +543,24 @@
   },
   // 涓�绾у垎绫诲垏鎹�
   onChangeStair(e) {
-    const path = e.detail.value.length
-      ? `${this.data.assortCheck.code}\\${e.detail.value}`
-      : this.data.assortCheck.code;
+    const path = e.detail.value.length ?
+      `${this.data.assortCheck.code}\\${e.detail.value}` :
+      this.data.assortCheck.code;
     this.setData({
+      skeletonLoding: true,
+      bookList: [],
       pathList: [],
       stairCode: e.detail.value,
       secondCode: '',
       path: path,
       'stairList.value': e.detail.value,
+      'secondList.value': ""
     });
     this.getBookList(false);
     this.getSecondList(path);
   },
-  // 浜岀骇鍒嗙被鍒囨崲
-  onChangeSecond(e) {
+  // 浜岀骇鍒嗙被鍒囨崲 
+  onConfirmSecond(e) {
     const pathList = [];
     for (let index = 0; index < e.detail.value.length; index++) {
       const element = e.detail.value[index];
@@ -482,69 +571,40 @@
       });
     }
     this.setData({
+      skeletonLoding: true,
       pathList: pathList,
       'secondList.value': e.detail.value,
     });
+    this.getBookList(false);
+  },
+  onResetSecond() {
+    this.setData({
+      skeletonLoding: true,
+      pathList: [],
+      'secondList.value': [],
+    });
+    this.getBookList(false);
+  },
 
-  },
-  // 
-  onConfirmSecond() {
-    this.getBookList(false);
-  },
-  // 閲嶇偣椤圭洰鏀瑰彉
-  changeMajorProject(e) {
+  // 鎺掑簭鍒囨崲
+  onSortChange(e) {
     this.setData({
-      'majorProjectList.value': e.detail.value,
+      backTop: "#assort-title",
+      "sortList.value": e.detail.value,
     });
-    this.getBookList(false);
-  },
-  // 閲嶇偣椤圭洰閲嶇疆
-  resetMajorProject() {
-    this.setData({
-      'majorProjectList.value': [],
-    });
-    this.getBookList(false);
-  },
-  changeNewText(e) {
-    this.setData({
-      'newTextBook.value': e.detail.value,
-    });
-    this.getBookList(false);
-  },
-  resetNewText() {
-    this.setData({
-      'newTextBook.value': [],
-    });
-    this.getBookList(false);
-  },
-  // 鎺掑簭鎸夐挳
-  sortClick() {
-    if (!this.data.sort.length) {
-      this.setData({
-        sort: 'Desc',
-      });
-    } else if (this.data.sort == 'Desc') {
-      this.setData({
-        sort: 'Asc',
-      });
-    } else if (this.data.sort == 'Asc') {
-      this.setData({
-        sort: '',
-      });
-    }
+
     let path;
     if (this.data.secondCode) {
       path = this.data.secondCode;
     } else if (this.data.stairCode) {
-      path = `${this.data.assortCheck.code
-        }\\${this.data.stairCode}`;
+      path = `${this.data.assortCheck.code}\\${this.data.stairCode}`;
     } else {
       path = this.data.assortCheck.code;
     }
     this.setData({
       path: path,
     });
-    this.getBookList(false);
+    this.getBookList(path);
   },
   // 鎼滅储鍥句功
   searchBook(e) {
@@ -555,7 +615,9 @@
   },
   // 璺宠浆鍥句功璇︽儏
   goDetail(e) {
-    const { book } = e.currentTarget.dataset;
+    const {
+      book
+    } = e.currentTarget.dataset;
     wx.navigateTo({
       url: `/packageBookService/pages/bookServices/detail/index?id=${book.id}&name=${book.name}`,
     });
@@ -621,7 +683,6 @@
         this.setData({
           alreadyElectronicBookList: list,
         });
-        this.getBookList(false);
       }
     })
   },
@@ -677,17 +738,34 @@
   //绾歌川鏍蜂功
   onChangePaper(e) {
     const item = e.currentTarget.dataset.book;
+    const index = this.data.bookList.findIndex(citem => citem.id == item.id)
     let role = this.data.userInfo != null ? this.data.userInfo.role : null
-    if (role) {
-      if (item.paperDisabled) {
-        wx.showToast({
-          title: "璇ユ牱涔﹀凡鐢宠",
-          icon: 'none',
-          duration: 1000,
+    if (role && role == 'Teacher') {
+      // 鏄暀甯�
+      if (e.detail.checked) {
+        // 鐐瑰嚮閫変腑
+        if (this.data.paperBookCount == 0) {
+          wx.showToast({
+            title: "鎮ㄧ殑绾歌川鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",
+            icon: "none",
+            duration: 1000,
+          })
+          return false;
+        }
+        if (this.data.paperBookList.length >= 2) {
+          wx.showToast({
+            title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�",
+            icon: "none",
+            duration: 1000,
+          })
+          return false;
+        }
+        this.addBookFun(item, "pBook")
+        this.setData({
+          ["bookList[" + index + "].paperChecked"]: e.detail.checked
         })
-        return
-      }
-      if (item.paperChecked) {
+      } else {
+        // 鍙栨秷閫変腑
         let pList = this.data.paperBookList;
         if (pList.length > 0) {
           pList.forEach((obj, index) => {
@@ -696,107 +774,43 @@
             }
           })
         }
-        item.paperChecked = false;
-        if (this.data.bookList.length > 0) {
-          this.data.bookList.forEach(i => {
-            if (i.id == item.id) {
-              i.paperChecked = false;
-            }
-          })
-        }
+        this.setData({
+          paperBookList: pList,
+          num: this.data.num - 1,
+          ["bookList[" + index + "].paperChecked"]: e.detail.checked
+        })
+        wx.setStorageSync("paperBookList", JSON.stringify(pList));
         wx.showToast({
           title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�",
           icon: 'none',
           duration: 1000,
-        })
-        this.setData({
-          paperBookList: pList,
-          num: pList.length + this.data.electronicBookList.length
-        })
-        wx.setStorageSync("paperBookList", JSON.stringify(pList));
-        return
-      }
-      if (role == 'Teacher') {
-        this.getSelectPaperBookCount(item)
-      } else {
-        item.paperChecked = false
-        wx.showModal({
-          title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', //鎻愮ず鐨勬爣棰�
-          content: '璇峰厛杩涜鏁欏笀璁よ瘉锛�', //鎻愮ず鐨勫唴瀹�
-          success: function (res) {
-            if (res.confirm) {
-              wx.navigateTo({
-                url: "/packageDomain/pages/teacherCertification/index",
-              });
-            } else if (res.cancel) {
-              item.paperChecked = false
-            }
-          }
         })
       }
     } else {
-      item.paperChecked = false
+      wx.showModal({
+        title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', //鎻愮ず鐨勬爣棰�
+        content: '璇峰厛杩涜鏁欏笀璁よ瘉锛�', //鎻愮ず鐨勫唴瀹�
+        success: function (res) {
+          if (res.confirm) {
+            wx.navigateTo({
+              url: "/packageDomain/pages/teacherCertification/index",
+            });
+          }
+        }
+      })
     }
   },
-  getSelectPaperBookCount(item) {
-    app.MG.app
-      .getTicketResult({
-        ticketRefCodeOrGuid: 'paperSampleBookapplyNum',
-        roleId: this.data.userInfo.roleId
-      })
-      .then((res) => {
-        this.setData({
-          paperBookCount: res.totalCount - res.usedCount
-        })
-        if (!item.paperDisabled) {
-          this.getAlreadyBookList(item, 'pBook')
-        }
-      })
-  },
+
   //閫夋嫨鐢靛瓙鏍蜂功
-  onChangeElectron(e) {
+  async onChangeElectron(e) {
     const item = e.currentTarget.dataset.book;
-    let role = this.data.userInfo != null ? this.data.userInfo.role : null;
-    if (role) {
-      if (item.electronDisabled) {
-        wx.showToast({
-          title: "璇ユ牱涔﹀凡鐢宠",
-          icon: 'none',
-          duration: 1000,
-        })
-        return
-      }
-      if (item.electronChecked) {
-        let eList = this.data.electronicBookList;
-        if (eList.length > 0) {
-          eList.forEach((obj, index) => {
-            if (obj.id == item.id) {
-              eList.splice(index, 1);
-            }
-          })
-        }
-        if (this.data.bookList.length > 0) {
-          this.data.bookList.forEach(i => {
-            if (i.id == item.id) {
-              i.electronChecked = false;
-            }
-          })
-        }
-        item.electronChecked = false;
-        wx.showToast({
-          title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�",
-          icon: 'none',
-          duration: 1000,
-        })
-        this.setData({
-          electronicBookList: eList,
-          num: eList.length + this.data.paperBookList.length
-        })
-        wx.setStorageSync("electronicBookList", eList);
-        return
-      }
-      if (role == 'Teacher') {
-        //鏈夋棤瀛愬晢鍝侊紝瀛愬晢鍝佹湁鏃犵數瀛愪功鏂囦欢
+    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',
@@ -806,7 +820,7 @@
           },
           paging: {
             start: 0,
-            size: 6
+            size: 1
           },
           mainProductId: item.id,
           fields: {
@@ -814,60 +828,88 @@
             bookshelf_protectedEpub: [],
           }
         }
-        app.MG.store.getProductList(obj).then((res) => {
-          if (res.datas.length > 0) {
-            if (res.datas[0].bookshelf_pdf || res.datas[0].bookshelf_protectedEpub) {
-              this.getSelectBookCount(item)
-            } else {
-              wx.showToast({
-                title: "鏆傛棤鐢靛瓙涔︽枃浠�,璇疯仈绯荤鐞嗗憳!",
-                icon: 'none',
-                duration: 1000,
-              })
-            }
-          } else {
-            this.getSelectBookCount(item)
+        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: "鎮ㄧ殑鐢靛瓙鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",
+            icon: "none",
+            duration: 1000,
+          })
+          return false;
+        }
+        if (this.data.electronicBookList.length >= 2) {
+          wx.showToast({
+            title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�",
+            icon: "none",
+            duration: 1000,
+          })
+          return false;
+        }
+        this.addBookFun(item, "eBook")
+        this.setData({
+          ["bookList[" + index + "].electronChecked"]: e.detail.checked
         })
       } else {
-        item.electronChecked = false
-        wx.showModal({
-          title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', //鎻愮ず鐨勬爣棰�
-          content: '璇峰厛杩涜鏁欏笀璁よ瘉锛�', //鎻愮ず鐨勫唴瀹�
-          success: function (res) {
-            if (res.confirm) {
-              wx.navigateTo({
-                url: "/packageDomain/pages/teacherCertification/index",
-              });
-            } else if (res.cancel) {
-              item.electronChecked = false
+        // 鍙栨秷閫変腑
+        let eList = this.data.electronicBookList;
+        if (eList.length > 0) {
+          eList.forEach((obj, index) => {
+            if (obj.id == item.id) {
+              eList.splice(index, 1);
             }
-          }
+          })
+        }
+        this.setData({
+          electronicBookList: eList,
+          num: this.data.num - 1,
+          ["bookList[" + index + "].electronChecked"]: e.detail.checked
+        })
+        wx.setStorageSync("electronicBookList", JSON.stringify(eList));
+        wx.showToast({
+          title: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�",
+          icon: 'none',
+          duration: 1000,
         })
       }
     } else {
-      item.electronChecked = false
-    }
-  },
-  getSelectBookCount(item) {
-    app.MG.app
-      .getTicketResult({
-        ticketRefCodeOrGuid: 'electronicSampleBookapplyNum',
-        roleId: this.data.userInfo.roleId
-      })
-      .then((res) => {
-        this.setData({
-          ebookCount: res.totalCount - res.usedCount
-        })
-        if (!item.electronDisabled) {
-          this.getAlreadyBookList(item, 'eBook')
+      wx.showModal({
+        title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', //鎻愮ず鐨勬爣棰�
+        content: '璇峰厛杩涜鏁欏笀璁よ瘉锛�', //鎻愮ず鐨勫唴瀹�
+        success: function (res) {
+          if (res.confirm) {
+            wx.navigateTo({
+              url: "/packageDomain/pages/teacherCertification/index",
+            });
+          }
         }
       })
+    }
   },
 
-  getAlreadyBookList(item, type) {
+  //  娣诲姞鏍蜂功
+  addBookFun(item, type) {
     let itemAttr = null
-    let isHas = false
+    const eList = this.data.electronicBookList;
+    const pList = this.data.paperBookList;
     itemAttr = {
       id: item.id,
       title: item.name || '-',
@@ -880,146 +922,27 @@
       isbn: item.isbn || '-',
       publicationDate: item.publicationDate
     }
-
     if (type == 'eBook') {
-      if (this.data.ebookCount > 0) {
-        const eBookData = this.data.electronicBookList
-        if (eBookData.length == 2) {
-          item.electronChecked = false
-          wx.showToast({
-            title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�",
-            icon: 'none',
-            duration: 1000,
-          })
-          return false
-        }
-        if (eBookData.length > 0) {
-          for (let i = 0; i < eBookData.length; i++) {
-            if (eBookData[i].id == item.id) {
-              isHas = true
-            }
-          }
-          if (!isHas) {
-            wx.showToast({
-              title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
-              icon: "none",
-              duration: 1000,
-            })
-            this.setData({
-              electronicBookList: [...this.data.electronicBookList, ...[itemAttr]],
-              num: this.data.electronicBookList.length + this.data.paperBookList.length
-            })
-            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: "宸蹭粠鏍蜂功鐢宠鍗曠Щ闄�",
-              icon: "none",
-              duration: 1000,
-            })
-            this.setData({
-              electronicBookList: list,
-              num: list.length + this.data.paperBookList.length
-            })
-            wx.setStorageSync("electronicBookList", list);
-          }
-        } else {
-          wx.showToast({
-            title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
-            icon: "none",
-            duration: 1000,
-          })
-          this.setData({
-            electronicBookList: [itemAttr],
-            num: 1 + this.data.paperBookList.length
-          })
-          wx.setStorageSync("electronicBookList", [itemAttr]);
-        }
-      } else {
-        item.electronChecked = false
-        wx.showToast({
-          title: "鎮ㄧ殑鐢靛瓙鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",
-          icon: "none",
-          duration: 1000,
-        })
-      }
+      eList.push(itemAttr)
+      this.setData({
+        electronicBookList: eList,
+      })
+      wx.setStorageSync("electronicBookList", JSON.stringify(eList));
     } else {
-      if (this.data.paperBookCount > 0) {
-        const pBookData = this.data.paperBookList
-        if (pBookData.length == 2) {
-          item.paperChecked = false
-          wx.showToast({
-            title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�",
-            icon: 'none',
-            duration: 1000,
-          })
-          return false
-        }
-        if (pBookData.length > 0) {
-          for (let i = 0; i < pBookData.length; i++) {
-            if (pBookData[i].id == item.id) {
-              isHas = true
-            }
-          }
-          if (!isHas) {
-            item.paperChecked = true
-            wx.showToast({
-              title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
-              icon: 'none',
-              duration: 1000,
-            })
-            this.setData({
-              paperBookList: [...this.data.paperBookList, ...[itemAttr]],
-              num: this.data.paperBookList.lenght + this.data.electronicBookList.length
-            })
-            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",
-              duration: 1000,
-            })
-            this.setData({
-              paperChecked: list,
-              num: list.length + this.data.electronicBookList.length
-            })
-            wx.setStorageSync("paperBookList", list);
-          }
-        } else {
-          item.paperChecked = true;
-          wx.showToast({
-            title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
-            icon: 'none',
-            duration: 1000,
-          })
-          this.setData({
-            paperBookList: [itemAttr],
-            num: 1 + this.data.electronicBookList.length
-          })
-          wx.setStorageSync("paperBookList", [itemAttr]);
-        }
-      } else {
-        item.paperChecked = false
-        wx.showToast({
-          title: "鎮ㄧ殑绾歌川鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",
-          icon: 'none',
-          duration: 1000,
-        })
-      }
+      pList.push(itemAttr)
+      this.setData({
+        paperBookList: pList,
+      })
+      wx.setStorageSync("paperBookList", JSON.stringify(pList));
     }
+    this.setData({
+      num: this.data.num + 1
+    })
+    wx.showToast({
+      title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
+      icon: "none",
+      duration: 1000,
+    })
   },
   //鍘绘牱涔︾敵璇峰崟
   goApply() {
@@ -1027,10 +950,22 @@
       url: "/packageDomain/pages/sampleBookList/applicationForm/index",
     });
   },
+
+  // 鐩戝惉婊氬姩璺濈
+  onPageScroll(e) {
+    if (e && e.scrollTop >= 1000) {
+      this.setData({
+        isBackTop: true
+      })
+    } else {
+      this.setData({
+        isBackTop: false
+      })
+    }
+  },
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
-  onShareAppMessage() {
-
-  }
+  onShareAppMessage() {},
+  onShareTimeline() {},
 })
\ No newline at end of file

--
Gitblit v1.9.1