瀏覽代碼

发货通知

kele 1 年之前
父節點
當前提交
2a949d1b1f
共有 2 個文件被更改,包括 62 次插入18 次删除
  1. 9 7
      pages/order/detail.vue
  2. 53 11
      pages/order/list.vue

+ 9 - 7
pages/order/detail.vue

@@ -401,11 +401,14 @@
     // todo:
     // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
     // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
-    if (sheep.$platform.name === 'WechatMiniProgram' && !ignore) {
-      if (!isEmpty(state.orderInfo.wechat_extra_data) && tradeManaged.value === 1) {
-        mpConfirm(orderId);
-        return;
-      }
+    let isOpenBusinessView = true;
+    if (
+      sheep.$platform.name === 'WechatMiniProgram' &&
+      !isEmpty(state.orderInfo.wechat_extra_data) &&
+      isOpenBusinessView &&
+      !ignore
+    ) {
+      mpConfirm(orderId);
       return;
     }
 
@@ -426,8 +429,7 @@
     wx.openBusinessView({
       businessType: 'weappOrderConfirm',
       extraData: {
-        // merchant_id: '1481069012',
-        // merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
+        merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
         transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
       },
       success(response) {

+ 53 - 11
pages/order/list.vue

@@ -157,7 +157,7 @@
             <button
               v-if="order.btns.includes('confirm')"
               class="tool-btn ss-reset-button"
-              @tap.stop="onConfirm(order.id)"
+              @tap.stop="onConfirm(order)"
             >
               确认收货
             </button>
@@ -239,6 +239,7 @@
   import { formatOrderColor } from '@/sheep/hooks/useGoods';
   import sheep from '@/sheep';
   import _ from 'lodash';
+  import { isEmpty } from 'lodash';
 
   const pagination = {
     data: [],
@@ -329,21 +330,62 @@
   }
 
   // 确认收货
-  async function onConfirm(orderId) {
-    uni.showModal({
-      title: '提示',
-      content: '请确认包裹全部到达后再确认收货',
-      success: async function (res) {
-        if (res.confirm) {
-          const { error, data } = await sheep.$api.order.confirm(orderId);
-          if (error === 0) {
-            let index = state.pagination.data.findIndex((order) => order.id === orderId);
-            state.pagination.data[index] = data;
+  async function onConfirm(order, ignore = false) {
+    // 需开启确认收货组件
+    // todo:
+    // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
+    // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
+    let isOpenBusinessView = true;
+    if (
+      sheep.$platform.name === 'WechatMiniProgram' &&
+      !isEmpty(order.wechat_extra_data) &&
+      isOpenBusinessView &&
+      !ignore
+    ) {
+      mpConfirm(order);
+      return;
+    }
+
+    // 正常的确认收货流程
+
+    const { error } = await sheep.$api.order.confirm(order.id);
+    if (error === 0) {
+      state.pagination = pagination;
+      getOrderList();
+    }
+  }
+
+  // #ifdef MP-WEIXIN
+  // 小程序确认收货组件
+  function mpConfirm(order) {
+    if (!wx.openBusinessView) {
+      sheep.$helper.toast(`请升级微信版本`);
+      return;
+    }
+    wx.openBusinessView({
+      businessType: 'weappOrderConfirm',
+      extraData: {
+        merchant_id: '1481069012',
+        merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
+        transaction_id: order.wechat_extra_data.transaction_id,
+      },
+      success(response) {
+        console.log('success:', response);
+        if (response.errMsg === 'openBusinessView:ok') {
+          if (response.extraData.status === 'success') {
+            onConfirm(order, true);
           }
         }
       },
+      fail(error) {
+        console.log('error:', error);
+      },
+      complete(result) {
+        console.log('result:', result);
+      },
     });
   }
+  // #endif
 
   // 查看物流
   async function onExpress(orderId) {