wallet:接入钱包充值

pull/3/head
YunaiV 2023-09-30 18:54:26 +08:00
parent 5981432ff7
commit 03ceb0bcf3
2 changed files with 78 additions and 188 deletions

View File

@ -9,3 +9,13 @@ export function getPayWallet() {
export function getWalletTransactionPage(data) {
return request.get("app-api/pay/wallet-transaction/page", data);
}
// 获得钱包充值套餐列表
export function getWalletRechargePackageList() {
return request.get("app-api/pay/wallet-recharge-package/list");
}
// 创建钱包充值记录(发起充值)
export function createWalletRecharge(data) {
return request.post("app-api/pay/wallet-recharge/create", data);
}

View File

@ -4,32 +4,38 @@
<view class="payment-top acea-row row-column row-center-wrapper">
<span class="name">我的余额</span>
<view class="pic">
<span class="pic-font">{{ userInfo.nowMoney || 0 }}</span>
<span class="pic-font">{{ fen2yuan(wallet.balance || 0) }}</span>
</view>
</view>
<view class="payment">
<view class="nav acea-row row-around row-middle">
<view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index" @click="navRecharges(index)">{{item}}</view>
</view>
<!-- 充值 -->
<view class='tip picList' v-if='!active'>
<view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic === index ? 'pic-box-color-active' : ''"
v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)">
<view class="pic-number-pic">
{{ item.price }}<span class="pic-number"> </span>
{{ fen2yuan(item.payPrice) }}<span class="pic-number"> </span>
</view>
<view class="pic-number">赠送{{ item.giveMoney }} </view>
<view class="pic-number">赠送{{ fen2yuan(item.bonusPrice) }} </view>
</view>
<view class="pic-box pic-box-color acea-row row-center-wrapper" :class="parseFloat(activePic)===parseFloat(picList.length)?'pic-box-color-active':''" @click="picCharge(picList.length)">
<input type="number" placeholder="其他" v-model="money" :maxlength="50000" class="pic-box-money pic-number-pic uni-input" :class="parseFloat(activePic) === parseFloat(picList.length) ? 'pic-box-color-active' : ''" />
<view class="pic-box pic-box-color acea-row row-center-wrapper" :class="parseFloat(activePic)===parseFloat(picList.length)?'pic-box-color-active':''"
@click="picCharge(picList.length)">
<input type="number" placeholder="其他" v-model="money" :maxlength="50000" class="pic-box-money pic-number-pic uni-input"
:class="parseFloat(activePic) === parseFloat(picList.length) ? 'pic-box-color-active' : ''" />
</view>
<view class="tips-box">
<view class="tips mt-30">注意事项</view>
<view class="tips-samll" v-for="item in rechargeAttention" :key="item">
{{ item }}
</view>
{{ item }}
</view>
</view>
</view>
<view class="tip" v-else>
<button class='but' formType="submit"> 立即充值 </button>
</view>
<!-- 佣金提现 -->
<view class="tip" v-else>
<view class='input'><text></text><input placeholder="0.00" type='number' placeholder-class='placeholder' :value="number"
name="number"></input></view>
<view class="tips-title">
@ -42,60 +48,45 @@
{{ item }}
</view>
</view>
</view>
<button class='but' formType="submit"> {{active ? '立即转入': '立即充值' }}</button>
<button class='but' formType="submit"> 立即转入 </button>
</view>
</view>
</form>
<!-- #ifdef MP -->
<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
<!-- #endif -->
<home></home>
</view>
</template>
<script>
import {
rechargeRoutine,
rechargeWechat,
getRechargeApi,
transferIn,
appWechat
} from '@/api/user.js';
import { wechatQueryPayResult } from '@/api/order.js';
import {
toLogin
} from '@/libs/login.js';
import {
mapGetters
} from "vuex";
// #ifdef MP
import authorize from '@/components/Authorize';
// #endif
import { transferIn } from '@/api/user.js';
import * as WalletApi from '@/api/pay/wallet.js';
import * as Util from '@/utils/util.js';
import { toLogin } from '@/libs/login.js';
import { mapGetters } from "vuex";
import home from '@/components/home';
export default {
components: {
// #ifdef MP
authorize,
// #endif
home
},
data() {
let that = this;
return {
now_money: 0,
wallet: {},
now_money: 0,
navRecharge: ['账户充值', '佣金转入'],
active: 0,
number: '',
placeholder: "0.00",
from: '',
isAuto: false, //
isShowAuth: false, //
picList: [],
activePic: 0,
money: "",
numberPic: '',
rechar_id: 0,
rechargeAttention: []
rechar_id: 0, //
rechargeAttention: [
'1、充值金额最少为 1 元',
'2、充值后只能用于消费',
'3、提现金额需要有手续费',
'4、提现到账需要 2~3 天时间'
]
};
},
computed: mapGetters(['isLogin', 'systemPlatform','userInfo']),
@ -110,23 +101,13 @@
}
},
onLoad(options) {
// #ifdef H5
this.from = this.$wechat.isWeixin() ? "public" : "weixinh5";
// #endif
if (true) {
alert('充值功能暂未实现!预期 10 月份');
if (!this.isLogin) {
toLogin();
return;
}
if (this.isLogin) {
this.getRecharge();
} else {
toLogin();
}
this.getRecharge();
},
methods: {
/**
* 选择金额
*/
@ -134,47 +115,42 @@
this.activePic = idx;
if (item === undefined) {
this.rechar_id = 0;
this.numberPic = "";
} else {
this.money = "";
this.rechar_id = item.id;
this.numberPic = item.price;
}
},
/**
* 充值额度选择
*/
getRecharge() {
getRechargeApi()
.then(res => {
this.picList = res.data.rechargeQuota;
if (this.picList[0]) {
this.rechar_id = this.picList[0].id;
this.numberPic = this.picList[0].price;
}
this.rechargeAttention = res.data.rechargeAttention || [];
})
.catch(res => {
this.$dialog.toast({
mes: res
});
});
},
//
WalletApi.getPayWallet().then(res=>{
this.wallet = res.data;
})
//
WalletApi.getWalletRechargePackageList().then(res => {
this.picList = res.data;
if (this.picList.length > 0) {
this.rechar_id = this.picList[0].id;
}
}).catch(res => {
this.$dialog.toast({
mes: res
});
});
},
onLoadFun: function() {
this.getRecharge();
},
//
authColse: function(e) {
this.isShowAuth = e
},
navRecharges: function(index) {
this.active = index;
},
/*
/**
* 用户充值
*/
submitSub: function(e) {
@ -223,7 +199,7 @@
title: '正在支付',
})
let money = parseFloat(this.money);
if (this.rechar_id == 0) {
if (this.rechar_id === 0) {
if (Number.isNaN(money)) {
return that.$util.Tips({
title: '充值金额必须为数字'
@ -231,131 +207,35 @@
}
if (money <= 0) {
return that.$util.Tips({
title: '充值金额不能为0'
title: '充值金额不能为 0'
});
}
if (money > 50000) {
return that.$util.Tips({
title: '充值金额最大值为50000'
title: '充值金额最大值为 50000'
});
}
} else {
money = this.numberPic
}
// #ifdef MP
rechargeRoutine({
price: money,
type: 0,
rechar_id: this.rechar_id
WalletApi.createWalletRecharge({
payPrice: money ? money * 100 : undefined,
packageId: this.rechar_id
}).then(res => {
uni.hideLoading();
let jsConfig = res.data.data.jsConfig;
uni.requestPayment({
timeStamp: jsConfig.timeStamp,
nonceStr: jsConfig.nonceStr,
package: jsConfig.packages,
signType: jsConfig.signType,
paySign: jsConfig.paySign,
success: function(res) {
that.$store.commit("changInfo", {
amount1: 'nowMoney',
amount2: that.$util.$h.Add(value, that.userinfo.nowMoney)
});
//that.$set(that, 'userinfo.nowMoney', that.$util.$h.Add(value, that.userinfo.nowMoney));
return that.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: 5,
url: '/pages/users/user_money/index'
});
},
fail: function(err) {
return that.$util.Tips({
title: '支付失败'
});
},
complete: function(res) {
if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
title: '取消支付'
});
}
})
const returnUrl = encodeURIComponent('/pages/users/user_payment/index');
uni.navigateTo({
url: `/pages/goods/cashier/index?order_id=${res.data.payOrderId}&returnUrl=${returnUrl}`
})
}).catch(err => {
uni.hideLoading();
return that.$util.Tips({
title: err
})
});
// #endif
// #ifdef H5
rechargeWechat({
price: money,
from: that.from,
rechar_id: that.rechar_id,
payType: 0
}).then(res => {
let jsConfig = res.data.jsConfig;
let orderNo = res.data.orderNo;
let data = {
timestamp:jsConfig.timeStamp,
nonceStr:jsConfig.nonceStr,
package:jsConfig.packages,
signType:jsConfig.signType,
paySign:jsConfig.paySign
};
if (that.from == "weixinh5") {
let domain = encodeURIComponent(location.href.split('/pages')[0]);
let urls = jsConfig.mwebUrl + '&redirect_url='+ domain + '/pages/users/user_money/index';
location.replace(urls);
return that.$util.Tips({
tab: 5,
url: '/pages/users/user_money/index'
});
// return that.$util.Tips({
// title: '',
// icon: 'success'
// }, {
// tab: 5,
// url: '/pages/users/user_money/index'
// });
} else {
that.$wechat.pay(data)
.finally(() => {
that.$store.commit("changInfo", {
amount1: 'nowMoney',
amount2: that.$util.$h.Add(value, that.userinfo.nowMoney)
});
// that.$set(that, 'userinfo.nowMoney', that.$util.$h.Add(value, that.userinfo.nowMoney));
wechatQueryPayResult(orderNo).then(res => {
return that.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: 5,
url: '/pages/users/user_money/index'
});
}).cache(err => {
return that.$util.Tips({
title: err
});
})
})
.catch(function(err) {
return that.$util.Tips({
title: '支付失败'
});
});
}
}).catch(res=>{
uni.hideLoading();
return that.$util.Tips({
title: res
});
})
// #endif
}
}
},
fen2yuan(price) {
return Util.fen2yuan(price)
}
}
}
</script>