| | |
| | | // pages/bookServices/detail/index.js |
| | | import Message from 'tdesign-miniprogram/message/index.js'; |
| | | import Toast from 'tdesign-miniprogram/toast/index'; |
| | | const app = getApp(); |
| | | Page({ |
| | | /** |
| | |
| | | loading: false, |
| | | isShowTeachDownload: false, // 提示PC下载弹窗状态 |
| | | confirmBtn: { content: '我知道了', variant: 'base' }, |
| | | mockData: { |
| | | id: 0, // 销售id |
| | | price: 0, // 售价 |
| | | count: 0, // 组卷已购买次数 |
| | | useCount: 0, // 组件已使用次数 |
| | | residue: 0, // 组卷剩余次数 |
| | | mockList: [] // 用户组卷提交信息 |
| | | } |
| | | }, |
| | | |
| | | |
| | | resetTree: function (e) { |
| | | this.setData({ |
| | |
| | | }); |
| | | this.getBookInfo(options.id); |
| | | this.getResourceClass() // 获取资源所属分类 |
| | | this.getApplyInfo(options.id) |
| | | const token = wx.getStorageSync('jsek-token') |
| | | if (token) { |
| | | this.getShoppingCartProductGet() |
| | | this.getApplyInfo(options.id) |
| | | this.getMockData() |
| | | } |
| | | }, |
| | | |
| | |
| | | }, |
| | | // 获取图书详情 |
| | | getBookInfo(id) { |
| | | this.setData({ |
| | | "mockData'.id": 0, |
| | | "mockData.price": 0, |
| | | "mockData.count": 0 |
| | | }) |
| | | const query = { |
| | | path: '*', |
| | | queryType: '*', |
| | |
| | | }, |
| | | }; |
| | | app.MG.store.getProductDetail(query).then(async (res) => { |
| | | |
| | | console.log(res.datas); |
| | | this.setData({ |
| | | bookDetail: res.datas, |
| | | cmsDatas: res.datas.cmsDatas[0].datas, |
| | |
| | | const iconType = JSON.parse(res.datas.bookClassification)[0][0]; |
| | | const classType = JSON.parse(res.datas.bookClassification)[0][1]; |
| | | const className = await this.getBookClass(iconType, classType) |
| | | // 获取组卷销售id |
| | | if (res.datas.saleMethod && res.datas.saleMethod.length) { |
| | | res.datas.saleMethod.forEach((item) => { |
| | | if (item.SaleType == 'combinationTestPaper') { |
| | | this.setData({ |
| | | 'mockData.id': item.Id, |
| | | 'mockData.price': item.Price |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | // 获取组卷已购买次数 |
| | | if (res.datas.purchasedSaleMethodIdList && res.datas.purchasedSaleMethodIdList.length) { |
| | | if (this.data.mockData.id) { |
| | | let count = res.datas.purchasedSaleMethodIdList.filter( |
| | | (item) => item == this.data.mockData.id |
| | | ).length |
| | | this.setData({ |
| | | 'mockData.count': count |
| | | }) |
| | | } |
| | | } |
| | | console.log('组卷信息', this.data.mockData); |
| | | this.setData({ |
| | | 'bookDetail.publicationDate': this.formatDate(this.data.bookDetail.publicationDate), |
| | | 'bookDetail.class': className, |
| | |
| | | 'bookDetail.paperPrice': this.numFormat(this.data.bookDetail.paperPrice), |
| | | }); |
| | | }); |
| | | |
| | | }, |
| | | // 获取图书分类 |
| | | async getBookClass(iconType, classType) { |
| | |
| | | goShop(e) { |
| | | const { link } = e.currentTarget.dataset; |
| | | wx.navigateTo({ |
| | | url: link, |
| | | }); |
| | | url: `/pages/bookServices/webpage/index?url=${link}`, |
| | | }) |
| | | }, |
| | | onTabsChange(e) { |
| | | this.setData({ |
| | |
| | | item.checked = false |
| | | }) |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | |
| | | console.log(list, 'list'); |
| | | this.setData({ |
| | | teach: list, |
| | | loading: false |
| | |
| | | }, |
| | | |
| | | // 图书添加购物车 |
| | | addBookShopcCar() { |
| | | async addBookShopcCar() { |
| | | 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.bookDetail.defaultSaleMethodId, 'this.data.bookDetail.defaultSaleMethodId'); |
| | | const determine = shoppingCartGetId.some((item) => item == this.data.bookDetail.defaultSaleMethodId) |
| | | console.log(determine); |
| | | |
| | | if (!determine) { |
| | | let query = { |
| | | requests: [ |
| | | { |
| | | saleMethodId: this.data.bookDetail.defaultSaleMethodId, |
| | | storeEventId: null, |
| | | agentCode: '电子书' |
| | | } |
| | | ] |
| | | } |
| | | const addRes = app.MG.store.addShoppingCart(query) |
| | | this.showSuccessToast() |
| | | |
| | | } else { |
| | | Toast({ |
| | | context: this, |
| | | selector: '#t-toast', |
| | | message: '已添加', |
| | | theme: 'success', |
| | | direction: 'column', |
| | | }); |
| | | } |
| | | |
| | | }, |
| | | |
| | | showSuccessToast() { |
| | | Toast({ |
| | | context: this, |
| | | selector: '#t-toast', |
| | | message: '添加成功', |
| | | theme: 'success', |
| | | direction: 'column', |
| | | }); |
| | | }, |
| | | |
| | | |
| | | |
| | | async buyBook() { |
| | | let bookOrdersId = '' |
| | | let query = { |
| | | remarks: '电子书', |
| | | requests: [ |
| | | { |
| | | saleMethodId: this.data.bookDetail.defaultSaleMethodId, |
| | | storeEventId: null, |
| | | agentCode: '电子书' |
| | | count: 1 |
| | | } |
| | | ] |
| | | } |
| | | const addRes = app.MG.store.addShoppingCart(query) |
| | | // 发起订单初始化请求并等待结果 |
| | | const res = await app.MG.store.initOrder(query) |
| | | // 获取订单号并赋值给 orderNumber.value |
| | | bookOrdersId = res.orderNumber |
| | | console.log(bookOrdersId); |
| | | // 检查订单号是否存在 |
| | | if (bookOrdersId) { |
| | | const url = '/pages/cart/paymentPage/index?orderNumber=' + bookOrdersId |
| | | wx.navigateTo({ |
| | | url |
| | | }) |
| | | } else { |
| | | console.log(222); |
| | | } |
| | | |
| | | }, |
| | | |
| | | // 获取教学资源下载是否申请通过 |
| | | getApplyInfo(id) { |
| | | // 获取当前时间 |
| | |
| | | if (initOrderRes.orderNumber) { |
| | | // bookService: orderNumber.value, 少传这个 ,暂时不知道有什么用 |
| | | wx.navigateTo({ |
| | | url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNum=${initOrderRes.orderNumber}`, |
| | | url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNumber=${initOrderRes.orderNumber}`, |
| | | }) |
| | | } else { |
| | | // 订单号不存在,显示警告消息 |
| | |
| | | handleTrue() { |
| | | // findAndUpdateItemsByIds(this.date.) |
| | | }, |
| | | // 组卷格式化日期显示 |
| | | DateFormat(date, fmt) { |
| | | if (date && fmt) { |
| | | let _date = new Date(date) |
| | | var o = { |
| | | 'M+': _date.getMonth() + 1, //月份 |
| | | 'd+': _date.getDate(), //日 |
| | | 'h+': _date.getHours(), //小时 |
| | | 'm+': _date.getMinutes(), //分 |
| | | 's+': _date.getSeconds(), //秒 |
| | | 'q+': Math.floor((_date.getMonth() + 3) / 3), //季度 |
| | | S: _date.getMilliseconds() //毫秒 |
| | | } |
| | | if (/(y+)/.test(fmt)) { |
| | | fmt = fmt.replace(RegExp.$1, (_date.getFullYear() + '').substr(4 - RegExp.$1.length)) |
| | | } |
| | | for (var k in o) { |
| | | if (new RegExp('(' + k + ')').test(fmt)) { |
| | | fmt = fmt.replace( |
| | | RegExp.$1, |
| | | RegExp.$1.length == 1 |
| | | ? (o)[k] |
| | | : ('00' + (o)[k]).substr(('' + (o)[k]).length) |
| | | ) |
| | | } |
| | | } |
| | | return fmt |
| | | } else { |
| | | return '' |
| | | } |
| | | }, |
| | | // 获取组卷答题数据 |
| | | getMockData() { |
| | | this.setData({ |
| | | 'mockData.useCount': 0, |
| | | 'mockData.mockList': [] |
| | | }) |
| | | app.MG.identity |
| | | .getUserKey({ |
| | | domain: 'mockData', |
| | | keys: [this.data.bookId] |
| | | }) |
| | | .then((res) => { |
| | | console.log(JSON.parse(res[0].value)); |
| | | if (res && res.length) { |
| | | const mock = JSON.parse(res[0].value) |
| | | mock.forEach(item => { |
| | | item.createDate = this.DateFormat(item.createDate, 'yyyy-MM-dd') |
| | | }) |
| | | this.setData({ |
| | | 'mockData.mockList': mock |
| | | }) |
| | | // 组卷已使用次数 |
| | | res.forEach((item) => { |
| | | // 已经有答题分数等数据,证明组卷已经使用完毕 |
| | | if (item.resultData) { |
| | | this.setData({ |
| | | 'mockData.useCount': this.data.mockData.useCount + 1 |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | }) |