yiming
2024-03-25 ecabd20b3dfbd956dad14ffb6ba3dc2efcfdd7c1
packageBookService/pages/bookServices/detail/index.js
@@ -67,6 +67,16 @@
    paperBookCount: 0, //纸质书剩余次数
    ebookCount: 0, //电子书剩余次数
    userInfo: {},
    fileInfo: {
      bookName: "",
      fileType: "",
      md5: "",
      freePage: ""
    },  //阅读器数据
    buyResourceData: {
      productLinkPath: '',
      refCode: '',
    }
  },
@@ -157,7 +167,7 @@
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.tabValue == 'jesk_note') {
    if (this.data.tabValue == 'jsek_note') {
      const child = this.selectComponent('#note')
      child.onReachBottom()
    }
@@ -352,13 +362,44 @@
          this.setData({
            noFile: true
          });
          if (res.datas[0].bookshelf_pdf) {
            this.setData({
              "fileInfo.bookName": this.data.bookDetail.name,
              "fileInfo.fileType": 'pdf',
              "fileInfo.md5": res.datas[0].bookshelf_pdf,
              "fileInfo.freePage": res.datas[0].bookshelf_probationPage,
            });
          } else if (res.datas[0].bookshelf_protectedEpub) {
            this.setData({
              "fileInfo.bookName": this.data.bookDetail.name,
              "fileInfo.fileType": 'epub',
              "fileInfo.md5": res.datas[0].bookshelf_protectedEpub,
              "fileInfo.freePage": res.datas[0].bookshelf_freeEpub,
            });
          }
        }
      } else {
        if (this.data.bookDetail.pdf || this.data.bookDetail.protectedEpub) {
          this.setData({
            noFile: true
          });
          if (this.data.bookDetail.pdf) {
            this.setData({
              "fileInfo.bookName": this.data.bookDetail.name,
              "fileInfo.fileType": 'pdf',
              "fileInfo.md5": this.data.bookDetail.pdf,
              "fileInfo.freePage": this.data.bookDetail.probationPage,
            });
          } else if (this.data.bookDetail.protectedEpub) {
            this.setData({
              "fileInfo.bookName": this.data.bookDetail.name,
              "fileInfo.fileType": 'epub',
              "fileInfo.md5": this.data.bookDetail.protectedEpub,
              "fileInfo.freePage": this.data.bookDetail.freeEpubPage,
            });
          }
        }
        console.log(this.data.fileInfo, 456)
        this.setData({
          selectedIds: this.data.bookDetail.defaultSaleMethodId,
          bookBuy: this.data.bookDetail.purchasedSaleMethodIdList.indexOf(this.data.bookDetail.defaultSaleMethodId) > -1
@@ -453,6 +494,12 @@
    if (e.detail.label == '教学资源' || e.detail.label == '云学习' || e.detail.label == '云测试') {
      const checkData = this.data.cmsDatas.find(item => item.refCode == e.detail.value)
      if (checkData) {
        if (e.detail.value == 'jsek_cloudLearning') {
          this.setData({
            'buyResourceData.productLinkPath': checkData.productLinkPath,
            'buyResourceData.refCode': checkData.refCode
          })
        }
        if ((e.detail.value == 'jsek_teachingResources' && !this.data.teach.length)
          || (e.detail.value == 'jsek_cloudLearning' && !this.data.learn.length)
          || (e.detail.value == 'questionBank' && !this.data.test.length)) {
@@ -470,6 +517,12 @@
      if (token) {
        child.changeLoading()
        child.getNoteList()
      }
    } else if (e.detail.label == '电子书') {
      const child = this.selectComponent('#eBook')
      if (child) {
        child.getProgress()
      }
    }
@@ -669,54 +722,65 @@
  // 图书添加购物车
  async addBookShopcCar() {
    const token = wx.getStorageSync('jsek-token')
    if (!token) {
      return wx.getUserProfile({
        desc: '用户登录',
        success: (res) => {
          console.log(res);
    if (!this.data.expire) {
      const token = wx.getStorageSync('jsek-token')
      if (!token) {
        return wx.getUserProfile({
          desc: '用户登录',
          success: (res) => {
            console.log(res);
          }
        })
      }
      const shoppingCartGetId = []
      let query = {
        start: 0,
        size: 9999,
        filterList: [],
        searchList: []
      }
      const res = await app.MG.store.getShoppingCartProductList(query)
      res.datas.forEach((item) => {
        shoppingCartGetId.push(item.saleMethod.id)
      })
      console.log(shoppingCartGetId, 'shoppingCartGetId');
      console.log(this.data.selectedIds, '销售方式id');
      const determine = shoppingCartGetId.some((item) => item == this.data.selectedIds)
      console.log(determine);
      if (!determine) {
        let query = {
          requests: [
            {
              saleMethodId: this.data.selectedIds,
              storeEventId: null,
              agentCode: '电子书'
            }
          ]
        }
        const addRes = app.MG.store.addShoppingCart(query)
        this.showSuccessToast()
      } else {
        Toast({
          context: this,
          selector: '#t-toast',
          message: '已添加',
          theme: 'success',
          direction: 'column',
        });
      }
    } else {
      wx.showToast({
        title: "商品不在有效期",
        icon: 'none',
        duration: 1000,
      })
    }
    const shoppingCartGetId = []
    let query = {
      start: 0,
      size: 999,
      filterList: [],
      searchList: []
    }
    const res = await app.MG.store.getShoppingCartProductList(query)
    res.datas.forEach((item) => {
      shoppingCartGetId.push(item.saleMethod.id)
    })
    console.log(shoppingCartGetId, 'shoppingCartGetId');
    console.log(this.data.selectedIds, '销售方式id');
    const determine = shoppingCartGetId.some((item) => item == this.data.selectedIds)
    console.log(determine);
    if (!determine) {
      let query = {
        requests: [
          {
            saleMethodId: this.data.selectedIds,
            storeEventId: null,
            agentCode: '电子书'
          }
        ]
      }
      const addRes = app.MG.store.addShoppingCart(query)
      this.showSuccessToast()
    } else {
      Toast({
        context: this,
        selector: '#t-toast',
        message: '已添加',
        theme: 'success',
        direction: 'column',
      });
    }
  },
@@ -1342,6 +1406,21 @@
    }
  },
  goRead() {
    if (!this.data.noFile) {
      wx.showToast({
        title: '暂无阅读文件',
        icon: 'none',
        duration: 2000
      })
      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
    })
  },
  //样书申请
  //申请电子样书
  appplyElectronicBook() {