From 4ef1826180997bac879913bf17867bd3e390c29d Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期四, 28 三月 2024 09:24:46 +0800 Subject: [PATCH] 微信支付修改 --- packageBookService/pages/bookServices/detail/components/tree/index.js | 273 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 220 insertions(+), 53 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/components/tree/index.js b/packageBookService/pages/bookServices/detail/components/tree/index.js index 414cc08..1486ac7 100644 --- a/packageBookService/pages/bookServices/detail/components/tree/index.js +++ b/packageBookService/pages/bookServices/detail/components/tree/index.js @@ -3,6 +3,8 @@ const util = require('./components/util') // 寮曞叆灏佽杩囩殑鍔犺浇鎻愮ず const app = getApp() Component({ + // checked: false, + properties: { treeList: { type: Array, @@ -24,31 +26,78 @@ type: String, value: '' }, - openTeachids: { + openIds: { type: Array, - value: '' + value: [], + } + , + isShowCheck: { + type: Boolean, + value: false, }, - openLearnids: { - type: Array, - value: "" + paymentPage: { + type: Boolean, + value: false, + }, + superior: { + type: Boolean, + value: false, } }, data: { - activeValues: [0], - webpageSrc: '' + sonPurchaseSaleMethodId: '', + superiorPurchaseSaleMethodId: [], + activeValues: [1, 2], + webpageSrc: '', + cloudShoppingCart: [] + }, + ready() { + this.setData({ + + }) + console.log('鍑嗗'); }, onShow() { - + debugger + this.setData({ + sonPurchaseSaleMethodId: '' + }) + }, + onLoad() { + this.setData({ + sonPurchaseSaleMethodId: '' + }) + }, + observers: { + 'openIds': function (newValue) { + // var myEventDetail = { + // } + // var myEventOption = { + // bubbles: true, + // composed: true + // } + // this.triggerEvent('handleTree', myEventDetail, myEventOption) + } }, - 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++) { @@ -74,7 +123,8 @@ // 鍒ゆ柇璧勬簮鏄惁璐拱 resourceIsBuy(data) { if (data.saleMethod && data.saleMethod.length) { - const isSHow = buyIdList.value.some((item) => item == data.saleMethod[0].Id) + 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 @@ -82,23 +132,23 @@ }, // 璺宠浆闊宠棰戞挱鏀惧櫒 goPlayer(e) { + if (this.properties.isShowCheck) return true const item = e.currentTarget.dataset.item const parent = e.currentTarget.dataset.parent - - - let url - if (item.selectType == 'video') { + if (item.selectType == 'video' || item.learnSelectType == 'video') { url = '/packageDomain/pages/resourceDetails/myVideo/index' - } else if (item.selectType == 'audio') { + } 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' } - - // else { - // - // } + if (this.properties.tab == 'jsek_cloudLearning' && this.resourceIsBuy(item)) { + return wx.showToast({ + icon: 'error', + title: '璇峰厛璐拱璇ヨ祫婧�', + }) + } 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}`, }) @@ -169,7 +219,7 @@ result.push(...item.children); } } - console.log(this.properties.treeList); + console.log(this.properties.treeList, 'this.properties.treeList'); this.properties.treeList.forEach(item => { findChildren(item); }); @@ -187,37 +237,19 @@ } } tree.forEach(node => { + flatten(node); }); + // 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) { function findAndUpdate(node) { if (ids.includes(node.id)) { - node.checked = true; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true + // console.log(node, 'node'); + node.checked = !node.checked // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true } if (node.children && node.children.length > 0) { for (let child of node.children) { @@ -227,27 +259,162 @@ } 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 = [] + this.properties.treeList.forEach(item => { + if (item.children && item.children.length > 0) { + list.push(...this.flattenTree([item])) + } + }) + list.forEach(item => { + ids.push(item.id) + }) + const updataList = this.findAndUpdateItemsByIds(this.properties.treeList, ids); + this.setData({ + treeList: updataList + }) + }, + // 绔犺妭鍕鹃�� checkResourceTitle(e) { + // 杩欎釜鏃跺�檆hecked鐨勫�兼槸fals + let checkResourceTitleList = [] 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); - } + // console.log(list, 'list789'); + const updatedTreeList = this.findAndUpdateItemsByIds(this.properties.treeList, ids); + this.setData({ + treeList: updatedTreeList // 鏇存柊 treeList 鏁版嵁 + }); + + if (!list.checked) { + if (this.properties.superior) { + console.log(852); + + this.properties.superior = false + this.setData({ + superiorPurchaseSaleMethodId: [] + }) + } + if (!this.properties.superior) { + 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.onCloudShoppingCart() + }, + // 瀛愰」鍕鹃�� + 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() { + let requests = [] + const item = this.data.cloudShoppingCart + console.log(item, 'item'); + item.forEach((items) => { + if (items.saleMethod.length) { + requests.push({ + saleMethodId: items.saleMethod[0].Id, + count: 1 + }) + } + }) + let query = { + remarks: '浜戝涔�', + requests + } + // 鏌ヨ璁㈠崟 + let initOrderRes = await app.MG.store.initOrder(query) + let parameter = { + orderNum: initOrderRes.orderNumber + } + const confirmOrderRes = await app.MG.store.confirmOrder(parameter) + // if (confirmOrderRes.orderNumber) { + // wx.navigateTo({ + // url: `/pages/cart/paymentPage/index?orderNumber=${confirmOrderRes.orderNumber}`, + // }) + // requests = [] + // } + }, }, - onCloudShoppingCart() { - console.log(this.properties.treeList); - }, - oncheckbox() { - console.log(111); + onCheckAllChange(e) { + // debugger + // console.log('checkbox', e.detail.value); + // this.setData({ + // checkAllValues: event.detail, + // }); } }) \ No newline at end of file -- Gitblit v1.9.1