| | |
| | | const util = require('./components/util') // 引入封装过的加载提示 |
| | | const app = getApp() |
| | | Component({ |
| | | // checked: false, |
| | | |
| | | properties: { |
| | | treeList: { |
| | | type: Array, |
| | |
| | | type: String, |
| | | value: '' |
| | | }, |
| | | openTeachids: { |
| | | openIds: { |
| | | type: Array, |
| | | value: '' |
| | | }, |
| | | openLearnids: { |
| | | type: Array, |
| | | value: "" |
| | | value: [], |
| | | } |
| | | , |
| | | isShowCheck: { |
| | | type: Boolean, |
| | | value: false, |
| | | } |
| | | }, |
| | | data: { |
| | | activeValues: [0], |
| | | webpageSrc: '' |
| | | activeValues: [1, 2], |
| | | webpageSrc: '', |
| | | cloudShoppingCart: [] |
| | | }, |
| | | ready() { |
| | | this.setData({ |
| | | |
| | | }) |
| | | console.log('准备'); |
| | | }, |
| | | onShow() { |
| | | |
| | | }, |
| | | observers: { |
| | | 'openIds': function (newValue) { |
| | | var myEventDetail = { |
| | | } |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true |
| | | } |
| | | this.triggerEvent('handleTree', myEventDetail, myEventOption) |
| | | } |
| | | }, |
| | | |
| | | |
| | | 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) { |
| | | this.setData({ |
| | | activeValues: e.detail.value, |
| | | openIds: e.detail.value, |
| | | }); |
| | | console.log('传递', this.properties.buyIds); |
| | | }, |
| | | handleCheck(data) { |
| | | for (let index = 0; index < data.length; index++) { |
| | |
| | | // 判断资源是否购买 |
| | | resourceIsBuy(data) { |
| | | if (data.saleMethod && data.saleMethod.length) { |
| | | const isSHow = buyIdList.value.some((item) => item == data.saleMethod[0].Id) |
| | | if (data.saleMethod[0].State == 'Disable') return false |
| | | const isSHow = this.properties.buyIds.some((item) => item == data.saleMethod[0].Id) |
| | | return !isSHow |
| | | } else { |
| | | return false |
| | |
| | | }, |
| | | // 跳转音视频播放器 |
| | | goPlayer(e) { |
| | | if (this.properties.isShowCheck) return true |
| | | const item = e.currentTarget.dataset.item |
| | | const parent = e.currentTarget.dataset.parent |
| | | let url |
| | | if (item.selectType == 'video') { |
| | | if (item.selectType == 'video' || item.learnSelectType == 'video') { |
| | | url = '/packageDomain/pages/resourceDetails/myVideo/index' |
| | | } else if (item.selectType == 'audio') { |
| | | } else if (item.selectType == 'audio' || item.learnSelectType == 'audio') { |
| | | url = '/packageDomain/pages/resourceDetails/myAudio/index' |
| | | } else if (item.selectType == 'picture' || item.selectType == 'zip') { |
| | | url = '/packageDomain/pages/resourceDetails/document/index' |
| | | } |
| | | |
| | | // else { |
| | | // |
| | | // } |
| | | if (this.properties.tab == 'jsek_cloudLearning' && this.resourceIsBuy(item)) { |
| | | return wx.showToast({ |
| | | icon: 'error', |
| | | title: '请先购买该资源', |
| | | }) |
| | | } |
| | | wx.navigateTo({ |
| | | url: `${url}?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parent.productLinkPath}&parentName=${parent.name}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}`, |
| | | }) |
| | |
| | | result.push(...item.children); |
| | | } |
| | | } |
| | | console.log(this.properties.treeList); |
| | | console.log(this.properties.treeList, 'this.properties.treeList'); |
| | | this.properties.treeList.forEach(item => { |
| | | findChildren(item); |
| | | }); |
| | |
| | | } |
| | | } |
| | | tree.forEach(node => { |
| | | |
| | | flatten(node); |
| | | }); |
| | | // console.log(result, 'result'); |
| | | return result |
| | | }, |
| | | findAndUpdateItemById(tree, id) { |
| | | function findAndUpdate(node) { |
| | | if (node.id === id) { |
| | | node.check = true; // 将目标项的 check 属性设置为 true |
| | | return true; // 返回 true 表示找到了目标项 |
| | | } |
| | | if (node.children && node.children.length > 0) { |
| | | for (let child of node.children) { |
| | | if (findAndUpdate(child)) { |
| | | return true; // 如果在子节点中找到了目标项,则直接返回 true |
| | | } |
| | | } |
| | | } |
| | | return false; // 表示未找到目标项 |
| | | } |
| | | |
| | | for (let node of tree) { |
| | | if (findAndUpdate(node)) { |
| | | break; // 如果在顶层节点中找到了目标项,直接退出循环 |
| | | } |
| | | } |
| | | }, |
| | | // 变为true |
| | | findAndUpdateItemsByIds(tree, ids) { |
| | | function findAndUpdate(node) { |
| | | if (ids.includes(node.id)) { |
| | | node.checked = true; // 将目标项的 check 属性设置为 true |
| | | // console.log(node, 'node'); |
| | | node.checked = !node.checked // 将目标项的 check 属性设置为 true |
| | | } |
| | | if (node.children && node.children.length > 0) { |
| | | for (let child of node.children) { |
| | |
| | | } |
| | | |
| | | for (let node of tree) { |
| | | |
| | | findAndUpdate(node); // 对每个顶层节点执行查找和更新操作 |
| | | } |
| | | // console.log(tree, 'tree345'); |
| | | return tree; // 返回修改后的完整数组 |
| | | }, |
| | | |
| | | checkResoucrceInfo(tree, id) { |
| | | function findAndUpdate(node) { |
| | | if (node.sysType == 'CmsFolder' && node.children.length > 0) { |
| | | for (let index = 0; index < node.children.length; index++) { |
| | | const element = node.children[index]; |
| | | findAndUpdate(element) |
| | | } |
| | | } |
| | | else if (id == node.id && node.sysType == "CmsItem") { |
| | | node.checked = !node.checked // 将目标项的 check 属性设置为 true |
| | | } |
| | | } |
| | | for (let node of tree) { |
| | | 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 |
| | | }) |
| | | }, |
| | | |
| | | // 章节勾选 |
| | | checkResourceTitle(e) { |
| | | // 这个时候checked的值是fals |
| | | const item = e.currentTarget.dataset.item |
| | | console.log(item, 'item'); |
| | | let list = this.flattenTree([item]) |
| | | let ids = [] |
| | | list.forEach(item => { |
| | | ids.push(item.id) |
| | | }) |
| | | const tab = this.findAndUpdateItemsByIds([item], ids) |
| | | console.log(ids, tab); |
| | | } |
| | | const updatedTreeList = this.findAndUpdateItemsByIds(this.properties.treeList, ids); |
| | | this.setData({ |
| | | treeList: updatedTreeList // 更新 treeList 数据 |
| | | }); |
| | | console.log(list, 'list'); |
| | | list.forEach(items => { |
| | | console.log(items.checked, 'itesasd'); |
| | | if (!items.checked) { |
| | | this.setData({ |
| | | cloudShoppingCart: items |
| | | }) |
| | | } |
| | | }) |
| | | this.onCloudShoppingCart() |
| | | }, |
| | | // 子项勾选 |
| | | checkResource(e) { |
| | | const citem = e.currentTarget.dataset.item |
| | | console.log(e); |
| | | const updataList = this.checkResoucrceInfo(this.properties.treeList, citem.id) |
| | | console.log(updataList); |
| | | this.setData({ |
| | | treeList: updataList |
| | | }) |
| | | }, |
| | | // 加入购物车 |
| | | async onCloudShoppingCart() { |
| | | let requests = [] |
| | | const item = this.data.cloudShoppingCart |
| | | console.log(item, 'item'); |
| | | item.forEach((items) => { |
| | | if (items.saleMethod.length) { |
| | | requests.push({ |
| | | saleMethodId: items.saleMethod[0].Id, |
| | | count: 1 |
| | | }) |
| | | } |
| | | }) |
| | | let query = { |
| | | remarks: '云学习', |
| | | requests |
| | | } |
| | | // 查询订单 |
| | | let initOrderRes = await app.MG.store.initOrder(query) |
| | | let parameter = { |
| | | orderNum: initOrderRes.orderNumber |
| | | } |
| | | const confirmOrderRes = await app.MG.store.confirmOrder(parameter) |
| | | // if (confirmOrderRes.orderNumber) { |
| | | // wx.navigateTo({ |
| | | // url: `/pages/cart/paymentPage/index?orderNumber=${confirmOrderRes.orderNumber}`, |
| | | // }) |
| | | // requests = [] |
| | | // } |
| | | }, |
| | | }, |
| | | onCloudShoppingCart() { |
| | | console.log(this.properties.treeList); |
| | | }, |
| | | oncheckbox() { |
| | | console.log(111); |
| | | }, |
| | | logdata(e) { |
| | | console.log(e); |
| | | onCheckAllChange(e) { |
| | | debugger |
| | | console.log('checkbox', e.detail.value); |
| | | // this.setData({ |
| | | // checkAllValues: event.detail, |
| | | // }); |
| | | } |
| | | }) |