From dc51c18fbb684482ee045797e26cbbecf852df79 Mon Sep 17 00:00:00 2001 From: wangdong <1551135706@qq.com> Date: Thu, 1 Aug 2024 17:14:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 5 +-- common/enum/payment/Method.js | 2 +- manifest.json | 1 + pages/checkout/cashier/index.vue | 75 +++++++++++++++++++++++--------- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/App.vue b/App.vue index f1bb974..e533179 100644 --- a/App.vue +++ b/App.vue @@ -26,13 +26,12 @@ }, onShow(options) { console.log('app onShow', options); - let extraData = options.referrerInfo.extraData; - if (extraData) { + if (options.referrerInfo) { // wx.showToast({ // title: params.errStr, // icon: 'none', // }); - uni.$emit('appShow', extraData); + uni.$emit('appShow', options.referrerInfo); } }, diff --git a/common/enum/payment/Method.js b/common/enum/payment/Method.js index ff329c5..8a8f7ce 100644 --- a/common/enum/payment/Method.js +++ b/common/enum/payment/Method.js @@ -8,5 +8,5 @@ export default new Enum([ { key: 'WECHAT', name: '微信支付', value: 'wechat' }, { key: 'ALIPAY', name: '支付宝支付', value: 'alipay' }, { key: 'BALANCE', name: '余额支付', value: 'balance' }, - { key: 'HUIFU', name: '汇支付', value: 'huifu' } + { key: 'HUIFU', name: '银联支付', value: 'huifu' } ]) diff --git a/manifest.json b/manifest.json index e486afc..a6a1fb5 100644 --- a/manifest.json +++ b/manifest.json @@ -123,6 +123,7 @@ "optimization" : { "subPackages" : true }, + "embeddedAppIdList": ["wx014ad2ef80a147a7"], "requiredPrivateInfos" : [ "chooseAddress", "getLocation" ] }, "mp-alipay" : { diff --git a/pages/checkout/cashier/index.vue b/pages/checkout/cashier/index.vue index 5e987d5..5f1a1ec 100644 --- a/pages/checkout/cashier/index.vue +++ b/pages/checkout/cashier/index.vue @@ -19,9 +19,12 @@ - + + + + {{ PayMethodEnum[item.method].name }} @@ -137,15 +140,14 @@ // 获取收银台信息 this.getCashierInfo(); uni.$on('appShow', this.solveShowMsg); + uni.onAppShow() }, methods: { - solveShowMsg(msgData) { - console.log(msgData); - if (msgData.errCode === '0000') { - this.onShowSuccess({ message: msgData.errStr }); - } else { - this.onPayFail({ message: msgData.errStr }); + solveShowMsg(info) { + console.log(info); + if (this.miniPayRequest && Object.keys(this.miniPayRequest).length > 0 && info.appId === this.miniPayRequest.miniuser) { + this.onTradeQuery(this.miniPayRequest.out_trade_no, this.curPaymentItem.method); } }, // 获取收银台信息 @@ -194,7 +196,11 @@ // this.$toast('抱歉,此支付方式暂未完善') // return // } - this.curPaymentItem = this.methods[index] + this.curPaymentItem = this.methods[index]; + console.log(this.curPaymentItem); + if (this.curPaymentItem.method === 'huifu') { + this.createOrder(); + } }, // 判断当前页面来源于浏览器返回 @@ -238,7 +244,34 @@ // 按钮禁用 if (app.disabled) return app.disabled = true + if (app.curPaymentItem.method === 'huifu') { + if (!app.miniPayRequest || Object.keys(app.miniPayRequest).length === 0) { + app.$toast(`暂无${app.PayMethodEnum[app.curPaymentItem.method].name}支付信息`); + return + } + let appPayRequest = ''; + appPayRequest = encodeURIComponent(JSON.stringify({ + sign: app.miniPayRequest.sign, + prepayid: app.miniPayRequest.prepayid, + })); + uni.openEmbeddedMiniProgram({ + appId: app.miniPayRequest.miniuser, + path: `${app.miniPayRequest.minipath}?appPayRequest=${appPayRequest}`, + success(res) { + console.log('success', res) + }, + fail(e) { + console.log('fail', e); + } + }); + } else { // 提交到后端API + this.createOrder(); + } + + }, + createOrder() { + const app = this; CashierApi.orderPay(app.orderId, { method: app.curPaymentItem.method, client: app.platform, @@ -247,16 +280,9 @@ .then(result => { console.log(result); if (app.curPaymentItem.method === 'huifu') { - const { miniPayRequest } = result.data.payment; - let appPayRequest = ''; - appPayRequest = encodeURIComponent(JSON.stringify({ - sign: miniPayRequest.sign, - prepayid: miniPayRequest.prepayid, - })); - uni.navigateToMiniProgram({ - appId: miniPayRequest.miniuser, - path: `${miniPayRequest.minipath}?appPayRequest=${appPayRequest}`, - }); + const { miniPayRequest, out_trade_no } = result.data.payment; + app.miniPayRequest = miniPayRequest; + app.miniPayRequest.out_trade_no = out_trade_no; } else { app.onSubmitCallback(result) } @@ -422,7 +448,7 @@ .payment-method { width: 94%; margin: 0 auto 20rpx auto; - padding: 0 40rpx; + padding: 0 40rpx 0 20rpx; background-color: #ffffff; border-radius: 20rpx; @@ -436,7 +462,8 @@ } .item-left_icon { - margin-right: 20rpx; + width: 100rpx; + text-align: center; font-size: 44rpx; &.wechat { @@ -455,6 +482,14 @@ color: #009fe8; } } + .huifu-box { + width: 100rpx; + display: flex; + justify-content: center; + .huifu { + height: 44rpx; + } + } .item-left_text { font-size: 28rpx;