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 | 361 ++++++++++++++++++++------------------------------ 1 files changed, 146 insertions(+), 215 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js index 332d2d4..d7151ef 100644 --- a/packageBookService/pages/bookServices/detail/components/tree/index.js +++ b/packageBookService/pages/bookServices/detail/components/tree/index.js @@ -51,26 +51,28 @@ 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 + canExecute: true, + purchaseList: [] }, ready() {}, - - onLoad() { - this.setData({ - sonPurchaseSaleMethodId: [], - }); - }, + onLoad() {}, observers: { treeList: function (newValue) { const list = []; @@ -94,9 +96,22 @@ } } }, + // 閬嶅巻鏍戠粨鏋勮浆鎹负鏁扮粍鏂规硶 + 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) { - console.log(e.detail.value); this.setData({ openIds: e.detail.value, }); @@ -124,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; } @@ -136,17 +165,16 @@ // 璺宠浆闊宠棰戞挱鏀惧櫒 goPlayer(e) { // 妫�鏌ョ櫥褰曠姸鎬� - const token = wx.getStorageSync(app.config.tokenKey); - if (token) { + const goPlayerFun = () => { const item = e.currentTarget.dataset.item; const parent = e.currentTarget.dataset.parent; - console.log('item', item); const parentProductLinkPath = parent ? parent.productLinkPath : wx.getStorageSync("teachResourcesPath"); const parentName = parent ? parent.name : "鏁欏璧勬簮"; - let url; - if (item.selectType == "webpage") { + // 璧勬簮璐拱椤甸潰(鍙睍绀烘湭璐拱璧勬簮) 鐐瑰嚮涓嶈烦杞� + if (this.properties.isShowCheck) return false; + if (item.selectType == "webpage" || item.learnSelectType == "webpage") { // 缃戦〉绫诲瀷璺宠浆鍒扮綉鍧�澶嶅埗椤碉紝鍥犱负url浼犲弬涓嶈兘浼� 甯﹀弬鏁扮殑缃戠粶鍦板潃锛屾墍浠ユ澶勮鎶婄綉缁滃湴鍧�閲岀殑浼犲弬鎽樺嚭鏉ワ紝鏀惧埌url閲� let urlData = '' const flags = item.jsek_link.indexOf("?") @@ -157,128 +185,86 @@ return wx.navigateTo({ url: urlData ? url + `?path=${item.jsek_link.slice(0,flags)}` + '&' + urlData : url + `?path=${item.jsek_link}` }) - } else if (item.selectType == 'zip') { - if (this.properties.applyState == 'Normal') { - return wx.showToast({ - icon: 'error', - title: '璇峰墠寰�PC绔笅杞�', - }) - } else { - return wx.showToast({ - icon: 'error', - title: '璇峰厛鐢宠涓嬭浇', - }) - } } - if (this.properties.isShowCheck && this.resourceIsBuy(item)) { - return false; - } - if (item.selectType == "video" || item.learnSelectType == "video") { - url = "/packageDomain/pages/resourceDetails/myVideo/index"; - } else if ( - item.selectType == "audio" || - item.learnSelectType == "audio" - ) { - url = "/packageDomain/pages/resourceDetails/myAudio/index"; - } else if (item.selectType == "picture") { - url = "/packageDomain/pages/resourceDetails/document/index"; - } - if ( - this.properties.tab == "jsek_cloudLearning" && - this.resourceIsBuy(item) - // item.saleMethod.length > 0 - ) { - return wx.showToast({ - icon: "error", - title: item.saleMethod[0].Price > 0 ? - "璇峰厛璐拱璇ヨ祫婧�" : "璇峰厛鐐瑰嚮棰嗗彇鏌ョ湅鎸夐挳", - }); - } - // if ( - // item.saleMethod.length == 0 && - // item.sysType == "CmsItem" && - // this.properties.tab == "jsek_cloudLearning" - // ) { - // return wx.showToast({ - // icon: "error", - // title: "鏆傛湭寮�濮嬮攢鍞紝璇疯仈绯荤鐞嗗憳", - // }); - // } - 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: "error", - title: "璧勬簮涓嶅彲鐢紝璇疯仈绯荤鐞嗗憳", - }); - } - } else if ((this.properties.tab == "jsek_teachingResources" || this.properties.tab == "jsek_cloudLearning") && (!item.file && !item.freeFile && !item.protectedFile)) { + 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"; + } + if ( + item.selectType == "audio" || + item.learnSelectType == "audio" + ) { + url = "/packageDomain/pages/resourceDetails/myAudio/index"; + } + 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"; + } wx.navigateTo({ 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}`, }); - - // debugger - if (item.selectType == "pdf" || item.selectType == "document") { - const fileLink = item.file ? item.file : item.freeFile - console.log(fileLink); - wx.navigateTo({ - url: "/packageBookService/pages/components/webView/index?md5=" + - fileLink + - "&fileName=" + - item.name + - "&fileType=pdf" + "&bookBuy=true" - }); - } - // if (item.selectType == "document") { - // // freeFile - // // if (item.selectType == "document") { - // // item.selectType = "pptx"; - // // } - // const fileLink = item.file ? - // app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file : - // app.config.requestCtx + - // "/file/api/ApiDownload?md5=" + - // item.freeFile; - // console.log(fileLink, "fileLink"); - // //鎻愮ず鍔犺浇涓� - // // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB - // wx.downloadFile({ - // url: fileLink, - // // filePath: wx.env.USER_DATA_PATH + `/${item.name}.${item.selectType}`, - // filePath: wx.env.USER_DATA_PATH + `/${item.name}.${item.selectType}`, - // success: function (res) { - // console.log(res, "wx.downloadFile success res"); - // if (res.statusCode != 200) { - // util.hideLoadingWithErrorTips(); - // return false; - // } - // var Path = res.tempFilePath; //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢� - // let data = res.filePath; - // wx.openDocument({ - // filePath: data, - // 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, - // }); - // } + } + const token = wx.getStorageSync(app.config.tokenKey); + if (!token && this.data.tab != 'jsek_teachingResources') { + loginInfo(app, (data) => { + if (data) {} + }) + } else { + goPlayerFun() } }, @@ -304,7 +290,6 @@ result.push(...item.children); } } - console.log(this.properties.treeList, "this.properties.treeList"); this.properties.treeList.forEach((item) => { findChildren(item); }); @@ -325,7 +310,6 @@ tree.forEach((node) => { flatten(node); }); - // console.log(result, 'result'); return result; }, @@ -333,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) { @@ -348,63 +331,32 @@ 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, - // ids, - // flag - // ); - // this.setData({ - // treeList: updataList, - // }); - var myEventDetail = { 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瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 @@ -413,29 +365,26 @@ 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 childrenList = []; let flagNum; if (parent) childrenList = parent.children.filter((citem) => citem.id !== item.id); - if (childrenList) - flagNum = childrenList.findIndex((item) => item.checked == false); + flagNum = childrenList.findIndex((item) => item.checked == false); let list = this.flattenTree([item]); + list = list.filter(item => !item.disabled) let ids = []; list.forEach((item) => { - if ( - item.sysType == "CmsFolder" || - (item.sysType == "CmsItem" && item.saleMethod.length) - ) - ids.push(item.id); + ids.push(item.id) }); var myEventDetail = { ids, @@ -445,26 +394,22 @@ bubbles: true, composed: true, }; // 瑙﹀彂浜嬩欢鐨勯�夐」 + // 鍘诲嬀閫夌偣鍑荤洰褰曠殑瀛愰」 this.triggerEvent("changeListChecked", myEventDetail, myEventOption); - if (flagNum == -1) { + // 鍘诲嬀閫夌偣鍑荤洰褰曠殑鐖堕」 + if (flagNum == -1 && parent && !parent.disabled) { 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, - }); - } list.forEach((items) => { - console.log(items.checked, "itesasd"); if (!items.checked) { this.setData({ cloudShoppingCart: items, @@ -477,6 +422,7 @@ }, // 瀛愰」鍕鹃�� checkResource(e) { + wx.showLoading() const citem = e.currentTarget.dataset.item; const parent = e.currentTarget.dataset.parent; let outermost; @@ -496,7 +442,7 @@ }; this.triggerEvent("changeResourceChecked", myEventDetail, myEventOption); // 閫氳繃鍒ゆ柇,鑱旈�氱埗绾hecked - if (flag == -1) { + if (flag == -1 && !parent.disabled) { let checkedState; citem.checked == false ? (checkedState = true) : (checkedState = false); var myEventDetail = { @@ -522,7 +468,7 @@ this.triggerEvent("changeListChecked", myEventDetail, myEventOption); } // 鑱旈�氭渶澶栧眰绾hecked, 濡傛灉鎵�鏈夊瓙椤瑰嬀閫�, 涓斿綋鍓嶆渶澶栧眰鏈嬀閫�, 鍒欏姞涓婃渶澶栧眰鐨勫嬀閫� - if (!citem.checked && outermost) { + if (!citem.checked && outermost && !outermost.disabled) { let allchildren = this.flattenTree([outermost]); allchildren = allchildren.filter( (item) => @@ -543,31 +489,12 @@ 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, - }); - } else { - // 鍙栨秷閫変腑鐨勬椂鍊欏垹闄d - } }, // 鍔犲叆璐墿杞� 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 = { start: 0, size: 999, @@ -579,10 +506,8 @@ shoppingCartGetId.push(item.saleMethod.id); }); if (shoppingCartGetId.includes(saleMethodId)) { - // this.data.updateShoppingCartHidden(); - // this.data.updateCloudLearning(); wx.showToast({ - icon: "error", + icon: "success", title: "宸叉坊鍔�", }); this.setData({ @@ -597,14 +522,20 @@ }, ], }; const addRes = await app.MG.store.addShoppingCart(query); - console.log(addRes, "addRes"); if (addRes) { wx.showToast({ icon: "success", title: "娣诲姞鎴愬姛", }); item.isShopCar = false; - this.triggerEvent("updateCloudLearning"); + var myEventDetail = { + id: item.id, + }; + var myEventOption = { + bubbles: true, + composed: true, + }; + this.triggerEvent("updateCloudLearning", myEventDetail, myEventOption); } } }, -- Gitblit v1.9.1