闫增涛
2024-04-02 5c236aa8ee143c1f0f23e738f92c0ebc21270549
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,9 @@
          selectedIds: res.datas[0].defaultSaleMethod.id,
          bookBuy: res.datas[0].purchasedSaleMethodIdList.indexOf(res.datas[0].defaultSaleMethodId) > -1
        });
        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 +523,6 @@
        }
      })
    } else {
      debugger
      if (this.data.bookDetail.isFavourite) {
        app.MG.store
          .delProductLink({
@@ -817,15 +821,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 = []
@@ -1003,49 +999,64 @@
    this.setData({
      applyResourceState: true
    })
    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 = JSON.parse(wx.getStorageSync(app.config.userInfoKey)).role
    if (role) {
      if (role == 'Teacher') {
        wx.showLoading({
          title: '加载中',
        })
        // 申请教学资源
        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()
    // }
    } else {
      wx.showModal({
        title: '尊敬的用户,您好!',
        content: '请先进行教师认证!',
        complete: (res) => {
          if (res.cancel) {}
          if (res.confirm) {
            wx.navigateTo({
              url: '/packageDomain/pages/teacherCertification/index',
            })
          }
        }
      })
    }
  },
  // 教学资源下载前往PC提示Diialog
  closeTeachDownload() {
@@ -1055,10 +1066,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
@@ -1251,6 +1279,7 @@
      let freeIds = arr.filter((item) => {
        return item.saleMethod[0].Price == 0
      })
      debugger
      if (!freeIds.length) return wx.showToast({
        icon: "error",
        title: '暂无免费资源',
@@ -1265,7 +1294,7 @@
          })
        }
      })
      debugger
      let query = {
        remarks: '云学习',
        requests,
@@ -1513,29 +1542,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
      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 +1718,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 +1776,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({