| | |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | bookId: '', |
| | | barHeight: '', |
| | | navBarHeight: '', |
| | | options: { |
| | |
| | | teachResources: [], |
| | | teach: [], |
| | | learn: [], |
| | | test: [], |
| | | openTeachids: [], |
| | | openLearnids: [], |
| | | openTestids: [], |
| | | resourceClassList: [], // 资源所属分类 |
| | | applyState: "", // 教学资源申请状态 |
| | | deadline: "", // 教学资源申请有效日期 |
| | |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | | this.setData({ |
| | | bookId: options.id, |
| | | barHeight: systInfo.statusBarHeight, |
| | | navBarHeight: navBarHeight, |
| | | }); |
| | |
| | | this.getBookInfo(options.id); |
| | | this.getResourceClass() // 获取资源所属分类 |
| | | this.getApplyInfo(options.id) |
| | | if (wx.getAccountInfoSync('jsek-token')) { |
| | | const token = wx.getStorageSync('jsek-token') |
| | | if (token) { |
| | | this.getShoppingCartProductGet() |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | } |
| | | console.log('切换', this.data.tabValue); |
| | | }, |
| | | // 获取资源所属分类 |
| | | getResourceClass() { |
| | |
| | | const data = res.datas.cmsDatas[0].datas.filter( |
| | | (item) => item.refCode == 'jsek_questionBank' |
| | | ) |
| | | if (data.length) return getResourceData(data[0]) |
| | | if (data.length) return this.getResourceData(data[0]) |
| | | } |
| | | //教学资源 云学习 |
| | | if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') { |
| | |
| | | }) |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | this.setData({ |
| | | teachResources: list, |
| | | teach: list |
| | | }) |
| | | this.findChildIds(this.data.teachResources, this.data.openTeachids = []) |
| | | this.findChildIds(this.data.teach, this.data.openTeachids = []) |
| | | } else if (type.refCode == 'jsek_cloudLearning') { |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | this.setData({ |
| | | learn: list |
| | | }) |
| | | console.log('云学习', this.data.learn); |
| | | this.findChildIds(this.data.teachResources, this.data.openLearnids = []) |
| | | this.findChildIds(this.data.learn, this.data.openLearnids = []) |
| | | } |
| | | } else { |
| | | // 无数据 |
| | | } |
| | | } else if (type.refCode == 'jsek_questionBank') { |
| | | console.log('云测试'); |
| | | // const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | this.setData({ |
| | | test: res.datas.cmsDatas[0].datas |
| | | }) |
| | | // this.findChildIds(this.data.test, this.data.openTestids = []) |
| | | console.log('云测试', this.data.test); |
| | | } else { |
| | | console.log('其他'); |
| | | } |
| | |
| | | .catch((e) => { |
| | | console.log(e) |
| | | }) |
| | | console.log('信息', this.data); |
| | | }, |
| | | // 获取tag下所有资源 |
| | | async getAllResource(data) { |
| | |
| | | return false |
| | | } |
| | | }, |
| | | // 获取已购买商品 |
| | | getShoppingCartProductGet() { |
| | | let query = { |
| | | start: 0, |
| | |
| | | } else { |
| | | return false |
| | | } |
| | | }, |
| | | // 遍历树结构转换为数组方法 |
| | | handleTreeData(array) { |
| | | const flattenedArray = [] |
| | | array.forEach((node) => { |
| | | // 将当前节点添加到展开的数组中 |
| | | flattenedArray.push(node) |
| | | // 递归处理子节点 |
| | | if (node.children && node.children.length > 0) { |
| | | const childrenArray = handleTreeData(node.children) |
| | | flattenedArray.push(...childrenArray) |
| | | } |
| | | }) |
| | | return flattenedArray.filter((item) => item.sysType == 'CmsItem') |
| | | }, |
| | | // 云学习一键领取 |
| | | async getFreeResource() { |
| | | // if (!localStorage.getItem('jsek-token')) { |
| | | // return logIn() |
| | | // } |
| | | let arr = handleTreeData(this.data.learn).filter((item) => resourceIsBuy(item)) |
| | | let freeIds = arr.filter((item) => { |
| | | return item.saleMethod[0].Price == 0 |
| | | }) |
| | | if (!freeIds.length) return console.log('暂无免费资源') |
| | | btnLoading.freeBtn = true |
| | | let requests = [] |
| | | freeIds.forEach((item, index) => { |
| | | if (resourceIsBuy(item)) { |
| | | requests.push({ |
| | | saleMethodId: item.saleMethod[0].Id, |
| | | count: 1 |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | let query = { |
| | | remarks: '云学习', |
| | | requests, |
| | | } |
| | | try { |
| | | const initOrderRes = await app.MG.store.initOrder(query) |
| | | let parameter = { |
| | | orderNum: initOrderRes.orderNumber |
| | | } |
| | | // 确认订单 |
| | | const confirmOrderRes = await MG.store.confirmOrder(parameter) |
| | | if (confirmOrderRes.orderNumber) { |
| | | // btnLoading.freeBtn = false |
| | | console.log('领取成共'); |
| | | this.getBookInfo(this.data.bookId) |
| | | } |
| | | } catch (error) { |
| | | console.log(error) |
| | | } |
| | | } |
| | | }) |