OfficeApp/subpkg/topUp/topUp.vue

315 lines
8.8 KiB
Vue
Raw Normal View History

2023-07-19 11:58:18 +08:00
<template>
<view class="">
<view class="info">
<view class="bg"></view>
<view class="card">
<view class="title">充值信息</view>
<view class="item">
<text>充值账户</text>
2023-08-03 17:44:02 +08:00
<text>{{$store.state.app.userInfo.company.company_name||''}}</text>
2023-07-19 11:58:18 +08:00
</view>
</view>
</view>
<view class="price">
<view class="title">充值金额</view>
<view class="tab">
2023-07-20 13:48:26 +08:00
<view class="item" :class="index==changeMoney?'active':''" @click="changePrice(index)"
2023-07-20 10:22:50 +08:00
v-for="(item, index) in priceList" :key="index">{{item}}</view>
2023-07-19 11:58:18 +08:00
</view>
2023-07-20 13:48:26 +08:00
<input v-if="priceList[changeMoney]=='自定义'" class="input" type="digit" placeholder="输入充值金额(元)" v-model="payMoney.money" />
2023-07-20 17:40:13 +08:00
<button class="btn" @click="pay">充值</button>
2023-07-19 11:58:18 +08:00
</view>
2023-07-25 08:11:50 +08:00
<!-- <view class="tip">
2023-07-19 11:58:18 +08:00
<view class="title">注意事项</view>
2023-07-24 16:44:23 +08:00
<view class="text">充值后帐户的金额不能提现可用于商城消费使用佣金导入账户之后不能再次导出不可提现账户充值出现问题可联系商城客服也可拨打商城客服热线<text @click="copyPhone('4008888888')">4008888888</text>
2023-07-20 10:22:50 +08:00
</view>
2023-07-25 08:11:50 +08:00
</view> -->
2023-07-19 11:58:18 +08:00
</view>
</template>
<script>
import { recharge, payWay, payPrepay, wechatJsConfig, payStatus } from "@/api/pay.js"
2023-07-24 16:01:38 +08:00
import { userInfo } from "@/api/oaUser.js"
2023-07-20 17:40:13 +08:00
import { debounce, throttle } from 'lodash'
import { Toast } from '@/libs/uniApi.js'
2023-07-20 10:22:50 +08:00
export default {
data() {
return {
2023-07-25 10:47:29 +08:00
priceList: ['10元','50元','100元','500元','1000元','5000元','10000元', '自定义'],
2023-07-20 17:40:13 +08:00
changeMoney: -1,
2023-07-20 10:22:50 +08:00
payMoney: {
money: ''
2023-07-20 17:40:13 +08:00
},
payTimer: null,
timeCount: 5,
2023-07-20 10:22:50 +08:00
}
},
2023-07-25 14:41:50 +08:00
// 点击充值记录
onNavigationBarButtonTap(res){
if (res.index === 0) {
uni.navigateTo({
url: '/subpkg/topUpList/topUpList'
})
}
},
2023-07-24 16:44:23 +08:00
onLoad() {},
2023-07-20 10:22:50 +08:00
onShow() {},
methods: {
2023-07-20 13:48:26 +08:00
changePrice(index){
2023-07-20 17:47:44 +08:00
if(this.changeMoney == index)this.changeMoney = -1;
else this.changeMoney = index;
2023-07-20 13:48:26 +08:00
if(this.priceList[index]=='自定义')this.payMoney.money = '';
else this.payMoney.money = this.priceList[index].split('元')[0];
},
2023-07-20 10:22:50 +08:00
//充值
2023-07-20 17:40:13 +08:00
pay(){
2023-07-20 17:47:44 +08:00
if(!this.payMoney.money)return Toast('请先填写充值金额!')
if(this.payMoney.money<=0)return Toast('充值金额不能小于0!')
2023-07-20 17:40:13 +08:00
if(!this.payTimer){
this.goRecharge();
this.payTimer = setInterval(()=>{
this.timeCount--;
if(this.timeCount<=0){
clearInterval(this.payTimer);
this.payTimer = null;
this.timeCount = 5;
}
}, 1000)
}
else Toast(this.timeCount+'秒后再支付!')
},
2023-07-25 16:45:04 +08:00
goRecharge() {
2023-07-20 10:22:50 +08:00
// console.log(obj);
uni.showLoading({
2023-07-25 16:45:04 +08:00
title:'获取支付信息',
success: async () => {
let { data } = await recharge({
money: this.payMoney.money
});
let res = await payWay({
order_id: data.order_id,
from: data.from,
})
// console.log(res);
let res1 = await payPrepay({
from: data.from,
order_id: data.order_id,
pay_way: res.data.lists[0].pay_way
})
// console.log(res1.data, res1.data.config.package.split('=')[1]);
let obj = {
"appid": res1.data.config.appId, // 微信开放平台 - 应用 - AppId注意和微信小程序、公众号 AppId 可能不一致
"noncestr": res1.data.config.nonceStr, // 随机字符串
"package": res1.data.config.package, // 固定值
"partnerid": res1.data.config.partnerid, // 微信支付商户号
"prepayid": res1.data.config.package.split('=')[1], // 统一下单订单号
"timestamp": res1.data.config.timestamp, // 时间戳(单位:秒)
"sign": res1.data.config.paySign
}
2023-07-20 10:22:50 +08:00
uni.getProvider({
service: 'payment',
success: (paymentList) => {
// console.log(paymentList);
uni.hideLoading();
uni.showLoading({
title:'微信支付中'
})
uni.requestPayment({
provider: 'wxpay',
// orderInfo: res1.data.config,
orderInfo: obj,
success: (e) => {
2023-07-25 16:45:04 +08:00
// console.log('成功', e);
2023-07-20 10:22:50 +08:00
uni.hideLoading();
payStatus({
order_id: data.order_id,
from: data.from,
}).then((status)=>{
uni.showToast({
2023-07-24 16:01:38 +08:00
icon:status.data.pay_status?'success':'none',
title: status.data.pay_status?'支付成功':'支付失败'
})
userInfo().then(user=>{
this.$store.commit('setUserInfo', user.data);
})
2023-07-20 10:22:50 +08:00
})
},
fail: (e) => {
uni.hideLoading();
uni.showToast({
icon:'error',
title: '支付失败!'
2023-07-20 10:22:50 +08:00
})
},
2023-07-25 16:45:04 +08:00
complete: () => {
this.payMoney.money = '';
},
2023-07-20 10:22:50 +08:00
});
}
})
},
fail: (e) => {
uni.showToast({
icon:'error',
title:'请先安装微信'
})
}
})
}
},
onPullDownRefresh() {
2023-07-19 11:58:18 +08:00
uni.stopPullDownRefresh()
}
}
</script>
<style lang="scss">
2023-07-20 10:22:50 +08:00
page {
2023-07-19 11:58:18 +08:00
background-color: #fff;
}
2023-07-20 10:22:50 +08:00
.info {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
2023-07-21 14:57:11 +08:00
height: 250rpx;
2023-07-20 10:22:50 +08:00
.bg {
2023-07-25 17:44:18 +08:00
background-color: $theme-oa-color;
2023-07-21 14:57:11 +08:00
height: 170rpx;
2023-07-20 10:22:50 +08:00
width: 100vw;
border-radius: 0rpx 0rpx 28rpx 28rpx;
position: absolute;
top: 0;
left: 0;
}
.card {
width: 694rpx;
2023-08-08 11:31:49 +08:00
min-height: 180rpx;
2023-07-20 10:22:50 +08:00
background: #FFFFFF;
margin-top: 38.55rpx;
box-shadow: 0rpx 0rpx 18rpx 2rpx rgba(50, 116, 249, 0.1);
border-radius: 14rpx 14rpx 14rpx 14rpx;
opacity: 1;
padding: 31.5rpx 28rpx;
display: flex;
flex-direction: column;
2023-08-08 11:31:49 +08:00
justify-content: space-around;
2023-07-20 10:22:50 +08:00
position: absolute;
top: 0;
.title {
font-size: 32rpx;
font-weight: 600;
color: #333333;
padding-bottom: 10rpx;
}
.item {
display: flex;
2023-08-08 11:31:49 +08:00
justify-content: space-around;
2023-07-20 10:22:50 +08:00
font-size: 32rpx;
font-weight: 400;
color: #333333;
2023-08-09 11:18:45 +08:00
text:nth-child(1){
flex-shrink: 0;
margin-right: 18rpx;
}
2023-07-20 10:22:50 +08:00
}
}
2023-07-19 11:58:18 +08:00
}
2023-07-20 10:22:50 +08:00
.price {
2023-07-19 11:58:18 +08:00
display: flex;
flex-direction: column;
2023-07-20 10:22:50 +08:00
padding: 0 28rpx;
2023-08-09 11:18:45 +08:00
margin-top: 50rpx;
2023-07-20 10:22:50 +08:00
.title {
2023-07-19 11:58:18 +08:00
font-size: 32rpx;
font-weight: 600;
color: #333333;
2023-07-20 10:22:50 +08:00
line-height: 39rpx;
margin-bottom: 42rpx;
2023-07-19 11:58:18 +08:00
}
2023-07-20 10:22:50 +08:00
.tab {
2023-07-19 11:58:18 +08:00
display: flex;
2023-07-20 10:22:50 +08:00
flex-wrap: wrap;
justify-content: space-evenly;
.item {
width: 217rpx;
height: 131rpx;
margin-bottom: 20rpx;
border-radius: 7rpx 7rpx 7rpx 7rpx;
border: 2rpx solid #F5F5F5;
display: flex;
justify-content: center;
align-items: center;
font-size: 32rpx;
font-weight: 500;
line-height: 32rpx;
}
.active {
2023-07-25 17:44:18 +08:00
border: 2rpx solid $theme-oa-color;
color: $theme-oa-color;
2023-07-20 10:22:50 +08:00
}
}
.input {
width: 100%;
height: 112rpx;
background: #F5F5F5;
border-radius: 56rpx 56rpx 56rpx 56rpx;
opacity: 1;
padding: 0 45.56rpx;
box-sizing: border-box;
font-size: 28rpx;
2023-07-19 11:58:18 +08:00
font-weight: 400;
2023-07-20 10:22:50 +08:00
color: #333;
line-height: 35rpx;
2023-07-19 11:58:18 +08:00
}
2023-07-20 10:22:50 +08:00
.btn {
width: 694rpx;
height: 84rpx;
margin-top: 73.6rpx;
2023-07-25 17:44:18 +08:00
background: $theme-oa-color;
2023-07-20 10:22:50 +08:00
box-shadow: 0rpx 14rpx 44rpx 2rpx #E9EFF5;
border-radius: 42rpx 42rpx 42rpx 42rpx;
2023-07-19 11:58:18 +08:00
display: flex;
justify-content: center;
align-items: center;
font-size: 32rpx;
2023-07-20 10:22:50 +08:00
font-weight: 400;
color: #FFFFFF;
2023-07-19 11:58:18 +08:00
}
}
2023-07-20 10:22:50 +08:00
.tip {
2023-07-19 11:58:18 +08:00
display: flex;
flex-direction: column;
padding: 0 28rpx;
margin-top: 84rpx;
2023-07-20 10:22:50 +08:00
.title {
2023-07-19 11:58:18 +08:00
font-size: 32rpx;
font-weight: 500;
2023-07-25 17:44:18 +08:00
color: $theme-oa-color;
2023-07-19 11:58:18 +08:00
line-height: 32rpx;
margin-bottom: 21rpx;
}
2023-07-20 10:22:50 +08:00
.text {
2023-07-19 11:58:18 +08:00
font-size: 28rpx;
font-weight: 400;
2023-07-20 10:22:50 +08:00
color: rgba(0, 0, 0, 0.6);
2023-07-19 11:58:18 +08:00
line-height: 42rpx;
-webkit-background-clip: text;
}
2023-07-20 10:22:50 +08:00
}
</style>