From 3d73fb33c46aada16a6060adcd4ea14bb33b6b2a Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 09 四月 2024 10:39:11 +0800 Subject: [PATCH] 详情页tabs样式优化,答题添加页面退出拦截,合并代码 --- packageBookService/pages/bookServices/detail/components/tree/index.js | 495 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 353 insertions(+), 142 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js index 2cc493e..d946ea5 100644 --- a/packageBookService/pages/bookServices/detail/components/tree/index.js +++ b/packageBookService/pages/bookServices/detail/components/tree/index.js @@ -1,163 +1,231 @@ - -import Message from 'tdesign-miniprogram/message/message'; -const util = require('./components/util') // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず -const app = getApp() +const util = require("./components/util"); // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず +import { loginInfo } from "../../../../../../assets/js/login"; +const app = getApp(); Component({ + // checked: false, + properties: { treeList: { type: Array, - value: [] + value: [], }, bookInfo: { type: Object, - value: {} + value: {}, }, buyIds: { type: Array, - value: [] + value: [], }, tab: { type: String, - value: '' + value: "", }, applyState: { type: String, - value: '' + value: "", }, - openTeachids: { + openIds: { type: Array, - value: '' + value: [], }, - openLearnids: { - type: Array, - value: "" - } + isShowCheck: { + type: Boolean, + value: false, + }, + paymentPage: { + type: Boolean, + value: false, + }, + superior: { + type: Boolean, + value: false, + }, + checkAllState: { + type: Boolean, + }, }, data: { - activeValues: [0], - webpageSrc: '' + sonPurchaseSaleMethodId: "", + superiorPurchaseSaleMethodId: [], + activeValues: [1, 2], + webpageSrc: "", + cloudShoppingCart: [], + selectAll: [], + shoppingCart: true, + stop: false, }, - onShow() { + ready() {}, + onLoad() { + this.setData({ + sonPurchaseSaleMethodId: [], + }); + console.log( + this.data.sonPurchaseSaleMethodId, + "sonPurchaseSaleMethodId789" + ); }, - + observers: { + treeList: function (newValue) { + const list = []; + let checked = ""; + this.properties.treeList.forEach((item) => { + if (item.children && item.children.length > 0) { + list.push(...this.flattenTree([item])); + } + }); + const flag = list.findIndex((item) => item.checked == true); + }, + }, 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++) { const element = data[index]; - element.checked = true + element.checked = true; if (element.childrenCount && element.type == "productFolder") { - handleCheck(element.children) + handleCheck(element.children); } } }, downloadTeach(e) { - const value = e.currentTarget.dataset.value + const value = e.currentTarget.dataset.value; var myEventDetail = { value, - } // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 + }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 var myEventOption = { bubbles: true, - composed: true - } // 瑙﹀彂浜嬩欢鐨勯�夐」 - this.triggerEvent('downloadTeach', myEventDetail, myEventOption) - + composed: true, + }; // 瑙﹀彂浜嬩欢鐨勯�夐」 + this.triggerEvent("downloadTeach", myEventDetail, myEventOption); }, // 鍒ゆ柇璧勬簮鏄惁璐拱 resourceIsBuy(data) { if (data.saleMethod && data.saleMethod.length) { - const isSHow = buyIdList.value.some((item) => item == data.saleMethod[0].Id) - return !isSHow + 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 + return false; } }, // 璺宠浆闊宠棰戞挱鏀惧櫒 goPlayer(e) { - const item = e.currentTarget.dataset.item - const parent = e.currentTarget.dataset.parent - let url - if (item.selectType == 'video') { - url = '/packageDomain/pages/resourceDetails/myVideo/index' - } else if (item.selectType == 'audio') { - url = '/packageDomain/pages/resourceDetails/myAudio/index' - } else if (item.selectType == 'picture' || item.selectType == 'zip') { - url = '/packageDomain/pages/resourceDetails/document/index' - } - - // else { - // - // } - 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}`, - }) - - - 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() + // 妫�鏌ョ櫥褰曠姸鎬� + const token = wx.getStorageSync(app.config.tokenKey); + if (!token) { + loginInfo(app, (data) => { + // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� + if (data) { + // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue + } else { + // 鍑虹幇閿欒锛岃繑鍥瀎alse } - }) - - + }); + } else { + const item = e.currentTarget.dataset.item; + const parent = e.currentTarget.dataset.parent; + let url; + 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" || item.selectType == "zip") { + 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}`, + }); + 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"); + } } - - if (item.selectType == 'webpage') { - console.log(11); - this.setData({ - webpageSrc: item.jsek_link - }) - console.log(this.data.webpageSrc, 'webpageSrc'); - } - - - }, // 鎷垮埌鎵�鏈夐」 getAllChildren(id) { let result = []; + function findChildren(item) { if (item.id === id) { if (item.children && item.children.length > 0) { - item.children.forEach(child => { + item.children.forEach((child) => { findChildren(child); }); } } else { if (item.children && item.children.length > 0) { - item.children.forEach(child => { + item.children.forEach((child) => { findChildren(child); }); } @@ -166,8 +234,8 @@ result.push(...item.children); } } - console.log(this.properties.treeList); - this.properties.treeList.forEach(item => { + console.log(this.properties.treeList, "this.properties.treeList"); + this.properties.treeList.forEach((item) => { findChildren(item); }); return result; @@ -175,46 +243,28 @@ // 鎷垮埌褰撳墠椤瑰瓙椤� flattenTree(tree) { let result = []; + function flatten(node) { result.push(node); if (node.children && node.children.length > 0) { - node.children.forEach(child => { + node.children.forEach((child) => { flatten(child); }); } } - tree.forEach(node => { + tree.forEach((node) => { flatten(node); }); - return result + // 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) { + findAndUpdateItemsByIds(tree, ids, state) { function findAndUpdate(node) { if (ids.includes(node.id)) { - node.checked = true; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true + // console.log(node, 'node'); + node.checked = state; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true } if (node.children && node.children.length > 0) { for (let child of node.children) { @@ -222,32 +272,193 @@ } } } + 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 = []; + let checked = ""; + this.properties.treeList.forEach((item) => { + if (item.children && item.children.length > 0) { + list.push(...this.flattenTree([item])); + } + }); + 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 + ); + console.log(checked, "list"); + if (!checked) { + this.setData({ + selectAll: list, + }); + } + this.setData({ + treeList: updataList, + }); + var myEventDetail = { + value: !flag, + }; // detail瀵硅薄锛屾彁渚涚粰浜嬩欢鐩戝惉鍑芥暟 + var myEventOption = { + bubbles: true, + composed: true, + }; // 瑙﹀彂浜嬩欢鐨勯�夐」 + this.triggerEvent("changeCheckAll", myEventDetail, myEventOption); + }, + // 绔犺妭鍕鹃�� checkResourceTitle(e) { - 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 flag = e.detail.checked; + // 杩欎釜鏃跺�檆hecked鐨勫�兼槸fals + let checkResourceTitleList = []; + const item = e.currentTarget.dataset.item; + // + let list = this.flattenTree([item]); + let ids = []; + list.forEach((item) => { + ids.push(item.id); + }); + const updatedTreeList = this.findAndUpdateItemsByIds( + this.properties.treeList, + ids, + flag + ); + this.setData({ + treeList: updatedTreeList, // 鏇存柊 treeList 鏁版嵁 + }); + console.log(list, "list.checked"); + if (!list.checked) { + this.setData({ + superiorPurchaseSaleMethodId: list, + }); + } + // console.log(this.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId'); + list.forEach((items) => { + console.log(items.checked, "itesasd"); + if (!items.checked) { + this.setData({ + cloudShoppingCart: items, + }); + } + }); + this.setData({ + openIds: this.data.openIds, + }); + }, + // 瀛愰」鍕鹃�� + 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"); + 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; + } + 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 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", + title: "宸叉坊鍔�", + }); + this.setData({ + shoppingCart: false, + }); + } else { + let query = { + requests: [ + { + saleMethodId: saleMethodId, + storeEventId: null, + // agentCode: '鐢靛瓙涔�' + }, + ], + }; + const addRes = await app.MG.store.addShoppingCart(query); + console.log(addRes, "addRes"); + wx.showToast({ + icon: "success", + title: "娣诲姞鎴愬姛", + }); + } + }, + sadd() { + this.triggerEvent("updateShoppingCartHidden"); + this.triggerEvent("updateCloudLearning"); + console.log(789); + }, }, - onCloudShoppingCart() { - console.log(this.properties.treeList); - }, - oncheckbox() { - console.log(111); - }, - logdata(e) { - console.log(e); - } -}) \ No newline at end of file + + catchtap() {}, +}); -- Gitblit v1.9.1