| | |
| | | // 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({ |
| | | /** |
| | |
| | | useCount: 0, // 组件已使用次数 |
| | | residue: 0, // 组卷剩余次数 |
| | | mockList: [] // 用户组卷提交信息 |
| | | } |
| | | }, |
| | | flag: true, |
| | | applyResourceLoading: false, |
| | | noResources: false |
| | | }, |
| | | |
| | | |
| | |
| | | }) |
| | | } |
| | | } |
| | | console.log('组卷信息', this.data.mockData); |
| | | this.setData({ |
| | | 'bookDetail.publicationDate': this.formatDate(this.data.bookDetail.publicationDate), |
| | | 'bookDetail.class': className, |
| | |
| | | 'bookDetail.oldPrice': this.numFormat(this.data.bookDetail.oldPrice), |
| | | 'bookDetail.paperPrice': this.numFormat(this.data.bookDetail.paperPrice), |
| | | }); |
| | | console.log('图书信息', this.data.bookDetail); |
| | | }); |
| | | |
| | | }, |
| | |
| | | }, |
| | | onTabsChange(e) { |
| | | this.setData({ |
| | | tabValue: e.detail.value |
| | | tabValue: e.detail.value, |
| | | noResources: false |
| | | }) |
| | | if (e.detail.label == '教学资源' || e.detail.label == '云学习' || e.detail.label == '云测试') { |
| | | const checkData = this.data.cmsDatas.find(item => item.refCode == e.detail.value) |
| | |
| | | || (e.detail.value == 'questionBank' && !this.data.test.length)) { |
| | | this.getResourceData(checkData) |
| | | } |
| | | |
| | | } else { |
| | | this.setData({ |
| | | noResources: true |
| | | }) |
| | | } |
| | | } else if (e.detail.label == '云笔记') { |
| | | const token = wx.getStorageSync('jsek-token') |
| | |
| | | // 获取教学资源 云学习 云测试 |
| | | getResourceData(type) { |
| | | this.setData({ |
| | | loading: true |
| | | loading: true, |
| | | noResources: false |
| | | }) |
| | | let query = { |
| | | path: '*', |
| | |
| | | app.MG.store |
| | | .getProductDetail(query) |
| | | .then(async (res) => { |
| | | if (!res.datas.cmsDatas[0].datas.length) { |
| | | return this.setData({ |
| | | noResources: true, |
| | | loading: false |
| | | }) |
| | | } |
| | | // 云测试,递归请求里层数据 |
| | | if (type.refCode == 'questionBank') { |
| | | const data = res.datas.cmsDatas[0].datas.filter( |
| | |
| | | //教学资源 云学习 |
| | | 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') { |
| | | res.datas.cmsDatas[0].datas.forEach(item => { |
| | | item.checked = false |
| | | }) |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | this.setData({ |
| | | learn: list, |
| | |
| | | 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) |
| | | } |
| | |
| | | |
| | | // 图书添加购物车 |
| | | async addBookShopcCar() { |
| | | |
| | | const token = wx.getStorageSync('jsek-token') |
| | | if (!token) { |
| | | return wx.getUserProfile({ |
| | | desc: '用户登录', |
| | | success: (res) => { |
| | | console.log(res); |
| | | } |
| | | }) |
| | | } |
| | | |
| | | const shoppingCartGetId = [] |
| | | |
| | | let query = { |
| | |
| | | }) |
| | | } |
| | | }) |
| | | console.log('有效日期', this.data.deadline); |
| | | this.setData({ |
| | | applyResourceLoading: false |
| | | }) |
| | | }, |
| | | // 申请教学资源 |
| | | applyResource() { |
| | | this.setData({ |
| | | applyResourceLoading: true |
| | | }) |
| | | // let role = userStore.userInfo ? userStore.userInfo.role : null |
| | | // if (role) { |
| | | // if (role == 'Teacher') { |
| | |
| | | } |
| | | app.MG.ugc.newTopicMessage(query).then((res) => { |
| | | if (res) { |
| | | Message.success('申请已提交,请待审核通过后下载') |
| | | wx.showToast({ |
| | | title: '申请已提交,请待审核通过后下载', |
| | | }) |
| | | } |
| | | this.getApplyInfo(this.data.bookDetail.id) |
| | | }) |
| | |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | // 购买组卷 |
| | | 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') { |
| | | const tree = this.selectComponent('#tree') |
| | | |
| | | tree.onCloudShoppingCart() |
| | | |
| | | |
| | | } else if (this.data.tabValue == 'questionBank') { |
| | | this.buyMock() |
| | | } else { |
| | | console.log(this.data.tabValue); |
| | | } |
| | | }, |
| | | |
| | | }) |