张田田 2 months ago
parent
commit
16ec085ad7

+ 9 - 0
miniprogram/module/order/pages/confirme-order/confirme-order.ts

@@ -224,6 +224,15 @@ Page({
           });
         }, (error: any) => {
           this.setData({ isPaymentLoading: false });
+          if (error?.errMsg === 'requestPayment:fail cancel') {
+            // 支付取消跳到支付订单页面
+            setTimeout(() => {
+              wx.redirectTo({
+                url: '/module/article/pages/order-list/order-list',
+              });
+              return;
+            }, 2000);
+          }
           wx.showToast({
             title: error?.errMsg || error?.message || "支付失败,请重试",
             icon: "none",

+ 11 - 1
miniprogram/module/order/pages/order-detail/order-detail.ts

@@ -173,7 +173,7 @@ Page({
     this.setData({ isPaymentLoading: true });
     try {
       // 调用支付接口
-      const payResult = await orderPayMethod(this.data.id, this.data.orderDetail?.remark);
+      const payResult = await orderPayMethod(this.data.id, (this.data.orderDetail as any)?.remark || '');
       if (payResult) {
         const paymentParams = payResult;
         handleWeChatPayment(paymentParams, (res: any) => {
@@ -183,6 +183,16 @@ Page({
           });
         }, (error: any) => {
           this.setData({ isPaymentLoading: false });
+          if (error?.errMsg === 'requestPayment:fail cancel') {
+            // 支付取消跳到支付订单页面
+            setTimeout(() => {
+              wx.redirectTo({
+                url: '/module/article/pages/order-list/order-list',
+              });
+              return;
+            }, 2000);
+          }
+          console.log(error, '支付失败');
           wx.showToast({
             title: error?.errMsg || error?.message || "支付失败,请重试",
             icon: "none",

+ 9 - 0
miniprogram/module/order/pages/other-detail/other-detail.ts

@@ -212,6 +212,15 @@ Page({
           });
         }, (error: any) => {
           this.setData({ isPaymentLoading: false });
+          if (error?.errMsg === 'requestPayment:fail cancel') {
+            // 支付取消跳到支付订单页面
+            setTimeout(() => {
+              wx.redirectTo({
+                url: '/module/article/pages/order-list/order-list',
+              });
+              return;
+            }, 2000);
+          }
           wx.showToast({
             title: error.errMsg || "支付失败,请重试",
             icon: "none",

+ 10 - 13
miniprogram/utils/util.ts

@@ -153,24 +153,21 @@ export const handleWeChatPayment = (paymentParams: any, onSuccess: any, onFail:
     paySign: paymentParams.paySign,
     success: (res) => {
       wx.hideLoading()
-      console.log('支付成功:', res)
       if (onSuccess) {
         onSuccess(res)
       }
     },
     fail: (err) => {
-      // wx.hideLoading()
-      if(err.errMsg==='requestPayment:fail cancel'){
-        // console.log('支付已取消')
-       wx.showToast({
-        title: '支付已取消',
-        icon: 'none'
-       })
-      }else{
-      console.error(onFail,'支付失败:', err)
-        if (onFail) {
-          onFail(err)
-        }
+      if (onFail) {
+        onFail(err)
+      }
+      if (err.errMsg === 'requestPayment:fail cancel') {
+        wx.showToast({
+          title: '支付已取消',
+          icon: 'none'
+        })
+      } else {
+        console.error('支付失败:', err)
       }
     }
   })