From 56b70cdad0a96691eaf37e04a79ef5e92b892480 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期五, 19 四月 2024 11:14:40 +0800
Subject: [PATCH] bug1

---
 pages/cart/paymentPage/index.js |  208 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 125 insertions(+), 83 deletions(-)

diff --git a/pages/cart/paymentPage/index.js b/pages/cart/paymentPage/index.js
index fcad534..1e853ee 100644
--- a/pages/cart/paymentPage/index.js
+++ b/pages/cart/paymentPage/index.js
@@ -1,6 +1,10 @@
 // pages/cart/paymentPage/index.js
+import Toast from 'tdesign-miniprogram/toast/index';
+
 const app = getApp()
-import { getPublicImage } from '../../../assets/js/middleGround/tool';
+import {
+  getPublicImage
+} from '../../../assets/js/middleGround/tool';
 import drawQrcode from './js/weapp.qrcode'
 Page({
 
@@ -8,6 +12,9 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    loading: true,
+    hidden: true,
+    myOrderOrderNumber: [],
     orderNumber: null,
     navBarHeight: '',
     barHeight: '',
@@ -15,20 +22,17 @@
     purchasedIds: [],
     productList: [],
     payPrice: '',
-    drawQrcodeText: 'https://www.baidu.com/',
     orderGoods: '',
-
-
-    confirmBtn: { content: '纭畾', variant: 'base' },
-    dialogKey: 'false',
-
+    isPaySuccess: false,
+    isPayComplete: false,
+    type: '',
+    onNorderSaleMethod: ''
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -36,47 +40,12 @@
       orderNumber: options.orderNumber,
       navBarHeight: navBarHeight,
       barHeight: systInfo.statusBarHeight,
-      selectedIds: options.selectedIds
+      selectedIds: options.selectedIds,
+      onNorderSaleMethod: options.onNorderSaleMethod
     })
-    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
-      }
-    })
-
-
-
-
-
-
+    console.log(this.data.onNorderSaleMethod, 'options');
+    this.getOrderByOrderNumData()
+    this.getDataList()
   },
 
   /**
@@ -132,7 +101,8 @@
   },
 
 
-  getOrderByOrderNum() {
+  getOrderByOrderNumData() {
+    console.log(this.data.orderNumber, 'this.data.orderNumber');
     let query = {
       orderNum: this.data.orderNumber,
       fields: {
@@ -154,49 +124,121 @@
         payPrice: res.payPrice.toFixed(2)
       })
       res.saleMethodLinks.forEach(item => {
+        console.log(item.type, 'item.type');
 
+        const type = item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product';
+        item.type = type; // 灏唗ype璁剧疆涓篿tem瀵硅薄鐨勫睘鎬э紝鑰屼笉鏄娇鐢╯etData
         item.paymentIcon = getPublicImage(item.orderSaleMethod.product.icon)
-        console.log(item.orderSaleMethod.type);
+        console.log(item.type, 'item');
+      })
+      this.setData({
+        productList: res.saleMethodLinks,
+        // type: item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'
+        loading: false,
+        hidden: false,
+      })
 
-        this.setData({
-          productList: res.saleMethodLinks,
-          type: item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'
-        })
+    })
+  },
+  getDataList() {
+    let data = {
+      start: 0,
+      size: 999,
+      filterList: [{
+        field: 'State',
+        value: 'WaitPay'
+      }],
+      sort: {
+        type: 'Desc',
+        field: 'CreateDate'
+      }
+    }
+    app.MG.store.getUserOrderList(data).then((res) => {
 
+      res.datas.forEach((item) => {
+        this.data.myOrderOrderNumber.push(item.saleMethodLinks[0].orderSaleMethod.id)
+        console.log(this.data.myOrderOrderNumber);
       })
     })
   },
   confirmOrderGet() {
-    let query = {
-      orderNum: this.data.orderGoods
-    }
-    app.MG.store.confirmOrder(query).then(res => {
-      this.makeWeChatQrPayGet()
-    })
-    // 璋冨彇寰俊浜岀淮鐮佹敮浠�
+    if (this.data.myOrderOrderNumber.includes(parseInt(this.data.onNorderSaleMethod))) {
+      Toast({
+        context: this,
+        selector: '#t-toast',
+        message: '宸茬粡鍦ㄨ鍗曚腑',
+        theme: 'warning',
+        direction: 'column',
+      });
+    } else {
+      var that = this;
+      let query = {
+        orderNum: this.data.orderGoods
+      }
+      app.MG.store.confirmOrder(query).then(res => {
+        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');
+            if (payRes) {
+              const payVal = JSON.parse(payRes);
+              console.log(payVal);
+              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()
+                  }
+                }
+              });
+            } else {
+              Toast({
+                context: this,
+                selector: '#t-toast',
+                message: '鏀粯澶辫触',
+                theme: 'warning',
+                direction: 'column',
+              });
+            }
 
-  },
-  // 璋冨彇寰俊浜岀淮鐮佹敮浠�
-  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 });
-  },
+    }
 
+  },
+  // 椤甸潰杩斿洖
+  navToBack() {
+    this.getOrderByOrderNumData()
+    // 杩斿洖
+    wx.navigateBack()
+  },
 })
\ No newline at end of file

--
Gitblit v1.9.1