From 338ad19ee45b5380a0d8433cbbce2a727a576dfa Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期五, 19 四月 2024 17:34:36 +0800 Subject: [PATCH] bug2 --- packageBookService/pages/bookServices/detail/components/tree/index.js | 333 +++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 260 insertions(+), 73 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js index d946ea5..77b7035 100644 --- a/packageBookService/pages/bookServices/detail/components/tree/index.js +++ b/packageBookService/pages/bookServices/detail/components/tree/index.js @@ -1,13 +1,17 @@ const util = require("./components/util"); // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず -import { loginInfo } from "../../../../../../assets/js/login"; +import { + loginInfo +} from "../../../../../../assets/js/login"; const app = getApp(); Component({ - // checked: false, - properties: { treeList: { type: Array, value: [], + }, + learnList: { + type: Array, + value: [] }, bookInfo: { type: Object, @@ -54,6 +58,7 @@ selectAll: [], shoppingCart: true, stop: false, + cart: true }, ready() {}, @@ -61,10 +66,6 @@ this.setData({ sonPurchaseSaleMethodId: [], }); - console.log( - this.data.sonPurchaseSaleMethodId, - "sonPurchaseSaleMethodId789" - ); }, observers: { treeList: function (newValue) { @@ -83,8 +84,7 @@ handleList(tree) { for (let index = 0; index < tree.length; index++) { const item = tree[index]; - if (item.sysType == "CmsItem" && !item.checked) { - } + if (item.sysType == "CmsItem" && !item.checked) {} if (item.children && item.children.length > 0) { this.handleList(item.children); } @@ -132,18 +132,12 @@ goPlayer(e) { // 妫�鏌ョ櫥褰曠姸鎬� const token = wx.getStorageSync(app.config.tokenKey); - if (!token) { - loginInfo(app, (data) => { - // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� - if (data) { - // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue - } else { - // 鍑虹幇閿欒锛岃繑鍥瀎alse - } - }); - } else { + + if (token) { const item = e.currentTarget.dataset.item; const parent = e.currentTarget.dataset.parent; + const parentProductLinkPath = parent ? parent.productLinkPath : wx.getStorageSync('teachResourcesPath') + const parentName = parent ? parent.name : '鏁欏璧勬簮' let url; if (this.properties.isShowCheck && this.resourceIsBuy(item)) { return false; @@ -164,24 +158,26 @@ ) { return wx.showToast({ icon: "error", - title: - item.saleMethod[0].Price > 0 - ? "璇峰厛璐拱璇ヨ祫婧�" - : "璇峰厛鐐瑰嚮棰嗗彇鏌ョ湅鎸夐挳", + 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}`, }); + + if (item.selectType == "document" || item.selectType == "pdf") { - const fileLink = - app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file; + console.log(item, 'item789'); + // freeFile + 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"); //鎻愮ず鍔犺浇涓� util.showLoading(); // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB wx.downloadFile({ - url: fileLink, // 鍦板潃宸叉墦鐮侊紝鑷繁鎹釜鍏朵粬鐨勫湴鍧�锛�"https://www.xxxxx.com/file/娴嬭瘯閫氱煡.pdf"锛� + url: fileLink, success: function (res) { console.log(res, "wx.downloadFile success res"); if (res.statusCode != 200) { @@ -204,6 +200,84 @@ }, }); } + + + + + + + + + + + + + + + + + + + + + + + + // if (item.selectType == "document" || item.selectType == "pdf") { + // const fileLink = app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file; + + // let filePath = wx.env.USER_DATA_PATH + '/' + item.name + // console.log(filePath, 'filePath'); + // //鎻愮ず鍔犺浇涓� + // util.showLoading(); + // // 鍗曟涓嬭浇鍏佽鐨勬渶澶ф枃浠朵负 200MB + // wx.downloadFile({ + // url: fileLink, + // success: function (res) { + + // if (res.statusCode != 200) { + // util.hideLoadingWithErrorTips(); + // return false; + // } + // var Path = res.tempFilePath; //杩斿洖鐨勬枃浠朵复鏃跺湴鍧�锛岀敤浜庡悗闈㈡墦寮�鏈湴棰勮鎵�鐢� + + // wx.saveFile({ + // tempFilePath: Path, + // success: function (res) { + // var savedFilePath = res.savedFilePath; + // // 灏嗘枃浠朵繚瀛樹负 item.name + // wx.saveFile({ + // tempFilePath: savedFilePath, + // filePath: wx.env.USER_DATA_PATH + '/' + item.name, + // success: function (res) { + // wx.openDocument({ + // filePath: res.savedFilePath, + // showMenu: true, + // success: function (res) { + // util.hideLoading(); + // }, + // }); + // }, + // fail: function (err) { + // util.hideLoadingWithErrorTips(); + // } + // }); + // }, + // fail: function (err) { + // util.hideLoadingWithErrorTips(); + // } + // }); + // }, + // fail: function (err) { + // util.hideLoadingWithErrorTips(); + // }, + // }); + // } + + + + + if (item.selectType == "webpage") { this.setData({ webpageSrc: item.jsek_link, @@ -212,6 +286,7 @@ } } }, + // 鎷垮埌鎵�鏈夐」 getAllChildren(id) { let result = []; @@ -312,20 +387,30 @@ // const flag = // list.findIndex((item) => item.checked == false) > -1 ? true : false; const flag = this.properties.checkAllState; - const updataList = this.findAndUpdateItemsByIds( - this.properties.treeList, + // const updataList = this.findAndUpdateItemsByIds( + // this.properties.treeList, + // ids, + // flag + // ); + // this.setData({ + // treeList: updataList, + // }); + + var myEventDetail = { ids, - flag - ); - console.log(checked, "list"); + flag, + }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 + var myEventOption = { + bubbles: true, + composed: true, + }; // 瑙﹀彂浜嬩欢鐨勯�夐」 + this.triggerEvent("changeListChecked", myEventDetail, myEventOption); + if (!checked) { this.setData({ selectAll: list, }); } - this.setData({ - treeList: updataList, - }); var myEventDetail = { value: !flag, }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 @@ -342,27 +427,43 @@ // 杩欎釜鏃跺�檆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) + 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) { @@ -378,18 +479,67 @@ // 瀛愰」鍕鹃�� 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); + // 閫氳繃鍒ゆ柇,鑱旈�氱埗绾hecked + 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); + } + // 鑱旈�氭渶澶栧眰绾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) { + 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 || []; - console.log(this.properties.paymentPage, "this.properties.paymentPage"); if (this.properties.paymentPage) { - console.log(789987); sonPurchaseSaleMethodId = []; this.properties.paymentPage = false; } @@ -399,17 +549,16 @@ 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 + console.log(item.isShopCar); const saleMethodId = e.currentTarget.dataset.item.saleMethod[0].Id; console.log(saleMethodId); let query = { @@ -437,28 +586,66 @@ }); } else { let query = { - requests: [ - { - saleMethodId: saleMethodId, - storeEventId: null, - // agentCode: '鐢靛瓙涔�' - }, - ], + requests: [{ + saleMethodId: saleMethodId, + storeEventId: null, + // agentCode: '鐢靛瓙涔�' + }, ], }; 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); }, - }, + 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; + }, - catchtap() {}, -}); + // 杈呭姪鍑芥暟锛岀敤浜庨�掑綊鏌ユ壘瀛愰」 + 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; + } + }, +}); \ No newline at end of file -- Gitblit v1.9.1