lanan-old/lanan-master-uniapp/pages/tapBar/mine/Recharge.vue

184 lines
4.2 KiB
Vue
Raw Normal View History

2024-07-17 14:16:22 +08:00
<template>
<view class="container">
<view class="cont-top">
<view class="top-left">充值金额:</view>
<view class="top-right">
<!-- @input="onInput" -->
<input type="number" placeholder="请输入充值金额" v-model="inputValue" >
</view>
</view>
<view class="cont-box">
<view :class="{'indexbox' : actindex == index}" class="box" v-for="(item,index) in num " :key="index" @click="getindex(index,item.text)">
<text>{{item.text}}</text>
</view>
</view>
<view class="anniu" @click="getpayment">
<text>点击充值</text>
</view>
</view>
</template>
<script>
export default {
data(){
return{
inputValue: '',
actindex:'',
num:[
{text:'500'},
{text:'1000'},
{text:'1500'},
{text:'2000'},
{text:'2500'},
{text:'3000'},
]
}
},
methods:{
getindex(index,text){
this.actindex = index
this.inputValue = text
},
onInput(event) {
const regex = /^\d*$/; // 只允许输入数字
if (!regex.test(event.target.value)) {
this.inputValue = this.inputValue.replace(/\D/g, ''); // 移除非数字字符
}
},
// 创建订单 吊起支付
async getpayment(){
const res = await this.$request({
method:'post',
url:'/orderApi/createOrder',
data: {
goodsId: 88888,
goodsType: 'cz',
balance:0,
balanceCz: this.inputValue*100
}
})
console.log(res);
this.orderid = res.data
const ress = await this.$request({
url:'/payApi/prepayment?type=jsapi'+'&orderId='+this.orderid,
})
console.log(ress);
wx.requestPayment({
timeStamp: ress.timeStamp, // 时间戳从1970年1月1日00:00:00至今的秒数即当前的时间
nonceStr: ress.nonceStr, // 随机字符串长度为32个字符以下。
package: ress.package, // 统一下单接口返回的 prepay_id 参数值格式如“prepay_id=*”
signType: ress.signType, // 签名算法类型,默认为 MD5支持RSA等其他加密算法
paySign: ress.paySign, // 签名,详见签名生成算法
success: function (res) {
console.log('成功',res);
if( res.errMsg = 'requestPayment:ok'){
uni.showToast({
title:'支付成功'
})
uni.navigateTo({
url:'/subInspectionPages/Paymentsuccessful/Paymentsuccessful'
})
}
// 支付成功后的回调函数, res.errMsg = 'requestPayment:ok'
},
fail: function (res) {
const resx = this.$request({
url:'/orderApi/cancelPay'
})
uni.showToast({
title:'支付失败'
})
console.log(resx);
// 支付失败或取消支付后的回调函数, res.errMsg = 'requestPayment:fail cancel' 取消支付res.errMsg = 'requestPayment:fail (detail error message)'
}
})
// wx.requestPayment(ress)
},
}
}
</script>
<style scoped lang="scss">
.container{
width: 100%;
height:calc(100vh);
box-sizing: border-box;
background-color: #242A38;
padding-top: 40px;
}
.cont-top{
width: 95%;
margin: 0 auto;
box-sizing: border-box;
overflow: hidden;
padding-bottom: 10px;
display: flex;
align-items: center;
border-bottom: 1px solid #FFE3AD;
}
.top-right{
width: 70%;
input{
width: 100%;
color: white;
font-size: 18px;
font-weight: 600;
}
}
.top-left{
color: #FFE3AD;
font-size: 18px;
font-weight: 600;
margin-right: 5px;
}
.cont-box{
margin: 0 auto;
margin-top: 20px;
width: 95%;
display: flex;
flex-wrap: wrap;
}
.box{
width: 30%;
height: 40px;
border-radius: 8px;
border: 1px solid #FFE3AD;
margin-top: 10px;
margin-right: 11px;
display: flex;
justify-content: center;
align-items: center;
font-size: 18px;
color: white;
font-weight: bold;
}
.anniu{
width: 80%;
height: 40px;
border-radius: 6px;
border: 1px solid #FFE3AD;
background-color: #FFE3AD ;
margin: 0 auto;
margin-top: 40px;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 18px;
font-weight: bold;
}
.indexbox{
background: #FFE3AD;
}
</style>