From 440b4ab9d4278d3f9c13b004d2c2289f45254cbc Mon Sep 17 00:00:00 2001
From: Liuyi <candymxq888@outlook.com>
Date: 星期二, 19 十一月 2024 17:29:06 +0800
Subject: [PATCH] 添加积分记录,修改位置获取

---
 pages/scanWater/index.vue |   77 ++++++++++++++++++++++++--------------
 1 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/pages/scanWater/index.vue b/pages/scanWater/index.vue
index 57d4a94..ab6ba91 100644
--- a/pages/scanWater/index.vue
+++ b/pages/scanWater/index.vue
@@ -28,7 +28,7 @@
 	const payMethod = ref(2)
 	const payList = ref([
 		// {text:"支付宝支付",value:1,checked:true,img:'../../static/images/recharge/pay.png'},
-		{text:"微信支付",value:2,checked:true,img:'../../static/images/recharge/wx.png'},
+		{text:"微信",value:2,checked:true,img:'../../static/images/recharge/wx.png'},
 		{text:"余额",value:1,checked:false,img:'../../static/images/recharge/balance.png'},
 	])
 	function choosePay(index1){
@@ -42,35 +42,47 @@
 		console.log('index',index1,payMethod.value)
 	}
 	async function submit(){
+		//余额支付
 		if(payMethod.value == 1){
-			let data = {
-				payType:payMethod.value,
-				card:JSON.parse(uni.getStorageSync('userInfo')).waterCardNumber,
-				amount:choosedMoney.value,
-				sn:facilityCode.value
-				}
-				//余额支付回
-			await buyWaterApi(data).then((res) =>{
-				console.log('余额支付回调',res,'传参',data)
-				if(res.code == 200){
-						uni.navigateTo({
-							url:'/pages/scanSuccess/index'
-						})
-					}else{
-						uni.showToast({
-							title:'支付失败!',
-							icon:'none'
-						})
+			if(choosedMoney.value > Number(userBalance.value)){
+				uni.showToast({
+					title:'水卡余额不足',
+					icon:'none'
+				})
+			}else{
+				let data = {
+					payType:payMethod.value,
+					card:JSON.parse(uni.getStorageSync('userInfo')).waterCardNumber,
+					amount:choosedMoney.value,
+					sn:facilityCode.value
 					}
-			})
+					//余额支付回
+				await buyWaterApi(data).then((res) =>{
+					console.log('余额支付回调',res,'传参',data)
+					if(res.code == 200){
+							uni.navigateTo({
+								url:'/pages/scanSuccess/index'
+							})
+						}else if(res.code == 300){
+							uni.showToast({
+								title:res.msg,
+								icon:'none'
+							})
+						}else{
+							uni.showToast({
+								title:'支付失败,联系管理员',
+								icon:'none'
+							})
+						}
+				})
+			}
+			//微信支付
 		}else if(payMethod.value == 2){
 			let data = {
 				businessType:3,
 				tradeAmount:choosedMoney.value,
 				facilityCode:facilityCode.value,
-				}
-				
-				console.log('data',data)
+			}
 			await wxPayApi(data).then((res) =>{
 				console.log('微信支付回调',res,'传参',data)
 				if(res.code == 200){
@@ -86,16 +98,12 @@
 					 success (res) {
 					   if (res.errMsg == "requestPayment:ok"){
 						  console.log('支付成功', res)
-						  uni.showToast({
-							title: '支付成功',
-							duration: 2000,
-						  });
 						 uni.navigateTo({
 						 	url:'/pages/scanSuccess/index'
 						 })
 					   }else{
 						  uni.showToast({
-							title: '支付失败',
+							title: '微信支付失败',
 							duration: 2000,
 							icon:'none'
 						  });
@@ -109,6 +117,18 @@
 					   });
 					 }
 					})
+				}else if(res.code == 300){
+					uni.showToast({
+						title:res.msg,
+						duration: 2000,
+						icon:'none'
+					});
+				}else{
+					uni.showToast({
+						title:'微信支付失败',
+						duration: 2000,
+						icon:'none'
+					});
 				}
 			})
 		}
@@ -116,6 +136,7 @@
 	const facilityCode = ref()
 	onLoad((option) =>{
 		facilityCode.value = option.facilityCode
+		console.log('小程序扫码取水','option.facilityCode',option.facilityCode,'facilityCode',facilityCode.value)
 	})
 	//设置水价及支付方式
 	async function getWaterPrice(){

--
Gitblit v1.9.3