From 3ec10b0c2654e1243e42a5ad563d088ac89c87fe Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期五, 27 九月 2024 14:06:56 +0800
Subject: [PATCH] zf

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

diff --git a/pages/cart/paymentPage/index.js b/pages/cart/paymentPage/index.js
index 645549c..a9e402d 100644
--- a/pages/cart/paymentPage/index.js
+++ b/pages/cart/paymentPage/index.js
@@ -21,25 +21,28 @@
     selectedIds: '',
     purchasedIds: [],
     productList: [],
+    price: '',
     payPrice: '',
     orderGoods: '',
     isPaySuccess: false,
     isPayComplete: false,
     type: '',
     onNorderSaleMethod: '',
-    ImmediatelyReceive: ''
+    integral: 0,
+    defaultVal: false,
+    deductioRate: 0,
+    currentBalance: 0,
+    showIntegral: false
+
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
-
     wx.setNavigationBarTitle({
       title: '鎻愪氦璁㈠崟'
     });
-
-
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -50,11 +53,22 @@
       selectedIds: options.selectedIds,
       onNorderSaleMethod: options.onNorderSaleMethod
     })
-    console.log(this.data.onNorderSaleMethod, 'options');
+    this.getIntegral()
     this.getOrderByOrderNumData()
     this.getDataList()
   },
-
+  getIntegral() {
+    app.MG.store
+      .getUserWallet({
+        type: 'integral'
+      })
+      .then((res) => {
+        this.setData({
+          integral: res.balance,
+          deductioRate: res.exchangeRate
+        });
+      })
+  },
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
@@ -107,9 +121,27 @@
     wx.navigateBack();
   },
 
-
+  // 閲戦鏄剧ず.00鏍煎紡
+  numFormat(value) {
+    if (!value) return "0.00";
+    value = Number(value).toFixed(2);
+    var intPart = Math.trunc(value); // 鑾峰彇鏁存暟閮ㄥ垎
+    var intPartFormat = intPart
+      .toString()
+      .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,"); // 灏嗘暣鏁伴儴鍒嗛�笁涓�鏂�
+    var floatPart = ".00"; // 棰勫畾涔夊皬鏁伴儴鍒�
+    var value2Array = value.split(".");
+    // =2琛ㄧず鏁版嵁鏈夊皬鏁颁綅
+    if (value2Array.length === 2) {
+      floatPart = value2Array[1].toString(); // 鎷垮埌灏忔暟閮ㄥ垎
+      if (floatPart.length === 1) {
+        return `${intPartFormat}.${floatPart}0`;
+      }
+      return `${intPartFormat}.${floatPart}`;
+    }
+    return intPartFormat + floatPart;
+  },
   getOrderByOrderNumData() {
-    console.log(this.data.orderNumber, 'this.data.orderNumber');
     let query = {
       orderNum: this.data.orderNumber,
       fields: {
@@ -118,33 +150,39 @@
       }
     }
     app.MG.store.getOrderByOrderNum(query).then(res => {
-      console.log(res, 'res');
       this.setData({
-        orderGoods: res.orderNumber
-      })
-      console.log(this.data.orderGoods, 'res.orderNumber');
-
-      console.log(res.payPrice);
-      this.setData({
+        orderGoods: res.orderNumber,
+        price: res.totalPrice.toFixed(2),
         payPrice: res.payPrice.toFixed(2),
-        ImmediatelyReceive: res.payPrice
       })
-      console.log(this.data.ImmediatelyReceive);
+      if (Number(this.data.payPrice) < Number(this.data.price)) {
+        this.handleChange()
+      }
       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.type, 'item');
+        if (item.orderSaleMethod.product.cmsTypeRefCode == 'jsek_digitalTextbooks') {
+          item.typeTxt = '鏁板瓧鏁欐潗'
+          item.productType = "鏁板瓧鏁欐潗"
+        } else if (item.orderSaleMethod.product.cmsTypeRefCode == 'jsek_digitalCourses') {
+          item.typeTxt = '鏁板瓧璇剧▼'
+          item.productType = "鏁板瓧璇剧▼"
+        } else {
+          item.typeTxt = '鐢靛瓙涔�'
+          item.productType = "鍥句功鏈嶅姟-鐢靛瓙涔�"
+
+          if (item.orderSaleMethod.type == 'createProductItemSaleMethod') {
+            item.typeTxt = '浜戝涔�'
+            item.productType = "鍥句功鏈嶅姟-浜戝涔�"
+          }
+        }
       })
       this.setData({
         productList: res.saleMethodLinks,
-        // type: item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'
         loading: false,
         hidden: false,
       })
-
     })
   },
   getDataList() {
@@ -161,13 +199,69 @@
       }
     }
     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);
       })
     })
   },
+
+  handleChange(e) {
+    if (e) {
+      this.setData({
+        defaultVal: e.detail.value,
+      });
+    } else {
+      this.setData({
+        defaultVal: true,
+      });
+    }
+
+    if (this.data.defaultVal) {
+      let useBalance = Math.round(Number(this.data.payPrice) * Number(this.data.deductioRate));
+      if (useBalance >= this.data.integral) {
+        this.setData({
+          currentBalance: this.data.integral,
+        });
+      } else {
+        this.setData({
+          currentBalance: useBalance,
+        });
+      }
+      const data = {
+        orderNumber: this.data.orderNumber,
+        payMethod: "Wallet",
+        type: "integral",
+        payValue: this.data.currentBalance
+      }
+      app.MG.store.newOrderPay(data).then(res => {
+        if (res) {
+          this.setData({
+            payId: res.payList[0].id,
+            payPrice: res.payPrice.toFixed(2),
+            deduct: (this.data.currentBalance / 100).toFixed(2),
+            integral: this.data.integral - this.data.currentBalance,
+            showIntegral: true
+          });
+        }
+      })
+    } else {
+      const data = {
+        orderNumber: this.data.orderNumber,
+        payId: this.data.payId,
+      }
+      app.MG.store.delOrderPay(data).then(res => {
+        if (res) {
+          this.setData({
+            payPrice: res.payPrice.toFixed(2),
+            showIntegral: false
+          });
+          this.getIntegral()
+        }
+      })
+    }
+  },
+
+
   confirmOrderGet() {
     if (this.data.myOrderOrderNumber.includes(parseInt(this.data.onNorderSaleMethod))) {
       Toast({
@@ -183,19 +277,15 @@
         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,
@@ -204,7 +294,6 @@
                 "signType": payVal.signType,
                 "paySign": payVal.paySign,
                 success: function (res) {
-                  console.log('鏀粯鎴愬姛');
                   if (res.errMsg == 'requestPayment:ok') {
                     that.setData({
                       isPaySuccess: true

--
Gitblit v1.9.1