shop_uniapp/bundle/pages/user_payment/user_payment.vue

376 lines
8.2 KiB
Vue
Raw Normal View History

2024-06-06 09:55:01 +08:00
<template>
<view>
<view class="user-payment">
<!-- 充值 -->
<form report-submit="true">
<view class="payment bg-white">
<view class="md normal flex" style="padding: 66rpx 66rpx 0">
充值金额
</view>
<view class="input flex">
<text style="font-size: 46rpx">¥</text>
<input :placeholder="placeholder" type="digit" @focus="setPlaceholder"
@blur="setPlaceholderStatus" :value="number" @input="onInput" />
</view>
<view class="tip muted m-t-20 flex">
提示:当前余额为
<text class="primary">¥{{wallet.user_money || 0}}</text>
</view>
2024-07-09 00:51:32 +08:00
<view class="rule">
2024-07-09 17:57:24 +08:00
{{content}}
2024-07-09 00:51:32 +08:00
</view>
2024-06-06 09:55:01 +08:00
</view>
<button size="lg" class="btn white br60" @tap="rechargeRights">
立即充值
</button>
</form>
<!-- 推荐充值 -->
<view class="fast-payment-container" v-if="rechargeObj.length">
<view class="title bold normal flex">推荐充值</view>
<view class="fast-pay flex flex-wrap">
<view v-for="(item, index) in rechargeObj" :key="index"
class="fast-pay-item bg-white flex-col col-center row-center" @tap="temRecharge(item.id)">
<view class="hot-recharge white" v-if="item.is_recommend">热门充值</view>
<view class="price bold">
2024-08-28 22:45:32 +08:00
<price-format weight="bold" :firstSize="32" :price="item.money"></price-format>
2024-06-06 09:55:01 +08:00
<text class="xxl" style="font-weight: 400">元</text>
</view>
<view class="preferential primary xs">{{item.tips}}</view>
</view>
</view>
</view>
</view>
<!-- 充值成功 -->
<u-popup class="pay-popup" v-model="showPopup" closeable round mode="center">
<view class="content bg-white">
2024-06-20 12:17:24 +08:00
<image class="img-icon" src="https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/icon_success.png"></image>
2024-06-06 09:55:01 +08:00
<view class="xxl bold m-t-10">充值成功</view>
<view v-if="rechargeInfo.give_growth" class="lg" style="margin-top: 50rpx">恭喜您获得 <text
2024-08-30 17:16:32 +08:00
v-if="rechargeInfo.give_growth">+ <text
class="primary">{{rechargeInfo.give_growth}}</text>成长值</text></view>
2024-06-06 09:55:01 +08:00
<button class="br60 btn" type="primary" size="md" @tap="onShowPopup">好的,谢谢</button>
</view>
</u-popup>
<loading-view id="van-toast" v-if="showLoading" backgroundColor="rgba(0, 0, 0, 0)"></loading-view>
2024-07-09 17:57:24 +08:00
<u-modal v-model="show" :title="title" :content='content' :showConfirmButton="true" :showCancelButton="true" @confirm="confirmPay"></u-modal>
2024-06-06 09:55:01 +08:00
<float-tab></float-tab>
</view>
</template>
<script>
import {
rechargeTemplate,
recharge,
getWallet
} from '@/api/user';
import {
prepay
} from '@/api/app';
import {
wxpay
} from '@/utils/pay';
export default {
data() {
return {
navRecharge: ['账户充值', '佣金转入'],
active: 0,
number: '',
placeholder: "0.00",
rechargeObj: [],
showPopup: false,
rechargeInfo: {},
wallet: {},
2024-07-09 17:57:24 +08:00
showLoading: false,
show: false,
title: '提示',
content: '充值参与消费返补活动'
2024-06-06 09:55:01 +08:00
};
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.rechargeTemplateFun();
this.getWalletFun();
},
onUnload() {
uni.$off('payment')
},
methods: {
onShowPopup() {
this.showPopup = !this.showPopup
},
setPlaceholderStatus: function(event) {
if (event.detail.value.length == 0) {
this.placeholder = '0.00'
}
},
setPlaceholder: function() {
this.placeholder = ''
},
getWalletFun() {
getWallet().then(res => {
if (res.code == 1) {
this.wallet = res.data
}
});
},
rechargeTemplateFun() {
rechargeTemplate().then(res => {
if (res.code == 1) {
this.rechargeObj = res.data
}
});
},
rechargeRights() {
const {
number
} = this;
this.rechargeFun({
money: Number(number)
});
},
temRecharge(id) {
this.rechargeFun({
id
});
},
rechargeFun(obj) {
if (!obj.id && obj.money == 0) {
return this.$toast({
title: '请输入金额'
})
}
2024-07-09 17:57:24 +08:00
uni.showModal({
title: this.title,
content:this.content,
success: (res) => {
if (res.confirm) {
this.showLoading = true
recharge(obj).then(({ code, data, msg }) => {
if (code != 1) throw new Error(msg)
this.rechargeInfo = data
uni.$on('payment', params => {
setTimeout(() => {
if (params.result) {
this.$toast({ title: "支付成功" })
this.onShowPopup();
this.getWalletFun();
} else {
this.$toast({ title: "支付失败" })
}
2024-07-12 17:48:22 +08:00
this.number = ''
this.placeholder = '0.00'
2024-07-09 17:57:24 +08:00
}, 500)
})
uni.navigateTo({
url: `/pages/payment/payment?from=${'recharge'}&order_id=${data.id}`
})
}).catch(err => {
console.log(err)
}).finally(() => {
this.showLoading = false
})
}
}
})
},
// rechargeFun(obj) {
// if (!obj.id && obj.money == 0) {
// return this.$toast({
// title: '请输入金额'
// })
// }
2024-06-06 09:55:01 +08:00
2024-07-09 17:57:24 +08:00
// this.showLoading = true
2024-06-06 09:55:01 +08:00
2024-07-09 17:57:24 +08:00
// recharge(obj).then(({ code, data, msg }) => {
// if (code != 1) throw new Error(msg)
2024-06-06 09:55:01 +08:00
2024-07-09 17:57:24 +08:00
// this.rechargeInfo = data
// uni.$on('payment', params => {
// setTimeout(() => {
// if (params.result) {
// this.number = 0
// this.$toast({ title: "支付成功" })
// this.onShowPopup();
// this.getWalletFun();
// } else {
// this.$toast({ title: "支付失败" })
// }
// }, 500)
// })
2024-06-06 09:55:01 +08:00
2024-07-09 17:57:24 +08:00
// uni.navigateTo({
// url: `/pages/payment/payment?from=${'recharge'}&order_id=${data.id}`
// })
// }).catch(err => {
// console.log(err)
// }).finally(() => {
// this.showLoading = false
// })
// },
2024-06-06 09:55:01 +08:00
checkInputText: function(text) {
var reg = /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;
if (reg.test(text)) {
//正则匹配通过,提取有效文本
text = text.replace(reg, '$2$3$4');
} else {
//正则匹配不通过,直接清空
text = '';
}
return text; //返回符合要求的文本(为数字且最多有带2位小数)
},
onInput(e) {
let number = e.detail.value;
number = this.checkInputText(number);
this.number = number
}
}
};
</script>
<style lang="scss">
.user-payment {
padding: 20rpx 30rpx;
.payment {
text-align: center;
border-radius: 20rpx;
overflow: hidden;
padding-bottom: 74rpx;
2024-07-09 00:51:32 +08:00
.rule {
text-align: left;
margin: 25rpx 66rpx;;
2024-07-09 17:57:24 +08:00
font-weight: bold;
2024-07-09 00:51:32 +08:00
}
2024-06-06 09:55:01 +08:00
.nav {
margin: 20rpx 95rpx 80rpx;
.item {
flex: 1;
.line {
width: 110rpx;
height: 2px;
}
}
}
.line {
width: 110rpx;
height: 2px;
}
.input {
margin-left: 66rpx;
margin-top: 35rpx;
margin-right: 30rpx;
input {
height: 94rpx;
text-align: left;
font-size: 66rpx;
margin-left: 30rpx;
}
border-bottom: $-solid-border;
}
.tip {
margin: 25rpx 66rpx;
}
}
.btn {
background: linear-gradient(79deg, rgba(249, 95, 47, 1) 0%, rgba(255, 44, 60, 1) 100%);
margin: 70rpx 0 30rpx;
}
.fast-payment-container {
margin-top: 72rpx;
.title {
font-size: 38rpx;
line-height: 53rpx;
}
.fast-pay {
margin-top: 40rpx;
2024-08-30 17:16:32 +08:00
display: grid;
grid-template-columns: repeat(4, 22%);
grid-row-gap: 24rpx;
justify-content: space-between;
2024-06-06 09:55:01 +08:00
.fast-pay-item {
position: relative;
2024-08-28 22:45:32 +08:00
height: 130rpx;
2024-08-30 17:16:32 +08:00
line-height: 130rpx;
2024-06-06 09:55:01 +08:00
border-radius: 10rpx;
2024-08-30 17:16:32 +08:00
2024-06-06 09:55:01 +08:00
.hot-recharge {
position: absolute;
padding: 2rpx 10rpx;
height: 30rpx;
background: linear-gradient(180deg, #FF2C3C 0%, #F95F2F 100%);
border-radius: 0 20rpx 0 20rpx;
font-size: 20rpx;
top: 0;
right: 0;
}
.price {
font-size: 42rpx;
line-height: 50rpx;
}
.preferential {
line-height: 32rpx;
}
}
}
}
}
.pay-popup {
.content {
padding: 40rpx 0;
text-align: center;
width: 560rpx;
border-radius: 20rpx;
}
.img-icon {
width: 112rpx;
height: 112rpx;
display: inline-block;
}
.btn {
margin: 80rpx 60rpx 0;
}
}
</style>