jiuyiUniapp/jiuyi2/pages/index/wallet/topUp.vue

120 lines
2.2 KiB
Vue
Raw Normal View History

2024-12-18 15:46:27 +08:00
<script setup>
/**
* 余额充值
*/
import {
reactive
} from 'vue';
import util from '@/common/js/util';
import api from '@/api/index.js';
2025-01-15 23:47:08 +08:00
import {
onLoad,
onReady,
onReachBottom,
onPullDownRefresh
} from '@dcloudio/uni-app'
2024-12-18 15:46:27 +08:00
// 表单
const form = reactive({
2025-01-15 23:47:08 +08:00
totalAmount: '',
})
2025-02-27 14:53:04 +08:00
onLoad((option) => {
if(option.amount) form.totalAmount = option.amount
2024-12-18 15:46:27 +08:00
})
// 充值
function handleSubmit() {
console.log('handleSubmit')
// 验证
util.isAuth({
success: rs => {
payment()
},
})
}
2025-01-15 23:47:08 +08:00
// 调用支付
2024-12-18 15:46:27 +08:00
function payment() {
const data = {
...form
}
2025-01-15 23:47:08 +08:00
if (!data.totalAmount) {
2024-12-18 15:46:27 +08:00
util.alert('金额不正确')
return
}
2025-01-15 23:47:08 +08:00
console.log('payment')
2024-12-18 15:46:27 +08:00
2025-01-15 23:47:08 +08:00
api.mine.recharge({
query: {
...data,
},
2024-12-18 15:46:27 +08:00
}).then(rs => {
2025-01-15 23:47:08 +08:00
console.log('recharge rs', rs)
if (rs.code == 200) {
2024-12-18 15:46:27 +08:00
uni.requestPayment({
provider: 'alipay',
2025-01-16 20:18:22 +08:00
orderInfo: rs.msg,
2024-12-18 15:46:27 +08:00
success: rs => {
console.log('requestPayment', rs)
2025-01-15 23:47:08 +08:00
util.getPurse()
2024-12-18 15:46:27 +08:00
uni.navigateBack()
},
2025-01-15 23:47:08 +08:00
fail: err => {
console.log('fail err', err)
}
2024-12-18 15:46:27 +08:00
})
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
}
</script>
<template>
<view class="appbw">
<!-- -->
<view class="form mtb30 mlr30">
<view class="line ptb20">
<view class="key f36">充值金额</view>
<view class="value mt10">
<view class="rows">
<view class="c333 f40 b"></view>
2025-01-15 23:47:08 +08:00
<input type="text" v-model="form.totalAmount" placeholder="输入金额" />
2024-12-18 15:46:27 +08:00
</view>
</view>
</view>
<view class="line ptb20">
<view class="key f36">充值方式</view>
<view class="value payment mt10">
<view class="list rows">
<image class="wh60" src="/static/shop-alipay-payment.png" mode="aspectFit" />
<view class="f1 mlr20 c333 f30">支付宝</view>
<uni-icons type="circle-filled" color="#20D200" size="40rpx" />
</view>
</view>
</view>
</view>
<view class="footer plr30 shadow bfff">
<view class="btn lg colourful" @click="handleSubmit">充值</view>
</view>
</view>
</template>
<style lang="scss">
// 表单
.form {
.line {
border-bottom: 1rpx solid #ccc;
}
}
</style>