From ecabd20b3dfbd956dad14ffb6ba3dc2efcfdd7c1 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期一, 25 三月 2024 16:23:32 +0800
Subject: [PATCH] 微信支付

---
 pages/cart/paymentPage/index.js |  118 +++++++++++++++++++++++++----------------------------------
 1 files changed, 50 insertions(+), 68 deletions(-)

diff --git a/pages/cart/paymentPage/index.js b/pages/cart/paymentPage/index.js
index fcad534..d1b3162 100644
--- a/pages/cart/paymentPage/index.js
+++ b/pages/cart/paymentPage/index.js
@@ -15,20 +15,15 @@
     purchasedIds: [],
     productList: [],
     payPrice: '',
-    drawQrcodeText: 'https://www.baidu.com/',
     orderGoods: '',
-
-
-    confirmBtn: { content: '纭畾', variant: 'base' },
-    dialogKey: 'false',
-
+    isPaySuccess: false,
+    isPayComplete: false,
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -39,44 +34,7 @@
       selectedIds: options.selectedIds
     })
     console.log('鎺ユ敹鍒扮殑璁㈠崟鍙�:', this.data.orderNumber);
-
-
     this.getOrderByOrderNum()
-
-
-
-
-    drawQrcode({
-
-      width: 200, // 蹇呴』锛屼簩缁寸爜瀹藉害锛屼笌canvas鐨剋idth淇濇寔涓�鑷�
-
-      height: 200, // 蹇呴』锛屼簩缁寸爜楂樺害锛屼笌canvas鐨刪eight淇濇寔涓�鑷�
-
-      canvasId: 'myQrcode',
-
-      background: '#ffffff', //	闈炲繀椤伙紝浜岀淮鐮佽儗鏅鑹诧紝榛樿鍊肩櫧鑹�
-
-      foreground: '#2bb15e', // 闈炲繀椤伙紝浜岀淮鐮佸墠鏅壊锛岄粯璁ゅ�奸粦鑹� 	'#000000'
-
-      // ctx: wx.createCanvasContext('myQrcode'), // 闈炲繀椤伙紝缁樺浘涓婁笅鏂囷紝鍙�氳繃 wx.createCanvasContext('canvasId') 鑾峰彇锛寁1.0.0+鐗堟湰鏀寔
-
-      text: this.data.drawQrcodeText,  // 蹇呴』锛屼簩缁寸爜鍐呭
-      // v1.0.0+鐗堟湰鏀寔鍦ㄤ簩缁寸爜涓婄粯鍒跺浘鐗�
-
-      image: {
-        // imageResource: '../../images/icon.png', // 鎸囧畾浜岀淮鐮佸皬鍥炬爣
-        dx: 70,
-        dy: 70,
-        dWidth: 60,
-        dHeight: 60
-      }
-    })
-
-
-
-
-
-
   },
 
   /**
@@ -167,36 +125,60 @@
     })
   },
   confirmOrderGet() {
+    var that = this;
     let query = {
       orderNum: this.data.orderGoods
     }
     app.MG.store.confirmOrder(query).then(res => {
-      this.makeWeChatQrPayGet()
+      console.log(res.orderNumber, 'res');
+      if (res.orderNumber) {
+        const resOrderNum = {
+          orderNum: res.orderNumber,
+        };
+
+        // 鐢ㄦ埛鏈粦瀹氬井淇� 鎶�500
+        app.MG.store.makeWeChatPay(resOrderNum).then(payRes => {
+          const payVal = JSON.parse(payRes);
+          wx.requestPayment({
+            "appId": payVal.appId,
+            "timeStamp": payVal.timeStamp,
+            "nonceStr": payVal.nonceStr,
+            "package": payVal.package,
+            "signType": payVal.signType,
+            "paySign": payVal.paySign,
+            success: function (res) {
+              console.log('鏀粯鎴愬姛');
+              if (res.errMsg == 'requestPayment:ok') {
+                that.setData({
+                  isPaySuccess: true
+                })
+              }
+            },
+            fail: function (res) {
+              console.log('鏀粯澶辫触');
+            },
+            // 鏃犺鏀粯鎴愬姛澶辫触閮戒細璋冪敤
+            "complete": function (res) {
+              if (res.errMsg == 'requestPayment:ok') {
+                that.setData({
+                  isPayComplete: true
+                })
+              }
+              if (that.data.isPaySuccess && that.data.isPayComplete) {
+                that.navToBack()
+              }
+            }
+          });
+        })
+      }
+
     })
     // 璋冨彇寰俊浜岀淮鐮佹敮浠�
+  },
+  // 椤甸潰杩斿洖
+  navToBack() {
 
+    // 杩斿洖
+    wx.navigateBack()
   },
-  // 璋冨彇寰俊浜岀淮鐮佹敮浠�
-  makeWeChatQrPayGet() {
-    let query = {
-      orderNum: this.data.orderGoods
-    }
-    app.MG.store.makeWeChatQrPay(query).then((res) => {
-
-      this.setData({
-        drawQrcodeText: res
-      })
-      this.data.dialogKey = true
-      console.log(this.data.drawQrcodeText, 'drawQrcodeText');
-    })
-  },
-  showDialog(e) {
-    const { key } = e.currentTarget.dataset;
-    this.setData({ [key]: true, dialogKey: key });
-  },
-  closeDialog() {
-    const { dialogKey } = this.data;
-    this.setData({ [dialogKey]: false });
-  },
-
 })
\ No newline at end of file

--
Gitblit v1.9.1