litian
2024-03-20 81b30e7fb0763bce403431f0c1f64d5a9e36dfb2
packageBookService/pages/bookServices/detail/index.js
@@ -1,6 +1,7 @@
// pages/bookServices/detail/index.js
import Message from 'tdesign-miniprogram/message/index.js';
import Toast from 'tdesign-miniprogram/toast';
import tool from '../../../../assets/js/toolClass'
const app = getApp();
Page({
  /**
@@ -49,7 +50,8 @@
      useCount: 0, // 组件已使用次数
      residue: 0, // 组卷剩余次数
      mockList: [] // 用户组卷提交信息
    }
    },
    flag: true
  },
@@ -415,20 +417,22 @@
        //教学资源 云学习
        if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') {
          if (res.datas.cmsDatas[0].datas.length > 0) {
            res.datas.cmsDatas[0].datas.forEach(item => {
              item.checked = false
            })
            const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
            if (type.refCode == 'jsek_teachingResources') {
              res.datas.cmsDatas[0].datas.forEach(item => {
                item.checked = false
              })
              const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
              console.log(list, 'list');
              this.setData({
                teach: list,
                loading: false
              })
              this.findChildIds(this.data.teach, this.data.openTeachids = [])
            } else if (type.refCode == 'jsek_cloudLearning') {
              const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
              // res.datas.cmsDatas[0].datas.forEach(item => {
              //   item.checked = false
              // })
              // const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
              console.log(list, 'currentlist');
              this.setData({
                learn: list,
                loading: false
@@ -513,6 +517,7 @@
      if (this.data.tabValue == 'jsek_teachingResources') {
        item.checked = false
      } else if (this.data.tabValue == 'jsek_cloudLearning') {
        item.checked = false
        item.isbuy = this.resourceIsBuy(item)
        item.isShopCar = this.isShoppingCart(item)
      }
@@ -1115,6 +1120,88 @@
          })
        }
      })
  }
  },
  // 购买组卷
  async buyMock() {
    let res
    if (!this.data.mockData.id) return wx.showToast({
      icon: "error",
      title: '暂无组卷',
      mask: true
    })
    // 构建订单查询对象
    try {
      let query = {
        remarks: '组卷',
        requests: [
          {
            saleMethodId: this.data.mockData.id,
            count: 1
          }
        ]
      }
      if (this.data.flag) {
        this.setData({
          flag: false
        })
        res = await app.MG.store.initOrder(query)
      }
      if (res.orderNumber && this.data.mockData.price) {
        wx.navigateTo({
          url: `/pages/cart/paymentPage/index?orderNumber=${res.orderNumber}`,
        })
      } else {
        // 0元直接领取
        // 确认订单
        const confirmOrderRes = await app.MG.store.confirmOrder({ orderNum: res.orderNumber })
        if (confirmOrderRes) {
          wx.showToast({
            icon: "success",
            title: '领取成功',
          })
          this.setData({
            flag: true
          })
          await this.recordBuyMock() // 记录购买时间
        }
      }
    } catch (error) {
      console.log(error)
    }
  },
  // 记录购买组卷时间
  recordBuyMock() {
    const num = this.data.mockData.mockList.length
    const id = tool.uuid(8)
    const createDate = new Date().getTime()
    const mockList = this.data.mockData.mockList
    mockList.push({ id, createDate, name: `第${num + 1}套试卷`, state: '0' })
    this.setData({
      'mockData.mockList': mockList
    })
    // 记录购买时间,并设状态state为1,表示刚购买完成组卷
    app.MG.identity.setUserKey({
      setKeyRequests: [
        {
          domain: 'mockData',
          key: this.data.bookDetail.id + '',
          value: JSON.stringify(this.data.mockData.mockList)
        }
      ]
    })
  },
  // 底部购买按钮
  buyBtn() {
    if (this.data.tabValue == 'brief') {
      this.buyBook()
    }
    else if (this.data.tabValue == 'jsek_cloudLearning') {
      console.log('云学习');
    } else if (this.data.tabValue == 'questionBank') {
      this.buyMock()
    } else {
      console.log(this.data.tabValue);
    }
  }
})