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

---
 pages/recharge/index.vue |  105 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 78 insertions(+), 27 deletions(-)

diff --git a/pages/recharge/index.vue b/pages/recharge/index.vue
index ebffff7..a73b815 100644
--- a/pages/recharge/index.vue
+++ b/pages/recharge/index.vue
@@ -1,9 +1,10 @@
 <script setup>
-	import{ ref ,onMounted} from 'vue'
-	import { wxPayApi } from '../../api/index.js'
+	import{ ref ,onMounted,onUnmounted} from 'vue'
+	import { wxPayApi,rechargeApi } from '../../api/index.js'
 	
-	const choosedMoney = ref()
+	const choosedMoney = ref(50)
 	const disabled = ref(true)
+	const userInfo = JSON.parse(uni.getStorageSync('userInfo'))
 	//选择金额
 	const moneyList = ref([
 		{value:50,active:true},
@@ -51,18 +52,52 @@
 	// 	payList.value[index1].checked = true
 	// 	payMethod.value = payList.value[index1].value
 	// }
+	let timerId 
+	let payStatus = ref(true)
 	async function submit(){
-		let money = ''
-		if(disabled.value){
-			money = choosedMoney.value
-		}else{
-			money = otherMoney.value
-		}
-		await wxPayApi({businessType:1,tradeAmount:money}).then((res) =>{
-			console.log('reswxpay',res)
+		if(payStatus.value){
+			payStatus.value = false
+			timerId = setTimeout(()=>{
+				payStatus.value = true
+			},20000)
+			let money = ''
+			if(disabled.value){
+				money = choosedMoney.value
+			}else{
+				money = Number(otherMoney.value)
+			}
+			let data = {
+			        cardNumber:userInfo.waterCardNumber,
+			        paymentMethod:1,
+			        rechargeAmount:money
+			    }
+			//生成订单
+			await rechargeApi(data).then(async(res) =>{
+				if(res.code == 200){
+					let data = {
+						businessType:1,
+						businessNo:res.data
+						}
+					//发起支付
+					await wxPay(data)
+					otherMoney.value = ''
+				}
+			})
 			
-			  //调用微信官方支付接口弹出付款界面,输入密码扣款
-			  wx.requestPayment({
+		}else{
+			uni.showToast({
+				title:'充值间隔20秒,请稍后!',
+				icon:'none'
+			})
+		}
+	}
+	//微信支付
+	async function wxPay(data){
+		
+		await wxPayApi(data).then((res) =>{
+			if(res.code == 200){
+				//调用微信官方支付接口弹出付款界面,输入密码扣款
+				wx.requestPayment({
 				  //预支付订单信息
 				  // appId: res.data.appId,
 				  timeStamp: res.data.timeStamp,     //时间戳 
@@ -70,21 +105,37 @@
 				  package: res.data.package,		//prepay_id
 				  signType: res.data.signType,		//签名算法MD5		
 				  paySign: res.data.paySign ,//微信签名 
-			     success (res) {
-			       if (res.errMsg == "requestPayment:ok"){
-			          console.log('支付成功', res)
-			       }else{
-			          console.log('支付失败')
-			       }
-			     },
-			     fail (res) { 
-			       console.log('支付失败', res)
-			     }
-			  })
+				 success (res) {
+				   if (res.errMsg == "requestPayment:ok"){
+					  console.log('支付成功', res)
+					  uni.showToast({
+						title: '支付成功',
+						duration: 2000,
+					  });
+					  uni.navigateBack()
+				   }else{
+					  uni.showToast({
+						title: '支付失败',
+						duration: 2000,
+						icon:'none'
+					  });
+				   }
+				   
+				 },
+				 fail (res) { 
+				   uni.showToast({
+						title: '微信支付失败',
+						duration: 2000,
+						icon:'none'
+				   });
+				 }
+				})
+			}
 		})
-
-		
 	}
+	onUnmounted(() =>{
+		clearTimeout(timerId)
+	})
 </script>
 <template>
 	<view class="container">
@@ -129,7 +180,7 @@
 					</view>
 				</view>
 			</view>
-			<view class="submit-btn" @click="submit()">立即充值</view>
+			<view :style="{opacity:payStatus ? 1 : 0.7}" class="submit-btn" @click="submit()">立即充值</view>
 		</view>
 	</view>
 </template>

--
Gitblit v1.9.3