From 04c7b0163caeae4ab1c5da62e301fa993101cfad Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期一, 31 三月 2025 10:40:45 +0800 Subject: [PATCH] bug修改 --- packageBookService/pages/bookServices/detail/components/tree/index.js | 480 +++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 299 insertions(+), 181 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js index c4f9ab8..d7151ef 100644 --- a/packageBookService/pages/bookServices/detail/components/tree/index.js +++ b/packageBookService/pages/bookServices/detail/components/tree/index.js @@ -4,10 +4,12 @@ } from "../../../../../../assets/js/login"; const app = getApp(); Component({ - // checked: false, - properties: { treeList: { + type: Array, + value: [], + }, + learnList: { type: Array, value: [], }, @@ -46,28 +48,31 @@ checkAllState: { type: Boolean, }, + deadline: { + type: String, + }, + cloundMenuIsBuy: { + type: Boolean + }, + learnMenu: { + type: Object + }, + isCloundHaveSaleMethod: { + type: Boolean + } }, data: { - sonPurchaseSaleMethodId: "", - superiorPurchaseSaleMethodId: [], activeValues: [1, 2], webpageSrc: "", cloudShoppingCart: [], - selectAll: [], shoppingCart: true, stop: false, + cart: true, + canExecute: true, + purchaseList: [] }, ready() {}, - - onLoad() { - this.setData({ - sonPurchaseSaleMethodId: [], - }); - console.log( - this.data.sonPurchaseSaleMethodId, - "sonPurchaseSaleMethodId789" - ); - }, + onLoad() {}, observers: { treeList: function (newValue) { const list = []; @@ -90,6 +95,20 @@ this.handleList(item.children); } } + }, + // 閬嶅巻鏍戠粨鏋勮浆鎹负鏁扮粍鏂规硶 + handleTreeData(array) { + const flattenedArray = []; + array.forEach((node) => { + // 灏嗗綋鍓嶈妭鐐规坊鍔犲埌灞曞紑鐨勬暟缁勪腑 + flattenedArray.push(node); + // 閫掑綊澶勭悊瀛愯妭鐐� + if (node.children && node.children.length > 0) { + const childrenArray = this.handleTreeData(node.children); + flattenedArray.push(...childrenArray); + } + }); + return flattenedArray; }, // 鑺傜偣灞曞紑 handleChange(e) { @@ -120,11 +139,25 @@ // 鍒ゆ柇璧勬簮鏄惁璐拱 resourceIsBuy(data) { if (data.saleMethod && data.saleMethod.length) { - if (data.saleMethod[0].State == "Disable") return false; + const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal') + if (saleData.State == 'Disable') return false const isSHow = this.properties.buyIds.some( - (item) => item == data.saleMethod[0].Id + (item) => item == saleData.Id ); - return !isSHow; + // 宸茬粡璐拱 + if (isShow) return false + // 鏈喘涔帮紝鏌ョ湅閿�鍞柟寮忔槸鍚﹁繃鏈� + if (!isShow) { + const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() && + new Date(saleData.BeginDate).getTime() <= new Date().getTime() + if (flag) { + // 涓鸿繃鏈� 锛岄渶瑕佽喘涔� + return true + } else { + // 宸茶繃鏈� 鏃犻渶璐拱 + return false + } + } } else { return false; } @@ -132,85 +165,109 @@ // 璺宠浆闊宠棰戞挱鏀惧櫒 goPlayer(e) { // 妫�鏌ョ櫥褰曠姸鎬� - const token = wx.getStorageSync(app.config.tokenKey); - if (!token) { - loginInfo(app, (data) => { - // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� - if (data) { - // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue - } else { - // 鍑虹幇閿欒锛岃繑鍥瀎alse - } - }); - } else { + const goPlayerFun = () => { const item = e.currentTarget.dataset.item; const parent = e.currentTarget.dataset.parent; - let url; - if (this.properties.isShowCheck && this.resourceIsBuy(item)) { - return false; + const parentProductLinkPath = parent ? + parent.productLinkPath : + wx.getStorageSync("teachResourcesPath"); + const parentName = parent ? parent.name : "鏁欏璧勬簮"; + // 璧勬簮璐拱椤甸潰(鍙睍绀烘湭璐拱璧勬簮) 鐐瑰嚮涓嶈烦杞� + if (this.properties.isShowCheck) return false; + if (item.selectType == "webpage" || item.learnSelectType == "webpage") { + // 缃戦〉绫诲瀷璺宠浆鍒扮綉鍧�澶嶅埗椤碉紝鍥犱负url浼犲弬涓嶈兘浼� 甯﹀弬鏁扮殑缃戠粶鍦板潃锛屾墍浠ユ澶勮鎶婄綉缁滃湴鍧�閲岀殑浼犲弬鎽樺嚭鏉ワ紝鏀惧埌url閲� + let urlData = '' + const flags = item.jsek_link.indexOf("?") + if (flags > -1) { + urlData = item.jsek_link.slice(flags + 1, item.jsek_link.length) + } + url = '/packageBookService/pages/bookServices/linkPage/index' + return wx.navigateTo({ + url: urlData ? url + `?path=${item.jsek_link.slice(0,flags)}` + '&' + urlData : url + `?path=${item.jsek_link}` + }) } + if (!item.file && !item.freeFile && !item.protectedFile) { + return wx.showToast({ + icon: 'error', + title: '鏆傛棤璧勬簮', + }) + } + if (item.selectType == 'zip' || item.learnSelectType == 'zip') { + return wx.showToast({ + icon: 'error', + title: '璇峰墠寰�PC绔笅杞�', + }) + } + if (this.properties.tab == "jsek_teachingResources" && (item.file || item.freeFile)) { + let file = item.fileMap[item.file] ? item.fileMap[item.file] : item.fileMap[item.freeFile] + if (file && file.protectType !== "Public") { + return wx.showToast({ + icon: "none", + title: "璧勬簮涓嶅彲鐢紝璇疯仈绯荤鐞嗗憳", + }); + } + } + if (this.properties.tab == "jsek_cloudLearning") { + // 1.鎵惧嚭鎵�鏈夌埗绾х洰褰曞拰鏈韩(鏈夐攢鍞柟寮�) 鍜� 浜戝涔犳湰韬�(鏈夐攢鍞柟寮�) 鏀惧埌涓�涓暟缁� 涓虹┖鍒欐殏鏈紑鏀鹃攢鍞� + let learn = [] + if (this.properties.isCloundHaveSaleMethod) { + // 1.1 浜戝涔犳湁閿�鍞柟寮忥紝鍔犲叆鐖剁骇鏁扮粍 + learn.push(this.properties.learnMenu) + } else { + // 1.2 浜戝涔犳棤閿�鍞柟寮忥紝灏嗙埗绾х洰褰曞拰鏈韩鍔犲叆鏁扮粍 + learn = this.handleTreeData(this.properties.learnList).filter( + (citem) => citem.saleMethod && + citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal' && ditem.Price > 0) && + new Date(citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal').EndDate).getTime() >= new Date().getTime() && + new Date(citem.saleMethod.find((ditem) => ditem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime() && + item.productLinkPath.includes(citem.productLinkPath) + ) + } + // 2.鎵惧嚭杩欎釜鏁扮粍閲屽凡璐拱鐨� 褰㈡垚鏂版暟缁� 涓虹┖鍒欐湭璐拱 + let buyList = [] + if (learn.length) buyList = learn.filter((item) => this.properties.buyIds.includes(item.saleMethod.find((citem) => citem.SaleType == 'Normal').Id)) + // 鏈夌埗绾�(鍖呭惈閿�鍞柟寮�)锛屼笖鏈喘涔� + if (learn.length && !buyList.length && !item.freeFile) return wx.showToast({ + icon: 'error', + title: '璇峰厛璐拱璇ヨ祫婧�', + }) + if (item.protectedFile || item.freeFile) { + let file = item.fileMap[item.protectedFile] ? item.fileMap[item.protectedFile] : item.fileMap[item.freeFile] + if (file && file.protectType !== "Public") { + return wx.showToast({ + icon: 'none', + title: "璧勬簮涓嶅彲鐢紝璇疯仈绯荤鐞嗗憳", + }); + } + } + } + let url; if (item.selectType == "video" || item.learnSelectType == "video") { url = "/packageDomain/pages/resourceDetails/myVideo/index"; - } else if ( + } + if ( item.selectType == "audio" || item.learnSelectType == "audio" ) { url = "/packageDomain/pages/resourceDetails/myAudio/index"; - } else if (item.selectType == "picture" || item.selectType == "zip") { + } + if (item.selectType == "picture" || item.selectType == 'document' || item.selectType == 'pdf' || item.learnSelectType == "picture" || item.learnSelectType == 'document' || item.learnSelectType == 'pdf') { url = "/packageDomain/pages/resourceDetails/document/index"; } - if ( - this.properties.tab == "jsek_cloudLearning" && - this.resourceIsBuy(item) - ) { - return wx.showToast({ - icon: "error", - 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=${parentProductLinkPath}&parentName=${parentName}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}&formPath=${this.properties.tab}&applyState=${this.properties.applyState}&deadline=${this.properties.deadline}`, }); - if (item.selectType == "document" || item.selectType == "pdf") { - const fileLink = - app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file; - console.log(fileLink, "fileLink"); - //鎻愮ず鍔犺浇涓� - util.showLoading(); - // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB - wx.downloadFile({ - url: fileLink, // 鍦板潃宸叉墦鐮侊紝鑷繁鎹釜鍏朵粬鐨勫湴鍧�锛�"https://www.xxxxx.com/file/娴嬭瘯閫氱煡.pdf"锛� - success: function (res) { - console.log(res, "wx.downloadFile success res"); - if (res.statusCode != 200) { - util.hideLoadingWithErrorTips(); - return false; - } - var Path = res.tempFilePath; //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢� - wx.openDocument({ - filePath: Path, - showMenu: true, - success: function (res) { - console.log("鎵撳紑鎴愬姛"); - util.hideLoading(); - }, - }); - }, - fail: function (err) { - console.log(err, "wx.downloadFile fail err"); - util.hideLoadingWithErrorTips(); - }, - }); - } - if (item.selectType == "webpage") { - this.setData({ - webpageSrc: item.jsek_link, - }); - console.log(this.data.webpageSrc, "webpageSrc"); - } + } + const token = wx.getStorageSync(app.config.tokenKey); + if (!token && this.data.tab != 'jsek_teachingResources') { + loginInfo(app, (data) => { + if (data) {} + }) + } else { + goPlayerFun() } }, + // 鎷垮埌鎵�鏈夐」 getAllChildren(id) { let result = []; @@ -233,7 +290,6 @@ result.push(...item.children); } } - console.log(this.properties.treeList, "this.properties.treeList"); this.properties.treeList.forEach((item) => { findChildren(item); }); @@ -254,7 +310,6 @@ tree.forEach((node) => { flatten(node); }); - // console.log(result, 'result'); return result; }, @@ -262,7 +317,6 @@ findAndUpdateItemsByIds(tree, ids, state) { function findAndUpdate(node) { if (ids.includes(node.id)) { - // console.log(node, 'node'); node.checked = state; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true } if (node.children && node.children.length > 0) { @@ -274,57 +328,35 @@ 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() { + wx.showLoading() const ids = []; - const list = []; + let list = []; let checked = ""; this.properties.treeList.forEach((item) => { if (item.children && item.children.length > 0) { list.push(...this.flattenTree([item])); } }); + list = list.filter(item => !item.disabled) list.forEach((item) => { ids.push(item.id); checked = item.checked; }); - // const flag = - // list.findIndex((item) => item.checked == false) > -1 ? true : false; const flag = this.properties.checkAllState; - const updataList = this.findAndUpdateItemsByIds( - this.properties.treeList, + var myEventDetail = { ids, - flag - ); - console.log(checked, "list"); - if (!checked) { - this.setData({ - selectAll: list, - }); - } - this.setData({ - treeList: updataList, - }); + flag, + }; + var myEventOption = { + bubbles: true, + composed: true, + }; + this.triggerEvent("changeListChecked", myEventDetail, myEventOption); var myEventDetail = { value: !flag, }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 @@ -333,37 +365,51 @@ composed: true, }; // 瑙﹀彂浜嬩欢鐨勯�夐」 this.triggerEvent("changeCheckAll", myEventDetail, myEventOption); + wx.hideLoading() }, // 绔犺妭鍕鹃�� checkResourceTitle(e) { + wx.showLoading() const flag = e.detail.checked; // 杩欎釜鏃跺�檆hecked鐨勫�兼槸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); + flagNum = childrenList.findIndex((item) => item.checked == false); let list = this.flattenTree([item]); + list = list.filter(item => !item.disabled) let ids = []; list.forEach((item) => { - ids.push(item.id); + 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"); - if (!list.checked) { - this.setData({ - superiorPurchaseSaleMethodId: list, - }); + flag, + }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 + var myEventOption = { + bubbles: true, + composed: true, + }; // 瑙﹀彂浜嬩欢鐨勯�夐」 + // 鍘诲嬀閫夌偣鍑荤洰褰曠殑瀛愰」 + this.triggerEvent("changeListChecked", myEventDetail, myEventOption); + // 鍘诲嬀閫夌偣鍑荤洰褰曠殑鐖堕」 + if (flagNum == -1 && parent && !parent.disabled) { + let checkedState; + var myEventDetail = { + ids: [parent.id], + flag, + }; + var myEventOption = { + bubbles: true, + composed: true, + }; + this.triggerEvent("changeListChecked", myEventDetail, myEventOption); } - // console.log(this.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId'); list.forEach((items) => { - console.log(items.checked, "itesasd"); if (!items.checked) { this.setData({ cloudShoppingCart: items, @@ -376,65 +422,92 @@ }, // 瀛愰」鍕鹃�� checkResource(e) { + wx.showLoading() const citem = e.currentTarget.dataset.item; - const parent = e.currentTarget.dataset.parent - const childrenList = parent.children.filter(item => item.id !== citem.id) - const flag = childrenList.findIndex(item => item.checked == false) - const updataList = this.checkResoucrceInfo( - this.properties.treeList, - citem.id + 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 ); - if (flag == -1) { - if (citem.checked == false) { - this.findAndUpdateItemsByIds(this.properties.treeList, [parent.id], true) - } else { - this.findAndUpdateItemsByIds(this.properties.treeList, [parent.id], false) + 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); + // 閫氳繃鍒ゆ柇,鑱旈�氱埗绾hecked + if (flag == -1 && !parent.disabled) { + 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); + } + // 鑱旈�氭渶澶栧眰绾hecked ,濡傛灉鏈変竴涓彇娑堝嬀閫�,涓斿綋鍓嶆渶澶栧眰鍕鹃��,鍒欏彇娑堟渶澶栧眰鐨勫嬀閫� + if (citem.checked && outermost && outermost.checked) { + var myEventDetail = { + ids: [outermost.id], + flag: false, + }; + var myEventOption = { + bubbles: true, + composed: true, + }; + this.triggerEvent("changeListChecked", myEventDetail, myEventOption); + } + // 鑱旈�氭渶澶栧眰绾hecked, 濡傛灉鎵�鏈夊瓙椤瑰嬀閫�, 涓斿綋鍓嶆渶澶栧眰鏈嬀閫�, 鍒欏姞涓婃渶澶栧眰鐨勫嬀閫� + if (!citem.checked && outermost && !outermost.disabled) { + 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) { - //閫変腑鐨勬椂鍊欐坊鍔爄d - let sonPurchaseSaleMethodId = this.data.sonPurchaseSaleMethodId || []; - if (this.properties.paymentPage) { - sonPurchaseSaleMethodId = []; - this.properties.paymentPage = false; - } - if (!this.properties.paymentPage) { - sonPurchaseSaleMethodId.push(citem.saleMethod[0].Id); - } - this.setData({ - sonPurchaseSaleMethodId: sonPurchaseSaleMethodId, - }); - console.log(this.data.sonPurchaseSaleMethodId); - } else { - // 鍙栨秷閫変腑鐨勬椂鍊欏垹闄d - } - this.setData({ - treeList: updataList, - }); }, // 鍔犲叆璐墿杞� async onCloudShoppingCart(e) { let shoppingCartGetId = []; + const item = e.currentTarget.dataset.item; const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id; - console.log(saleMethodId); let query = { start: 0, size: 999, filterList: [], searchList: [], }; - const res = await app.MG.store.getShoppingCartProductList(query); res.datas.forEach((item) => { shoppingCartGetId.push(item.saleMethod.id); }); if (shoppingCartGetId.includes(saleMethodId)) { - console.log(111); - // this.data.updateShoppingCartHidden(); - // this.data.updateCloudLearning(); - wx.showToast({ - icon: "error", + icon: "success", title: "宸叉坊鍔�", }); this.setData({ @@ -449,19 +522,64 @@ }, ], }; 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; + var myEventDetail = { + id: item.id, + }; + var myEventOption = { + bubbles: true, + composed: true, + }; + this.triggerEvent("updateCloudLearning", myEventDetail, myEventOption); + } } }, sadd() { this.triggerEvent("updateShoppingCartHidden"); this.triggerEvent("updateCloudLearning"); - console.log(789); + }, + 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() {}, }); \ No newline at end of file -- Gitblit v1.9.1