| | |
| | | } from "../../../../../../assets/js/login"; |
| | | const app = getApp(); |
| | | Component({ |
| | | // checked: false, |
| | | |
| | | properties: { |
| | | treeList: { |
| | | type: Array, |
| | | value: [], |
| | | }, |
| | | learnList: { |
| | | type: Array, |
| | | value: [] |
| | | }, |
| | | bookInfo: { |
| | | type: Object, |
| | |
| | | type: Boolean, |
| | | value: false, |
| | | }, |
| | | checkAllState: { |
| | | type: Boolean, |
| | | }, |
| | | }, |
| | | data: { |
| | | sonPurchaseSaleMethodId: "", |
| | |
| | | selectAll: [], |
| | | shoppingCart: true, |
| | | stop: false, |
| | | cart: true |
| | | }, |
| | | ready() { |
| | | this.setData({}); |
| | | console.log("准备"); |
| | | }, |
| | | ready() {}, |
| | | |
| | | onLoad() { |
| | | this.setData({ |
| | | sonPurchaseSaleMethodId: [], |
| | | }); |
| | | console.log( |
| | | this.data.sonPurchaseSaleMethodId, |
| | | "sonPurchaseSaleMethodId789" |
| | | ); |
| | | }, |
| | | observers: { |
| | | treeList: function (newValue) { |
| | | const list = []; |
| | | let checked = ""; |
| | | console.log("新值", this.properties.treeList); |
| | | this.properties.treeList.forEach((item) => { |
| | | if (item.children && item.children.length > 0) { |
| | | list.push(...this.flattenTree([item])); |
| | |
| | | goPlayer(e) { |
| | | // 检查登录状态 |
| | | const token = wx.getStorageSync(app.config.tokenKey); |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | // 如果不是第一次登录,会执行回调 |
| | | if (data) { |
| | | // 登录成功,自动记录token和用户信息,并返回true |
| | | } else { |
| | | // 出现错误,返回false |
| | | } |
| | | }); |
| | | } else { |
| | | if (token) { |
| | | const item = e.currentTarget.dataset.item; |
| | | const parent = e.currentTarget.dataset.parent; |
| | | let url; |
| | |
| | | ) { |
| | | return wx.showToast({ |
| | | icon: "error", |
| | | title: "请先购买该资源", |
| | | title: item.saleMethod[0].Price > 0 ? |
| | | "请先购买该资源" : "请先点击领取查看按钮", |
| | | }); |
| | | } |
| | | 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}`, |
| | | 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}&formPath=${this.properties.tab}`, |
| | | }); |
| | | if (item.selectType == "document" || item.selectType == "pdf") { |
| | | const fileLink = |
| | |
| | | ids.push(item.id); |
| | | checked = item.checked; |
| | | }); |
| | | const flag = |
| | | list.findIndex((item) => item.checked == false) > -1 ? true : false; |
| | | // const flag = |
| | | // list.findIndex((item) => item.checked == false) > -1 ? true : false; |
| | | const flag = this.properties.checkAllState; |
| | | // const updataList = this.findAndUpdateItemsByIds( |
| | | // this.properties.treeList, |
| | | // ids, |
| | | // flag |
| | | // ); |
| | | // this.setData({ |
| | | // treeList: updataList, |
| | | // }); |
| | | |
| | | var myEventDetail = { |
| | | value: flag, |
| | | ids, |
| | | flag, |
| | | }; // detail对象,提供给事件监听函数 |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; // 触发事件的选项 |
| | | this.triggerEvent("changeListChecked", myEventDetail, myEventOption); |
| | | |
| | | if (!checked) { |
| | | this.setData({ |
| | | selectAll: list, |
| | | }); |
| | | } |
| | | var myEventDetail = { |
| | | value: !flag, |
| | | }; // detail对象,提供给事件监听函数 |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; // 触发事件的选项 |
| | | this.triggerEvent("changeCheckAll", myEventDetail, myEventOption); |
| | | const updataList = this.findAndUpdateItemsByIds( |
| | | this.properties.treeList, |
| | | ids, |
| | | flag |
| | | ); |
| | | console.log(checked, "list"); |
| | | if (!checked) { |
| | | this.setData({ |
| | | selectAll: list, |
| | | }); |
| | | } |
| | | this.setData({ |
| | | treeList: updataList, |
| | | }); |
| | | }, |
| | | |
| | | // 章节勾选 |
| | |
| | | // 这个时候checked的值是fals |
| | | let checkResourceTitleList = []; |
| | | const item = e.currentTarget.dataset.item; |
| | | // |
| | | const parent = this.findParentById(this.properties.learnList, item.id) |
| | | let childrenList |
| | | let flagNum |
| | | if (parent) childrenList = parent.children.filter(citem => citem.id !== item.id) |
| | | if (childrenList) flagNum = childrenList.findIndex(item => item.checked == false) |
| | | let list = this.flattenTree([item]); |
| | | let ids = []; |
| | | list.forEach((item) => { |
| | | ids.push(item.id); |
| | | if (item.sysType == 'CmsFolder' || (item.sysType == 'CmsItem' && item.saleMethod.length)) |
| | | ids.push(item.id); |
| | | }); |
| | | const updatedTreeList = this.findAndUpdateItemsByIds( |
| | | this.properties.treeList, |
| | | var myEventDetail = { |
| | | ids, |
| | | flag |
| | | ); |
| | | this.setData({ |
| | | treeList: updatedTreeList, // 更新 treeList 数据 |
| | | }); |
| | | console.log(list, "list.checked"); |
| | | flag, |
| | | }; // detail对象,提供给事件监听函数 |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; // 触发事件的选项 |
| | | this.triggerEvent("changeListChecked", myEventDetail, myEventOption); |
| | | if (flagNum == -1) { |
| | | let checkedState |
| | | var myEventDetail = { |
| | | ids: [parent.id], |
| | | flag, |
| | | }; // detail对象,提供给事件监听函数 |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; // 触发事件的选项 |
| | | this.triggerEvent("changeListChecked", myEventDetail, myEventOption); |
| | | } |
| | | if (!list.checked) { |
| | | this.setData({ |
| | | superiorPurchaseSaleMethodId: list, |
| | | }); |
| | | } |
| | | // console.log(this.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId'); |
| | | list.forEach((items) => { |
| | | console.log(items.checked, "itesasd"); |
| | | if (!items.checked) { |
| | |
| | | // 子项勾选 |
| | | checkResource(e) { |
| | | const citem = e.currentTarget.dataset.item; |
| | | console.log(citem, "5648"); |
| | | const updataList = this.checkResoucrceInfo( |
| | | this.properties.treeList, |
| | | citem.id |
| | | ); |
| | | console.log(citem.checked, "citem.checked"); |
| | | const parent = e.currentTarget.dataset.parent |
| | | let outermost |
| | | if (parent) outermost = this.findParentById(this.properties.learnList, parent.id) |
| | | const childrenList = parent.children.filter(item => item.id !== citem.id && item.saleMethod.length) |
| | | const flag = childrenList.findIndex(item => item.checked == false) |
| | | // 改变该项checked |
| | | var myEventDetail = { |
| | | id: citem.id |
| | | }; |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; |
| | | this.triggerEvent("changeResourceChecked", myEventDetail, myEventOption); |
| | | // 通过判断,联通父级checked |
| | | if (flag == -1) { |
| | | let checkedState |
| | | citem.checked == false ? checkedState = true : checkedState = false |
| | | var myEventDetail = { |
| | | ids: [parent.id], |
| | | flag: checkedState, |
| | | }; |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; |
| | | this.triggerEvent("changeListChecked", myEventDetail, myEventOption); |
| | | } |
| | | // 联通最外层级checked ,如果有一个取消勾选,且当前最外层勾选,则取消最外层的勾选 |
| | | if (citem.checked && outermost && outermost.checked) { |
| | | var myEventDetail = { |
| | | ids: [outermost.id], |
| | | flag: false, |
| | | }; |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; |
| | | this.triggerEvent("changeListChecked", myEventDetail, myEventOption); |
| | | } |
| | | // 联通最外层级checked, 如果所有子项勾选, 且当前最外层未勾选, 则加上最外层的勾选 |
| | | if (!citem.checked && outermost) { |
| | | let allchildren = this.flattenTree([outermost]) |
| | | allchildren = allchildren.filter(item => item.sysType == 'CmsItem' && item.id !== citem.id && item.saleMethod.length) |
| | | const satate = allchildren.findIndex(item => item.checked == false) |
| | | if (satate == -1) { |
| | | var myEventDetail = { |
| | | ids: [outermost.id], |
| | | flag: true, |
| | | }; |
| | | var myEventOption = { |
| | | bubbles: true, |
| | | composed: true, |
| | | }; |
| | | this.triggerEvent("changeListChecked", myEventDetail, myEventOption); |
| | | } |
| | | } |
| | | if (!citem.checked) { |
| | | //选中的时候添加id |
| | | let sonPurchaseSaleMethodId = this.data.sonPurchaseSaleMethodId || []; |
| | | console.log(this.properties.paymentPage, "this.properties.paymentPage"); |
| | | if (this.properties.paymentPage) { |
| | | console.log(789987); |
| | | sonPurchaseSaleMethodId = []; |
| | | this.properties.paymentPage = false; |
| | | } |
| | |
| | | this.setData({ |
| | | sonPurchaseSaleMethodId: sonPurchaseSaleMethodId, |
| | | }); |
| | | console.log(this.data.sonPurchaseSaleMethodId); |
| | | } else { |
| | | // 取消选中的时候删除id |
| | | } |
| | | this.setData({ |
| | | treeList: updataList, |
| | | }); |
| | | }, |
| | | // 加入购物车 |
| | | async onCloudShoppingCart(e) { |
| | | let shoppingCartGetId = []; |
| | | |
| | | const item = e.currentTarget.dataset.item |
| | | console.log(item.isShopCar); |
| | | const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id; |
| | | console.log(saleMethodId); |
| | | let query = { |
| | |
| | | }; |
| | | const addRes = await app.MG.store.addShoppingCart(query); |
| | | console.log(addRes, "addRes"); |
| | | wx.showToast({ |
| | | icon: "success", |
| | | title: "添加成功", |
| | | }); |
| | | if (addRes) { |
| | | wx.showToast({ |
| | | icon: "success", |
| | | title: "添加成功", |
| | | }); |
| | | item.isShopCar = false |
| | | this.triggerEvent("updateCloudLearning") |
| | | } |
| | | |
| | | } |
| | | }, |
| | | sadd() { |
| | | this.triggerEvent('updateShoppingCartHidden'); |
| | | this.triggerEvent('updateCloudLearning'); |
| | | console.log(789); |
| | | this.triggerEvent("updateShoppingCartHidden"); |
| | | this.triggerEvent("updateCloudLearning"); |
| | | }, |
| | | findParentById(arr, id) { |
| | | for (let i = 0; i < arr.length; i++) { |
| | | const item = arr[i]; |
| | | // 检查当前项是否匹配(即它是不是我们要找的项) |
| | | if (item.id === id) { |
| | | // 如果当前项就是我们要找的项,则它没有父级,返回 null |
| | | return null; |
| | | } |
| | | // 递归查找当前项的子项 |
| | | const child = this.findChildById(item.children, id); |
| | | if (child) { |
| | | // 如果在子项中找到匹配的项,返回当前项作为父级 |
| | | return item; |
| | | } |
| | | } |
| | | // 如果没有找到匹配的父项,返回 null |
| | | return null; |
| | | }, |
| | | |
| | | // 辅助函数,用于递归查找子项 |
| | | findChildById(children, id) { |
| | | if (!children) { |
| | | return null; |
| | | } |
| | | for (let i = 0; i < children.length; i++) { |
| | | const child = children[i]; |
| | | if (child.id === id) { |
| | | // 如果找到匹配的项,返回它 |
| | | return child; |
| | | } |
| | | // 递归检查子项的子项 |
| | | const subChild = this.findChildById(child.children, id); |
| | | if (subChild) { |
| | | return subChild; |
| | | } |
| | | } |
| | | // 如果没有找到匹配的项,返回 null |
| | | return null; |
| | | } |
| | | }, |
| | | |
| | | |
| | | catchtap() {} |
| | | }) |
| | | }); |