From 2ee8ddb1ecac7df4198e54e08ec7f22daf4b07c0 Mon Sep 17 00:00:00 2001 From: QYF-GitLab1 <1940665526@qq.com> Date: 星期五, 03 一月 2025 16:57:38 +0800 Subject: [PATCH] 111 --- pages/cart/paymentPage/index.js | 138 +++++++++++++++++++++++++++++++++++++-------- 1 files changed, 112 insertions(+), 26 deletions(-) diff --git a/pages/cart/paymentPage/index.js b/pages/cart/paymentPage/index.js index 9e747a2..8a28a08 100644 --- a/pages/cart/paymentPage/index.js +++ b/pages/cart/paymentPage/index.js @@ -21,13 +21,19 @@ selectedIds: '', purchasedIds: [], productList: [], + price: '', payPrice: '', orderGoods: '', isPaySuccess: false, isPayComplete: false, type: '', onNorderSaleMethod: '', - ImmediatelyReceive: '' + integral: 0, + defaultVal: false, + deductioRate: 0, + currentBalance: 0, + showIntegral: false + }, /** @@ -47,11 +53,22 @@ selectedIds: options.selectedIds, onNorderSaleMethod: options.onNorderSaleMethod }) - console.log(this.data.onNorderSaleMethod, 'options'); + this.getIntegral() this.getOrderByOrderNumData() this.getDataList() }, - + getIntegral() { + app.MG.store + .getUserWallet({ + type: 'integral' + }) + .then((res) => { + this.setData({ + integral: res.balance, + deductioRate: res.exchangeRate + }); + }) + }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ @@ -125,7 +142,6 @@ return intPartFormat + floatPart; }, getOrderByOrderNumData() { - console.log(this.data.orderNumber, 'this.data.orderNumber'); let query = { orderNum: this.data.orderNumber, fields: { @@ -135,26 +151,43 @@ } app.MG.store.getOrderByOrderNum(query).then(res => { this.setData({ - orderGoods: res.orderNumber - }) - this.setData({ + orderGoods: res.orderNumber, + price: res.totalPrice.toFixed(2), payPrice: res.payPrice.toFixed(2), - ImmediatelyReceive: res.payPrice }) - console.log(this.data.ImmediatelyReceive); + if (Number(this.data.payPrice) < Number(this.data.price)) { + this.handleChange() + } + console.log(res, "res") res.saleMethodLinks.forEach(item => { const type = item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'; item.type = type; // 灏唗ype璁剧疆涓篿tem瀵硅薄鐨勫睘鎬э紝鑰屼笉鏄娇鐢╯etData item.paymentIcon = getPublicImage(item.orderSaleMethod.product.icon) - item.payPrice = this.numFormat(item.payPrice) - console.log(item, 'item'); + item.price = item.orderSaleMethod.price.toFixed(2) + if (item.orderSaleMethod.product.cmsTypeRefCode == 'jsek_digitalTextbooks') { + item.typeTxt = '鏁板瓧鏁欐潗' + item.productType = "鏁板瓧鏁欐潗" + } else if (item.orderSaleMethod.product.cmsTypeRefCode == 'jsek_digitalCourses') { + item.typeTxt = '鏁板瓧璇剧▼' + item.productType = "鏁板瓧璇剧▼" + } else { + item.typeTxt = '鐢靛瓙涔�' + item.productType = "鍥句功鏈嶅姟-鐢靛瓙涔�" + if (item.orderSaleMethod.type == 'createProductItemSaleMethod') { + item.typeTxt = '浜戝涔�' + item.productType = "鍥句功鏈嶅姟-浜戝涔�" + } + if (item.orderSaleMethod.cmsItemList.length && item.orderSaleMethod.cmsItemList[0].type == "questionBankFolder") { + item.typeTxt = '棰樺簱' + item.productType = "鍥句功鏈嶅姟-浜戞祴璇�" + } + } }) this.setData({ productList: res.saleMethodLinks, loading: false, hidden: false, }) - }) }, getDataList() { @@ -171,13 +204,69 @@ } } app.MG.store.getUserOrderList(data).then((res) => { - res.datas.forEach((item) => { this.data.myOrderOrderNumber.push(item.saleMethodLinks[0].orderSaleMethod.id) - console.log(this.data.myOrderOrderNumber); }) }) }, + + handleChange(e) { + if (e) { + this.setData({ + defaultVal: e.detail.value, + }); + } else { + this.setData({ + defaultVal: true, + }); + } + + if (this.data.defaultVal) { + let useBalance = Math.round(Number(this.data.payPrice) * Number(this.data.deductioRate)); + if (useBalance >= this.data.integral) { + this.setData({ + currentBalance: this.data.integral, + }); + } else { + this.setData({ + currentBalance: useBalance, + }); + } + const data = { + orderNumber: this.data.orderNumber, + payMethod: "Wallet", + type: "integral", + payValue: this.data.currentBalance + } + app.MG.store.newOrderPay(data).then(res => { + if (res) { + this.setData({ + payId: res.payList[0].id, + payPrice: res.payPrice.toFixed(2), + deduct: (this.data.currentBalance / 100).toFixed(2), + integral: this.data.integral - this.data.currentBalance, + showIntegral: true + }); + } + }) + } else { + const data = { + orderNumber: this.data.orderNumber, + payId: this.data.payId, + } + app.MG.store.delOrderPay(data).then(res => { + if (res) { + this.setData({ + payPrice: res.payPrice.toFixed(2), + showIntegral: false + }); + this.getIntegral() + } + }) + } + }, + + confirmOrderGet() { if (this.data.myOrderOrderNumber.includes(parseInt(this.data.onNorderSaleMethod))) { Toast({ @@ -193,19 +282,15 @@ orderNum: this.data.orderGoods } app.MG.store.confirmOrder(query).then(res => { - console.log(res.orderNumber, 'res'); if (res.orderNumber) { let resOrderNum = { orderNum: res.orderNumber, platform: "WeChatAppCustom" }; - console.log(resOrderNum, 'resOrderNum'); // 鐢ㄦ埛鏈粦瀹氬井淇� 鎶�500 app.MG.store.makeWeChatPay(resOrderNum).then(payRes => { - console.log(payRes, 'payRes'); if (payRes) { const payVal = JSON.parse(payRes); - console.log(payVal); wx.requestPayment({ "appId": payVal.appId, "timeStamp": payVal.timeStamp, @@ -214,7 +299,6 @@ "signType": payVal.signType, "paySign": payVal.paySign, success: function (res) { - console.log('鏀粯鎴愬姛'); if (res.errMsg == 'requestPayment:ok') { that.setData({ isPaySuccess: true @@ -263,14 +347,16 @@ orderNum: this.data.orderGoods } app.MG.store.confirmOrder(query).then(res => { - Toast({ - context: this, - selector: '#t-toast', - message: '棰嗗彇鎴愬姛', - theme: 'success', - direction: 'column', + wx.showToast({ + title: '棰嗗彇鎴愬姛', + icon: 'success', + complete: res => { + setTimeout(() => { + wx.navigateBack() + }, 1000); + } }); - wx.navigateBack() + }) } }) \ No newline at end of file -- Gitblit v1.9.1