From 7adfe5210fad2b4ab1b1be41e2d58eb3dd9b2b1a Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 02 四月 2024 09:38:22 +0800
Subject: [PATCH] 代码合并

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

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index dfc5171..07ab18a 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -173,11 +173,16 @@
       this.getShoppingCartProductGet()
       this.getApplyInfo(options.id)
       this.getMockData()
+      this.getAlreadyPBookList()
+      this.getAlreadyEBookList()
     }
     if (wx.getStorageSync(app.config.userInfoKey)) {
       this.setData({
         userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
       })
+      // 鑾峰彇鐢宠娆℃暟
+      this.getSelectPaperBookCount()
+      this.getSelectBookCount()
     }
 
   },
@@ -413,9 +418,13 @@
           selectedIds: res.datas[0].defaultSaleMethod.id,
           bookBuy: res.datas[0].purchasedSaleMethodIdList.indexOf(res.datas[0].defaultSaleMethodId) > -1
         });
+        console.log(res);
+        console.log(res.datas[0].defaultSaleMethod.endDate, 'res.datas[0].defaultSaleMethod.endDate');
+        console.log(res.datas[0].defaultSaleMethod.beginDate, 'res.datas[0].defaultSaleMethod.beginDate');
         console.log(this.data.bookItemDetail, 'bookItemData.value');
         let times = new Date(res.datas[0].defaultSaleMethod.endDate).getTime()
         let startTime = new Date(res.datas[0].defaultSaleMethod.beginDate).getTime()
+
         if (times < new Date().getTime() || new Date().getTime() < startTime) {
           this.setData({
             expire: true
@@ -518,7 +527,6 @@
         }
       })
     } else {
-      debugger
       if (this.data.bookDetail.isFavourite) {
         app.MG.store
           .delProductLink({
@@ -817,15 +825,7 @@
   // 鍥句功娣诲姞璐墿杞�
   async addBookShopcCar() {
     if (!this.data.expire) {
-      const token = wx.getStorageSync('jsek-token')
-      if (!token) {
-        return wx.getUserProfile({
-          desc: '鐢ㄦ埛鐧诲綍',
-          success: (res) => {
-            console.log(res);
-          }
-        })
-      }
+
 
       const shoppingCartGetId = []
 
@@ -1006,46 +1006,49 @@
     wx.showLoading({
       title: '鍔犺浇涓�',
     })
-    // let role = userStore.userInfo ? userStore.userInfo.role : null
-    // if (role) {
-    //   if (role == 'Teacher') {
-    // 鐢宠鏁欏璧勬簮
-    let query = {
-      topicIdOrRefCode: 'productDownLoad',
-      type: 'applyForDownload',
-      state: 'WaitAudit',
-      cmsTypeRefCode: '',
-      newDataListRequest: [],
-      name: this.data.bookDetail.name, // name涓虹敵璇风殑涔︽湰鍚嶇О
-      content: JSON.stringify([{
-        name: this.data.bookDetail.name,
-        id: this.data.bookDetail.id,
-        // defaultSaleMethodId: bookData.value.defaultSaleMethodId,
-        icon: this.data.bookDetail.icon
-      }])
-    }
-    app.MG.ugc.newTopicMessage(query).then(async (res) => {
-      if (res) {
-        wx.showToast({
-          title: '鐢宠宸叉彁浜わ紝璇峰緟瀹℃牳閫氳繃鍚庝笅杞�',
+    let role = wx.getStorageSync(app.config.userInfoKey).role
+    if (role) {
+      debugger
+      if (role == 'Teacher') {
+        // 鐢宠鏁欏璧勬簮
+        let query = {
+          topicIdOrRefCode: 'productDownLoad',
+          type: 'applyForDownload',
+          state: 'WaitAudit',
+          cmsTypeRefCode: '',
+          newDataListRequest: [],
+          name: this.data.bookDetail.name, // name涓虹敵璇风殑涔︽湰鍚嶇О
+          content: JSON.stringify([{
+            name: this.data.bookDetail.name,
+            id: this.data.bookDetail.id,
+            // defaultSaleMethodId: bookData.value.defaultSaleMethodId,
+            icon: this.data.bookDetail.icon
+          }])
+        }
+        app.MG.ugc.newTopicMessage(query).then(async (res) => {
+          if (res) {
+            wx.showToast({
+              title: '鐢宠宸叉彁浜�',
+              duration: 2000,
+            })
+          }
+          await this.getApplyInfo(this.data.bookDetail.id)
+        })
+      } else {
+        wx.showModal({
+          title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�',
+          content: '璇峰厛杩涜鏁欏笀璁よ瘉锛�',
+          complete: (res) => {
+            if (res.cancel) {}
+            if (res.confirm) {
+              wx.navigateTo({
+                url: '/packageDomain/pages/teacherCertification/index',
+              })
+            }
+          }
         })
       }
-      await this.getApplyInfo(this.data.bookDetail.id)
-    })
-    //   } else {
-    //     ElMessageBox.confirm('璇峰厛杩涜鏁欏笀璁よ瘉锛�', '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', {
-    //       confirmButtonText: '鍘昏璇�',
-    //       cancelButtonText: '鍙栨秷',
-    //       type: 'warning'
-    //     })
-    //       .then(() => {
-    //         isShow.value = true
-    //       })
-    //       .catch(() => { })
-    //   }
-    // } else {
-    //   // logIn()
-    // }
+    }
   },
   // 鏁欏璧勬簮涓嬭浇鍓嶅線PC鎻愮ずDiialog
   closeTeachDownload() {
@@ -1055,10 +1058,27 @@
   },
   // 涓嬭浇鍔熻兘
   downloadTeach(e) {
-    this.setData({
-      isShowTeachDownload: true
-    })
-    console.log('zhuan', this.data.isShowTeachDownload);
+    let role = JSON.parse(wx.getStorageSync(app.config.userInfoKey)).role
+    if (role && role == 'Teacher') {
+      this.setData({
+        isShowTeachDownload: true
+      })
+    } else {
+      wx.showModal({
+        title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�',
+        content: '璇峰厛杩涜鏁欏笀璁よ瘉锛�',
+        complete: (res) => {
+          if (res.cancel) {
+
+          }
+          if (res.confirm) {
+            wx.navigateTo({
+              url: '/packageDomain/pages/teacherCertification/index',
+            })
+          }
+        }
+      })
+    }
     //   const data = e.detail.value
     //   // const data
     //   // let role = userStore.userInfo ? userStore.userInfo.role : null
@@ -1513,29 +1533,154 @@
       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 + '&bookBuy=' + this.data.bookBuy
+      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 + '&bookBuy=' + this.data.bookBuy + '&bookId=' + this.data.bookDetail.id
     })
 
   },
 
   //鏍蜂功鐢宠
+  //鑾峰彇宸茬敵璇风焊璐ㄦ牱涔�
+  getAlreadyPBookList() {
+    const data = {
+      start: 0,
+      size: 9999,
+      topicIdOrRefCode: 'applyEntityBook',
+      appRefCode: app.config.appRefCode,
+      sort: {
+        type: 'Desc',
+        field: 'CreateDate'
+      }
+    }
+    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: list,
+      });
+    })
+  },
+  //鑾峰彇宸茬敵璇风數瀛愭牱涔�
+  getAlreadyEBookList() {
+    const data = {
+      start: 0,
+      size: 9999,
+      topicIdOrRefCode: 'applyBook',
+      appRefCode: app.config.appRefCode,
+      sort: {
+        type: 'Desc',
+        field: 'CreateDate'
+      }
+    }
+    app.MG.ugc.getTopicMessageList(data).then((res) => {
+      let list = []
+      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,
+        });
+      }
+    })
+  },
+
+  //鑾峰彇褰撳墠宸茬敵璇锋鏁帮紙绾歌川锛�
+  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
+        })
+      })
+  },
+
   //鐢宠鐢靛瓙鏍蜂功
   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') {
-          if (this.data.noFile) {
-            this.getSelectBookCount()
-          } else {
+          if (!this.data.noFile) {
             wx.showToast({
               title: "鏆傛棤鐢靛瓙涔︽枃浠�,璇疯仈绯荤鐞嗗憳!",
               icon: 'none',
               duration: 1000,
             })
+            return
           }
+          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;
+          }
+          let isHas = this.data.electronicBookList.find((eitem) => eitem.id == this.data.bookDetail.id)
+          if (isHas) {
+            wx.showToast({
+              title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�",
+              icon: "none",
+              duration: 1000,
+            })
+            return false;
+          }
+          let isApply = this.data.alreadyElectronicBookList.find((eitem) => eitem.id == this.data.bookDetail.id)
+          if (isApply) {
+            wx.showToast({
+              title: "璇ヤ功宸茬敵璇凤紒",
+              icon: "none",
+              duration: 1000,
+            })
+            return false;
+          }
+          this.addBookFun(this.data.bookDetail, "eBook")
         } else {
           wx.showModal({
             title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', //鎻愮ず鐨勬爣棰�
@@ -1564,7 +1709,42 @@
       let role = this.data.userInfo != null ? this.data.userInfo.role : null
       if (role) {
         if (role == 'Teacher') {
-          this.getSelectPaperBookCount()
+          // 鐐瑰嚮閫変腑
+          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;
+          }
+          let isHas = this.data.paperBookList.find((pitem) => pitem.id == this.data.bookDetail.id)
+          if (isHas) {
+            wx.showToast({
+              title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�",
+              icon: "none",
+              duration: 1000,
+            })
+            return false;
+          }
+          let isApply = this.data.alreadyPaperBookList.find((pitem) => pitem.id == this.data.bookDetail.id)
+          if (isApply) {
+            wx.showToast({
+              title: "璇ヤ功宸茬敵璇凤紒",
+              icon: "none",
+              duration: 1000,
+            })
+            return false;
+          }
+          this.addBookFun(this.data.bookDetail, "pBook")
         } else {
           wx.showModal({
             title: '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', //鎻愮ず鐨勬爣棰�
@@ -1587,216 +1767,46 @@
       })
     }
   },
-  //鑾峰彇褰撳墠宸茬敵璇锋鏁帮紙绾歌川锛�
-  getSelectPaperBookCount() {
-    app.MG.app
-      .getTicketResult({
-        ticketRefCodeOrGuid: 'paperSampleBookapplyNum',
-        roleId: this.data.userInfo.roleId
-      })
-      .then((res) => {
-        this.setData({
-          paperBookCount: res.totalCount - res.usedCount
-        })
-        this.getAlreadyBookList(this.data.bookDetail, 'pBook')
-      })
-  },
-  //鑾峰彇褰撳墠宸茬敵璇锋鏁帮紙鐢靛瓙锛�
-  getSelectBookCount() {
-    app.MG.app
-      .getTicketResult({
-        ticketRefCodeOrGuid: 'electronicSampleBookapplyNum',
-        roleId: this.data.userInfo.roleId
-      })
-      .then((res) => {
-        this.setData({
-          ebookCount: res.totalCount - res.usedCount
-        })
-        this.getAlreadyBookList(this.data.bookDetail, 'eBook')
-      })
-  },
-  //鑾峰彇宸茬敵璇风殑鏍蜂功鍒楄〃
-  getAlreadyBookList(item, type) {
-    let topicIdOrRefCode = null
+  //  娣诲姞鏍蜂功
+  addBookFun(item, type) {
+    let itemAttr = null
+    const eList = this.data.electronicBookList;
+    const pList = this.data.paperBookList;
+    itemAttr = {
+      id: item.id,
+      title: item.name || '-',
+      icon: item.icon,
+      checked: false,
+      defaultSaleMethodId: item.defaultSaleMethodId,
+      md5: item.datas.Icon,
+      author: item.author || '-',
+      price: item.price || '-',
+      isbn: item.isbn || '-',
+      publicationDate: item.publicationDate
+    }
     if (type == 'eBook') {
-      topicIdOrRefCode = 'applyBook'
-    } else {
-      topicIdOrRefCode = 'applyEntityBook'
-    }
-    const data = {
-      start: 0,
-      size: 9999,
-      topicIdOrRefCode,
-      appRefCode: app.config.appRefCode,
-      sort: {
-        type: 'Desc',
-        field: 'CreateDate'
-      }
-    }
-    app.MG.ugc.getTopicMessageList(data).then((res) => {
-      let itemAttr = null
-      let isHas = false
-      itemAttr = {
-        id: item.id,
-        title: item.name || '--',
-        icon: item.icon,
-        checked: false,
-        defaultSaleMethodId: item.defaultSaleMethodId,
-        md5: item.datas.Icon,
-        author: item.author || '--',
-        price: item.price || '--',
-        isbn: item.isbn || '--',
-        publicationDate: item.publicationDate
-      }
-      res.datas.map((item) => {
-        if (item.feedBack) {
-          item.feedBack = JSON.parse(item.feedBack)
-          if (item.feedBack.endDate) {
-            const currentDate = new Date()
-            let times = new Date(item.feedBack.endDate + ' 23:59:59').getTime()
-            if (times < currentDate.getTime()) {
-              item.isExpiry = true
-            }
-          }
-        }
-        if (item.content) {
-          item.content = JSON.parse(item.content)
-          item.content.map((e) => (item.productId = e.id))
-        }
+      eList.push(itemAttr)
+      this.setData({
+        electronicBookList: eList,
       })
-      let objVal = null
-      if (type != 'eBook') {
-        objVal = res.datas.find(
-          (i) => i.productId == item.id && i.state != 'Reject' && i.state == 'WaitAudit'
-        )
-      } else {
-        objVal = res.datas.find((i) => i.productId == item.id && i.state != 'Reject')
-      }
-      if (objVal && !objVal.isExpiry && type == 'eBook') {
-        wx.showToast({
-          title: "鎮ㄥ凡鐢宠璇ユ牱涔�",
-          icon: 'none',
-          duration: 1000,
-        })
-      } else if (objVal && type != 'eBook') {
-        wx.showToast({
-          title: "鎮ㄥ凡鐢宠璇ユ牱涔�",
-          icon: 'none',
-          duration: 1000,
-        })
-      } else {
-        if (type == 'eBook') {
-          if (this.data.ebookCount > 0) {
-            const eBookData = this.data.electronicBookList
-            if (eBookData.length == 2) {
-              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 {
-                wx.showToast({
-                  title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�",
-                  icon: "none",
-                  duration: 1000,
-                })
-              }
-            } else {
-              wx.showToast({
-                title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
-                icon: "none",
-                duration: 1000,
-              })
-              this.setData({
-                electronicBookList: [itemAttr],
-                num: 1 + this.data.paperBookList.length
-              })
-              wx.setStorageSync("electronicBookList", [itemAttr]);
-            }
-          } else {
-            wx.showToast({
-              title: "鎮ㄧ殑鐢靛瓙鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",
-              icon: "none",
-              duration: 1000,
-            })
-          }
-        } else {
-          if (this.data.paperBookCount > 0) {
-            const pBookData = this.data.paperBookList
-            if (pBookData.length == 2) {
-              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) {
-                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 {
-                wx.showToast({
-                  title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�",
-                  icon: "none",
-                  duration: 1000,
-                })
-              }
-            } else {
-              wx.showToast({
-                title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
-                icon: 'none',
-                duration: 1000,
-              })
-              this.setData({
-                paperBookList: [itemAttr],
-                num: 1 + this.data.electronicBookList.length
-              })
-              wx.setStorageSync("paperBookList", [itemAttr]);
-            }
-          } else {
-            wx.showToast({
-              title: "鎮ㄧ殑绾歌川鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒",
-              icon: 'none',
-              duration: 1000,
-            })
-          }
-        }
-      }
+      wx.setStorageSync("electronicBookList", eList);
+    } else {
+      pList.push(itemAttr)
+      this.setData({
+        paperBookList: pList,
+      })
+      wx.setStorageSync("paperBookList", pList);
+    }
+    this.setData({
+      num: this.data.num + 1
+    })
+    wx.showToast({
+      title: "娣诲姞鎴愬姛锛屽湪鏍蜂功鐢宠鍗曠瓑鎮ㄥ摝~",
+      icon: "none",
+      duration: 1000,
     })
   },
+
   //鍘绘牱涔︾敵璇峰崟
   goApply() {
     wx.navigateTo({

--
Gitblit v1.9.1