| | |
| | | } |
| | | }, |
| | | data: { |
| | | |
| | | activeValues: [1, 2], |
| | | webpageSrc: '', |
| | | cloudShoppingCart: [] |
| | | }, |
| | | onShow() { |
| | | }, |
| | | observers: { |
| | | 'treeList': function (newValue) { |
| | | |
| | | } |
| | | }, |
| | | |
| | | methods: { |
| | | handleList(tree) { |
| | | for (let index = 0; index < tree.length; index++) { |
| | | const item = tree[index]; |
| | | if (item.sysType == 'CmsItem' && !item.checked) { |
| | | |
| | | } |
| | | if (item.children && item.children.length > 0) { |
| | | this.handleList(item.children) |
| | | } |
| | | } |
| | | }, |
| | | // 节点展开 |
| | | handleChange(e) { |
| | | // console.log(this.properties.treeList, 'this.properties.treeList'); |
| | |
| | | }, |
| | | // 拿到当前项子项 |
| | | flattenTree(tree) { |
| | | |
| | | let result = []; |
| | | |
| | | function flatten(node) { |
| | | |
| | | result.push(node); |
| | | |
| | | if (node.children && node.children.length > 0) { |
| | | |
| | | node.children.forEach(child => { |
| | | flatten(child); |
| | | }); |
| | |
| | | } |
| | | } |
| | | else if (id == node.id && node.sysType == "CmsItem") { |
| | | debugger |
| | | node.checked = !node.checked // 将目标项的 check 属性设置为 true |
| | | } |
| | | } |
| | |
| | | findAndUpdate(node); // 对每个顶层节点执行查找和更新操作 |
| | | } |
| | | return tree; // 返回修改后的完整数组 |
| | | }, |
| | | |
| | | checkAll() { |
| | | const ids = [] |
| | | const list = [] |
| | | this.properties.treeList.forEach(item => { |
| | | if (item.children && item.children.length > 0) { |
| | | list.push(...this.flattenTree([item])) |
| | | } |
| | | }) |
| | | list.forEach(item => { |
| | | ids.push(item.id) |
| | | }) |
| | | const updataList = this.findAndUpdateItemsByIds(this.properties.treeList, ids); |
| | | this.setData({ |
| | | treeList: updataList |
| | | }) |
| | | }, |
| | | |
| | | // 章节勾选 |
| | |
| | | // 子项勾选 |
| | | checkResource(e) { |
| | | const citem = e.currentTarget.dataset.item |
| | | this.checkResoucrceInfo(this.properties.treeList, citem.id) |
| | | console.log(e); |
| | | const updataList = this.checkResoucrceInfo(this.properties.treeList, citem.id) |
| | | console.log(updataList); |
| | | this.setData({ |
| | | treeList: updataList |
| | | }) |
| | | }, |
| | | // 加入购物车 |
| | | async onCloudShoppingCart() { |
| | |
| | | // } |
| | | }, |
| | | }, |
| | | onCheckAllChange(e) { |
| | | debugger |
| | | console.log('checkbox', e.detail.value); |
| | | // this.setData({ |
| | | // checkAllValues: event.detail, |
| | | // }); |
| | | } |
| | | }) |