From 4c472f6bbf82e5ef95b60ac8e417760d89a7ba36 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期五, 29 三月 2024 19:39:17 +0800
Subject: [PATCH] 购物车2

---
 pages/cart/paymentPage/index.js |  142 ++++++++++++++++++++++-------------------------
 1 files changed, 66 insertions(+), 76 deletions(-)

diff --git a/pages/cart/paymentPage/index.js b/pages/cart/paymentPage/index.js
index fcad534..de51373 100644
--- a/pages/cart/paymentPage/index.js
+++ b/pages/cart/paymentPage/index.js
@@ -1,6 +1,8 @@
 // pages/cart/paymentPage/index.js
 const app = getApp()
-import { getPublicImage } from '../../../assets/js/middleGround/tool';
+import {
+  getPublicImage
+} from '../../../assets/js/middleGround/tool';
 import drawQrcode from './js/weapp.qrcode'
 Page({
 
@@ -15,20 +17,16 @@
     purchasedIds: [],
     productList: [],
     payPrice: '',
-    drawQrcodeText: 'https://www.baidu.com/',
     orderGoods: '',
-
-
-    confirmBtn: { content: '纭畾', variant: 'base' },
-    dialogKey: 'false',
-
+    isPaySuccess: false,
+    isPayComplete: false,
+    type: ''
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -39,44 +37,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
-      }
-    })
-
-
-
-
-
-
+    this.getOrderByOrderNumData()
   },
 
   /**
@@ -132,7 +93,7 @@
   },
 
 
-  getOrderByOrderNum() {
+  getOrderByOrderNumData() {
     let query = {
       orderNum: this.data.orderNumber,
       fields: {
@@ -155,48 +116,77 @@
       })
       res.saleMethodLinks.forEach(item => {
 
+        const type = item.type == 'createProductItemSaleMethod' ? 'item' : 'product';
+        item.type = type; // 灏唗ype璁剧疆涓篿tem瀵硅薄鐨勫睘鎬э紝鑰屼笉鏄娇鐢╯etData
         item.paymentIcon = getPublicImage(item.orderSaleMethod.product.icon)
-        console.log(item.orderSaleMethod.type);
 
-        this.setData({
-          productList: res.saleMethodLinks,
-          type: item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'
-        })
+        console.log(item.type, 'item');
 
+
+      })
+      this.setData({
+        productList: res.saleMethodLinks,
+        // type: item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'
       })
     })
   },
   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) {
+        let resOrderNum = {
+          orderNum: res.orderNumber,
+          platform: "WeChatAppCustom"
+        };
+        console.log(resOrderNum, 'resOrderNum');
+        // 鐢ㄦ埛鏈粦瀹氬井淇� 鎶�500
+        app.MG.store.makeWeChatPay(resOrderNum).then(payRes => {
+          console.log(payRes, '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