From d470e67ac1997882502b75cbfdaf359626cfaaa8 Mon Sep 17 00:00:00 2001
From: Liuyi <candymxq888@outlook.com>
Date: 星期五, 20 十二月 2024 17:27:07 +0800
Subject: [PATCH] 测试修复小程序问题,添加水控机设备

---
 unpackage/dist/dev/mp-weixin/pages/recharge/index.js |  111 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 80 insertions(+), 31 deletions(-)

diff --git a/unpackage/dist/dev/mp-weixin/pages/recharge/index.js b/unpackage/dist/dev/mp-weixin/pages/recharge/index.js
index 2872b67..7b00dc2 100644
--- a/unpackage/dist/dev/mp-weixin/pages/recharge/index.js
+++ b/unpackage/dist/dev/mp-weixin/pages/recharge/index.js
@@ -14,6 +14,7 @@
   setup(__props) {
     const choosedMoney = common_vendor.ref(50);
     const disabled = common_vendor.ref(true);
+    const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
     const moneyList = common_vendor.ref([
       { value: 50, active: true },
       { value: 100, active: false },
@@ -49,41 +50,88 @@
       { text: "微信支付", value: 2, checked: true, img: "../../static/images/recharge/wx.png" }
       // {text:"余额",value:3,checked:false,img:'../../static/images/recharge/balance.png'},
     ]);
+    let timerId;
+    let payStatus = common_vendor.ref(true);
     async function submit() {
-      let money = "";
-      if (disabled.value) {
-        money = choosedMoney.value;
-      } else {
-        money = Number(otherMoney.value);
-      }
-      await api_index.wxPayApi({ businessType: 1, tradeAmount: money }).then((res) => {
-        console.log("reswxpay", res);
-        common_vendor.wx$1.requestPayment({
-          //预支付订单信息
-          // appId: res.data.appId,
-          timeStamp: res.data.timeStamp,
-          //时间戳 
-          nonceStr: res.data.nonceStr,
-          //随机串     
-          package: res.data.package,
-          //prepay_id
-          signType: res.data.signType,
-          //签名算法MD5		
-          paySign: res.data.paySign,
-          //微信签名 
-          success(res2) {
-            if (res2.errMsg == "requestPayment:ok") {
-              console.log("支付成功", res2);
-            } else {
-              console.log("支付失败");
-            }
-          },
-          fail(res2) {
-            console.log("支付失败", res2);
+      if (payStatus.value) {
+        payStatus.value = false;
+        timerId = setTimeout(() => {
+          payStatus.value = true;
+        }, 2e4);
+        let money = "";
+        if (disabled.value) {
+          money = choosedMoney.value;
+        } else {
+          money = Number(otherMoney.value);
+        }
+        let data = {
+          cardNumber: userInfo.waterCardNumber,
+          paymentMethod: 1,
+          rechargeAmount: money
+        };
+        await api_index.rechargeApi(data).then(async (res) => {
+          if (res.code == 200) {
+            let data2 = {
+              businessType: 1,
+              businessNo: res.data
+            };
+            await wxPay(data2);
+            otherMoney.value = "";
           }
         });
+      } else {
+        common_vendor.index.showToast({
+          title: "充值间隔20秒,请稍后!",
+          icon: "none"
+        });
+      }
+    }
+    async function wxPay(data) {
+      await api_index.wxPayApi(data).then((res) => {
+        if (res.code == 200) {
+          common_vendor.wx$1.requestPayment({
+            //预支付订单信息
+            // appId: res.data.appId,
+            timeStamp: res.data.timeStamp,
+            //时间戳 
+            nonceStr: res.data.nonceStr,
+            //随机串     
+            package: res.data.package,
+            //prepay_id
+            signType: res.data.signType,
+            //签名算法MD5		
+            paySign: res.data.paySign,
+            //微信签名 
+            success(res2) {
+              if (res2.errMsg == "requestPayment:ok") {
+                console.log("支付成功", res2);
+                common_vendor.index.showToast({
+                  title: "支付成功",
+                  duration: 2e3
+                });
+                common_vendor.index.navigateBack();
+              } else {
+                common_vendor.index.showToast({
+                  title: "支付失败",
+                  duration: 2e3,
+                  icon: "none"
+                });
+              }
+            },
+            fail(res2) {
+              common_vendor.index.showToast({
+                title: "微信支付失败",
+                duration: 2e3,
+                icon: "none"
+              });
+            }
+          });
+        }
       });
     }
+    common_vendor.onUnmounted(() => {
+      clearTimeout(timerId);
+    });
     return (_ctx, _cache) => {
       return {
         a: common_vendor.p({
@@ -109,7 +157,8 @@
             d: item.checked
           };
         }),
-        h: common_vendor.o(($event) => submit())
+        h: common_vendor.unref(payStatus) ? 1 : 0.7,
+        i: common_vendor.o(($event) => submit())
       };
     };
   }

--
Gitblit v1.9.3