Browse Source

feat(微信小程序): 新增微信小程序原生确认收货功能

在订单详情页和订单列表项组件中:
1. 新增校验支付订单号有效性的工具方法hasPayOrderNo
2. 新增调用微信原生确认收货业务视图的方法openWechatConfirmReceive
3. 调整确认收货逻辑,当订单配置showConfirmShop为1时,使用微信官方流程替代默认弹窗确认
ylong 1 day ago
parent
commit
35467d3465
2 changed files with 76 additions and 0 deletions
  1. 38 0
      pages-car/components/buy-order-item.vue
  2. 38 0
      pages-car/pages/order-detail.vue

+ 38 - 0
pages-car/components/buy-order-item.vue

@@ -144,6 +144,41 @@
             }
             }
         },
         },
         methods: {
         methods: {
+            hasPayOrderNo(payOrderNo) {
+                return payOrderNo !== null && payOrderNo !== undefined && String(payOrderNo).trim() !== '';
+            },
+            openWechatConfirmReceive(order) {
+                // #ifdef MP-WEIXIN
+                if (typeof wx === 'undefined' || typeof wx.openBusinessView !== 'function') {
+                    return false;
+                }
+                wx.openBusinessView({
+                    businessType: 'weappOrderConfirm',
+                    extraData: {
+                        transaction_id: order.payOrderNo
+                    },
+                    success: () => {
+                        uni.showLoading({ title: '处理中' });
+                        this.$u.api.confirmReceiveAjax({ orderId: order.orderId }).then(res => {
+                            uni.hideLoading();
+                            if (res.code == 200) {
+                                uni.showToast({ title: '收货成功', icon: 'success' });
+                                this.$emit('refresh'); // 通知父组件刷新列表
+                            }
+                        }).catch(() => {
+                            uni.hideLoading();
+                        });
+                    },
+                    fail: (err) => {
+                        const errMsg = (err && err.errMsg) ? err.errMsg : '';
+                        if (errMsg.indexOf('cancel') > -1) return;
+                        uni.showToast({ title: '暂无法唤起微信确认收货', icon: 'none' });
+                    }
+                });
+                return true;
+                // #endif
+                return false;
+            },
             goToDetail() {
             goToDetail() {
                 uni.navigateTo({
                 uni.navigateTo({
                     url: `/pages-car/pages/order-detail?orderId=${this.order.orderId}`
                     url: `/pages-car/pages/order-detail?orderId=${this.order.orderId}`
@@ -176,6 +211,9 @@
                     return;
                     return;
                 }
                 }
                 if (type === 'confirm') {
                 if (type === 'confirm') {
+                    if (data.showConfirmShop == 1 && this.hasPayOrderNo(data.payOrderNo) && this.openWechatConfirmReceive(data)) {
+                        return;
+                    }
                     uni.showModal({
                     uni.showModal({
                         title: '提示',
                         title: '提示',
                         content: '是否确认收货?',
                         content: '是否确认收货?',

+ 38 - 0
pages-car/pages/order-detail.vue

@@ -229,6 +229,41 @@ export default {
         uni.$off('selectAddr', this.onAddressSelected);
         uni.$off('selectAddr', this.onAddressSelected);
     },
     },
     methods: {
     methods: {
+        hasPayOrderNo(payOrderNo) {
+            return payOrderNo !== null && payOrderNo !== undefined && String(payOrderNo).trim() !== '';
+        },
+        openWechatConfirmReceive(payOrderNo) {
+            // #ifdef MP-WEIXIN
+            if (typeof wx === 'undefined' || typeof wx.openBusinessView !== 'function') {
+                return false;
+            }
+            wx.openBusinessView({
+                businessType: 'weappOrderConfirm',
+                extraData: {
+                    transaction_id: payOrderNo
+                },
+                success: () => {
+                    uni.showLoading({ title: '处理中' });
+                    this.$u.api.confirmReceiveAjax({ orderId: this.orderInfo.orderId }).then(res => {
+                        uni.hideLoading();
+                        if (res.code == 200) {
+                            uni.showToast({ title: '收货成功', icon: 'success' });
+                            this.loadOrderDetail(this.orderInfo.orderId);
+                        }
+                    }).catch(() => {
+                        uni.hideLoading();
+                    });
+                },
+                fail: (err) => {
+                    const errMsg = (err && err.errMsg) ? err.errMsg : '';
+                    if (errMsg.indexOf('cancel') > -1) return;
+                    uni.showToast({ title: '暂无法唤起微信确认收货', icon: 'none' });
+                }
+            });
+            return true;
+            // #endif
+            return false;
+        },
         onAddressSelected(addr) {
         onAddressSelected(addr) {
             if (this.isModifyingAddress && addr && addr.id) {
             if (this.isModifyingAddress && addr && addr.id) {
                 this.$u.api.modifyOrderAddressAjax({
                 this.$u.api.modifyOrderAddressAjax({
@@ -388,6 +423,9 @@ export default {
                 return;
                 return;
             }
             }
             if (type === 'confirm') {
             if (type === 'confirm') {
+                if (this.orderInfo.showConfirmShop == 1 && this.hasPayOrderNo(this.orderInfo.payOrderNo) && this.openWechatConfirmReceive(this.orderInfo.payOrderNo)) {
+                    return;
+                }
                 uni.showModal({
                 uni.showModal({
                     title: '提示',
                     title: '提示',
                     content: '是否确认收货?',
                     content: '是否确认收货?',