| | |
| | | electronicBookList: [], //样书单电子书 |
| | | paperBookCount: 0, //纸质书剩余次数 |
| | | ebookCount: 0, //电子书剩余次数 |
| | | resourceCodeList: [], // 资源refcode列表 |
| | | userInfo: {}, |
| | | pageLoading: true, |
| | | fileInfo: { |
| | |
| | | }, |
| | | }; |
| | | app.MG.store.getProductDetail(query).then(async (res) => { |
| | | this.getResourceCode(id, res.datas.rootCmsItemId) |
| | | this.setData({ |
| | | bookDetail: res.datas, |
| | | buyIdList: res.datas.purchasedSaleMethodIdList, |
| | |
| | | |
| | | }); |
| | | }); |
| | | }, |
| | | getResourceCode(bookId, cmsId) { |
| | | let query = { |
| | | path: '*', |
| | | queryType: '*', |
| | | productId: bookId, |
| | | cmsPath: cmsId, |
| | | itemFields: { |
| | | SysType: 'Cms' |
| | | }, |
| | | pading: { |
| | | start: 99, |
| | | size: 0 |
| | | } |
| | | } |
| | | app.MG.store.getProductDetail(query).then((res) => { |
| | | this.setData({ |
| | | resourceCodeList: res.datas.cmsDatas[0].datas |
| | | }) |
| | | // console.log('图书资源', res.datas.cmsDatas[0].datas) |
| | | }) |
| | | }, |
| | | //请求子商品的文件 |
| | | getSubTtem() { |
| | |
| | | learnPath: type.productLinkPath |
| | | }) |
| | | const dataList = res.datas.cmsDatas[0].datas |
| | | if (dataList.length) { |
| | | // 先判断是否否买云学习整个目录 |
| | | let couldId = null |
| | | let codeData = null |
| | | if (this.data.resourceCodeList.length) { |
| | | codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') |
| | | if (codeData && codeData.saleMethod && codeData.saleMethod.length) |
| | | couldId = codeData.saleMethod[0].Id |
| | | } |
| | | if (couldId) { |
| | | this.setData({ |
| | | isGoBuyResource: this.data.buyIdList.indexOf(couldId) > -1 ? false : true |
| | | }) |
| | | } else if (dataList.length) { |
| | | const tag = dataList.findIndex(item => item.saleMethod.length && item.saleMethod[0].Price > 0) |
| | | this.setData({ |
| | | isGoBuyResource: tag > -1 ? true : false |
| | |
| | | let result = []; |
| | | if (type.refCode == "jsek_teachingResources") { |
| | | this.findChildIds(list, result); |
| | | const newUSeList = this.deleteTreeData(list, result) |
| | | console.log('树剔除', result, newUSeList); |
| | | console.log('树加一', this.increaseTreeData(list, newUSeList, 16094)); |
| | | |
| | | this.setData({ |
| | | openTeachids: result, |
| | | loading: false, |
| | |
| | | }, |
| | | // 判断资源是否购买 |
| | | resourceIsBuy(data) { |
| | | if (data.saleMethod && data.saleMethod.length) { |
| | | let couldId = null |
| | | let codeData = null |
| | | if (this.data.resourceCodeList.length) { |
| | | codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') |
| | | if (codeData && codeData.saleMethod && codeData.saleMethod.length) |
| | | couldId = codeData.saleMethod[0].Id |
| | | } |
| | | if (couldId) { |
| | | return this.data.buyIdList.indexOf(couldId) > -1 ? false : true |
| | | } else if (data.saleMethod && data.saleMethod.length) { |
| | | const isSHow = this.data.buyIdList.some( |
| | | (item) => item == data.saleMethod[0].Id |
| | | ); |
| | |
| | | }, |
| | | // 判断资源加入购物车按钮是否显示 |
| | | isShoppingCart(data) { |
| | | if (data.saleMethod && data.saleMethod.length) { |
| | | let couldId = null |
| | | let codeData = null |
| | | if (this.data.resourceCodeList.length) { |
| | | codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') |
| | | if (codeData && codeData.saleMethod && codeData.saleMethod.length) |
| | | couldId = codeData.saleMethod[0].Id |
| | | } |
| | | if (couldId) { |
| | | return this.data.buyIdList.indexOf(couldId) > -1 ? false : true |
| | | } else if (data.saleMethod && data.saleMethod.length) { |
| | | if (data.saleMethod[0].Price <= 0) return false; |
| | | // 再判断是否购买 |
| | | const isBuy = this.data.buyIdList.some( |
| | |
| | | teach: tree, |
| | | }); |
| | | }, |
| | | }); |
| | | |
| | | // 剔除树结构多余,只保留初始需要展开的 |
| | | // 第一步:保留树结构前两层,并将展开项加入数组 |
| | | deleteTreeData(list, openids) { |
| | | let resultList = [] |
| | | for (let index = 0; index < list.length; index++) { |
| | | const item = list[index]; |
| | | for (let cindex = 0; cindex < item.children.length; cindex++) { |
| | | const citem = item.children[cindex]; |
| | | citem.children = [] |
| | | } |
| | | resultList.push(item) |
| | | } |
| | | for (let index = 0; index < openids.length; index++) { |
| | | const id = openids[index]; |
| | | // 展开项加入数组 |
| | | this.increaseTreeData(list, resultList, id) |
| | | } |
| | | return resultList |
| | | }, |
| | | // 传递ids,将需要展开的id的children 赋值 |
| | | increaseTreeData(treeList, list, openid) { |
| | | |
| | | let num = 0; |
| | | // let useData = treeList.find(item => item.id == openid) |
| | | for (let index = 0; index < treeList.length; index++) { |
| | | const item = treeList[index]; |
| | | if (item.id == openid && num >= 3) { |
| | | debugger |
| | | let useArr = item.children ? item.children : [] |
| | | changeList(list, openid, useArr) |
| | | } else { |
| | | num += 1 |
| | | this.increaseTreeData(item.children, list, openid) |
| | | } |
| | | } |
| | | // 递归前两层,找出需要展开的 |
| | | const changeList = (isList, id, childrenList) => { |
| | | for (let dindex = 0; dindex < isList.length; dindex++) { |
| | | const ditem = isList[cindex]; |
| | | if (ditem.id == id) { |
| | | diitem.children = childrenList |
| | | return true |
| | | } else { |
| | | changeList(ditem.children, id, childrenList) |
| | | } |
| | | } |
| | | } |
| | | return list |
| | | } |
| | | }) |