From 53dc2bac460d2ff210aa9523717753ae1fd2c159 Mon Sep 17 00:00:00 2001 From: Liuyi <candymxq888@outlook.com> Date: 星期二, 26 十一月 2024 17:27:44 +0800 Subject: [PATCH] 添加运维端首页 --- pages/scanWater/index.vue | 145 +++++++++++++++++++++++------------------------- 1 files changed, 70 insertions(+), 75 deletions(-) diff --git a/pages/scanWater/index.vue b/pages/scanWater/index.vue index 3009f65..ab6ba91 100644 --- a/pages/scanWater/index.vue +++ b/pages/scanWater/index.vue @@ -1,6 +1,6 @@ <script setup> import{ ref ,onMounted} from 'vue' - import { wxPayApi,buyWaterApi } from '../../api/index.js' + import { wxPayApi,buyWaterApi,getPriceBySnApi } from '../../api/index.js' import { onLoad } from "@dcloudio/uni-app" const choosedMoney = ref(1) @@ -22,23 +22,13 @@ }) moneyList.value[index1].active = true choosedMoney.value = moneyList.value[index1].value - // if(index1 == 5){ - // disabled.value = false - // choosedMoney.value = '' - // }else{ - // choosedMoney.value = moneyList.value[index1].value - // otherMoney.value = '' - // disabled.value = true - // } } - //输入金额 - // const otherMoney = ref() //支付方式 const userBalance = ref(JSON.parse(uni.getStorageSync('userInfo')).balance) 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){ @@ -52,44 +42,49 @@ console.log('index',index1,payMethod.value) } async function submit(){ - // let money = '' - // if(disabled.value){ - // money = choosedMoney.value - // }else{ - // money = Number(otherMoney.value) - // } + //余额支付 if(payMethod.value == 1){ - let data = { - payType:payMethod.value, - card:JSON.parse(uni.getStorageSync('userInfo')).waterCardNumber, - amount:choosedMoney.value, - // sn:1060003979 - 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:'1066012684', facilityCode:facilityCode.value, - } - - console.log('data',data) + } await wxPayApi(data).then((res) =>{ - console.log('微信',res,'data',data) + console.log('微信支付回调',res,'传参',data) if(res.code == 200){ //调用微信官方支付接口弹出付款界面,输入密码扣款 wx.requestPayment({ @@ -103,21 +98,16 @@ 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' }); } - }, fail (res) { uni.showToast({ @@ -127,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' + }); } }) } @@ -134,7 +136,27 @@ const facilityCode = ref() onLoad((option) =>{ facilityCode.value = option.facilityCode + console.log('小程序扫码取水','option.facilityCode',option.facilityCode,'facilityCode',facilityCode.value) }) + //设置水价及支付方式 + async function getWaterPrice(){ + await getPriceBySnApi(facilityCode.value).then((res) =>{ + moneyList.value.forEach((item,index) =>{ + item.value = ((index + 1) * res.data.price).toFixed(1) + item.volume = ((index + 1) * res.data.yield).toFixed(1) + }) + choosedMoney.value = res.data.price + console.log('水价设置回调',res,'传参',facilityCode.value) + }) + let waterCardNumber = JSON.parse(uni.getStorageSync('userInfo')).waterCardNumber + if(!waterCardNumber){ + payList.value.splice(1,1) + } + } + onMounted(async() =>{ + await getWaterPrice() + }) + </script> <template> <view class="container"> @@ -155,15 +177,6 @@ </block> </view> </view> - <!-- <view class="other-money"> - <view class="money-title"> - <view class="title-icon"></view> - <view class="title-text">其他金额</view> - </view> - <view class="money-input"> - <input :disabled = 'disabled' :focus = '!disabled' placeholder="请输入其他金额" v-model="otherMoney"/> - </view> - </view> --> <view class="pay-methods"> <view class="money-title"> <view class="title-icon"></view> @@ -242,24 +255,6 @@ } } } - // .other-money{ - // width: 100%; - // height:164rpx; - // margin-top:58rpx; - // .money-input{ - // margin:40rpx auto 0; - // width:calc(100% - 40rpx); - // height: 80rpx; - // box-sizing: border-box; - // border-radius:8rpx; - // border: 2rpx solid #75C8EB; - // input{ - // width:94%; - // height: 80rpx; - // margin-left:6%; - // } - // } - // } .pay-methods{ width: 100%; margin-top:58rpx; -- Gitblit v1.9.3