| | |
| | | wx.navigateBack(); |
| | | }, |
| | | |
| | | // 获取所有子项数量 |
| | | getChildrenItem(data) { |
| | | let num = 0 |
| | | |
| | | function getNum(data) { |
| | | for (let index = 0; index < data.length; index++) { |
| | | const item = data[index]; |
| | | if (item.sysType == 'CmsItem') { |
| | | num += 1 |
| | | } else if (item.sysType == 'CmsFolder') { |
| | | if (item.children && item.children.length) |
| | | getNum(item.children) |
| | | } |
| | | } |
| | | } |
| | | getNum(data) |
| | | return num |
| | | }, |
| | | |
| | | // 给·目录添加子项数量 |
| | | changeResourceChildren(list) { |
| | | const changeList = (list) => { |
| | | for (let index = 0; index < list.length; index++) { |
| | | const item = list[index]; |
| | | if (item.sysType == 'CmsFolder' && item.children && item.children.length) { |
| | | item.childrenItem = this.getChildrenItem([item]) |
| | | changeList(item.children) |
| | | } else if (item.sysType == 'CmsFolder' && item.children && !item.children.length) { |
| | | item.childrenItem = 0 |
| | | } else if (item.sysType == 'CmsFolder' && !item.children) { |
| | | item.childrenItem = 0 |
| | | } |
| | | } |
| | | } |
| | | changeList(list) |
| | | return list |
| | | }, |
| | | |
| | | // 扁平化数据转换tree |
| | | getTreeList(rootList, pathLength, newArr, path) { |
| | | for (const item of rootList) { |
| | |
| | | } |
| | | } |
| | | // newArr.push(item) |
| | | // 在插入过程中对数据进行排序 |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) |
| | | // 在插入过程中对数据进行排序 并且去除已经领取和购买的 |
| | | if (item.sysType == 'CmsFolder') { |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) |
| | | } else if (item.sysType == 'CmsItem' && this.resourceIsBuy(item)) { |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) |
| | | } |
| | | } |
| | | } |
| | | //给数组里面再添加一个children的空数组 |
| | |
| | | } |
| | | }); |
| | | // 显示 需要购买的和需要免费领取的 |
| | | const arr = res.datas.cmsDatas[0].datas.filter(item => this.resourceIsBuy(item)) |
| | | if (!arr.length) { |
| | | return this.setData({ |
| | | loading: false, |
| | | haider: true, |
| | | noData: true |
| | | }) |
| | | } |
| | | this.getTreeList(arr, 17, list, '\\') |
| | | // const arr = res.datas.cmsDatas[0].datas.filter(item => this.resourceIsBuy(item)) |
| | | // if (!arr.length) { |
| | | // return this.setData({ |
| | | // loading: false, |
| | | // haider: true, |
| | | // noData: true |
| | | // }) |
| | | // } |
| | | // debugger |
| | | this.getTreeList(res.datas.cmsDatas[0].datas, 17, list, '\\') |
| | | list = this.ensureTreeConsistency(list) |
| | | list = this.changeResourceChildren(list) |
| | | console.log('修改后云', list); |
| | | let result = []; |
| | | if (type.refCode == "jsek_teachingResources") { |