Commit b20d4dbd authored by chenqikuai's avatar chenqikuai

fix: 充值成功返回后,展示是否充值成功的检查

parent 670ae6db
...@@ -112,6 +112,7 @@ export default class Recharge extends Vue { ...@@ -112,6 +112,7 @@ export default class Recharge extends Vue {
// method: 1, // method: 1,
// }, // },
// }; // };
@Prop() private isCallback!: boolean;
private payMethods: IMethod[] = []; private payMethods: IMethod[] = [];
private planList: any[] = []; private planList: any[] = [];
private selectedPlan: any = { private selectedPlan: any = {
...@@ -180,17 +181,42 @@ export default class Recharge extends Vue { ...@@ -180,17 +181,42 @@ export default class Recharge extends Vue {
}); });
} }
private async recharge() { private async recharge() {
const { id } = await this.$api.order.add(this.selectedPlan.id); try {
const { id } = await this.$api.order.add(this.selectedPlan.id, this.method);
this.confirm = true; this.confirm = true;
this.orderId = id; this.orderId = id;
} catch (err) {
if (err.code === 10603) {
this.$dialog.confirm({
title: '提示',
message: '您的账户还很充足请剩余少量余额时进行充值',
confirmButtonText: '确定',
cancelButtonText: '取消',
});
}
} }
}
private goToQrPayPage(pay_url: string, coin: string, downloadUrl: string){
this.$router.push({
name: 'ViewCode',
query: {
locationUrl: pay_url,
payment: JSON.stringify(true),
coin,
downloadUrl
}
})
}
private async payHandler() { private async payHandler() {
const { protocol, host } = location; const { protocol, host } = location;
localStorage.setItem('orderId', this.orderId);
localStorage.setItem('methodId', JSON.stringify(this.selectedMethodId));
const params:any = {}; const params:any = {};
if(this.getSelectedPayMethodType === EPayMethod.biqianbaopay) params.coin = this.getSelectedPayMethod().coin; if(this.getSelectedPayMethodType === EPayMethod.biqianbaopay) params.coin = this.getSelectedPayMethod().coin;
const { pay_url } = await this.$api.order.pay(this.orderId, this.getSelectedPayMethodType, params); const { pay_url } = await this.$api.order.pay(this.orderId, this.getSelectedPayMethodType, params);
const redirectUrl = encodeURIComponent(`${protocol}//${host}/#/rechargeSuccess`); const redirectUrl = encodeURIComponent(`${protocol}//${host}/#/recharge?isCallback=true`);
if(this.getSelectedPayMethodType === EPayMethod.biqianbaopay){ if(this.getSelectedPayMethodType === EPayMethod.biqianbaopay){
// 币钱包 需要展示二维码 // 币钱包 需要展示二维码
...@@ -198,19 +224,55 @@ export default class Recharge extends Vue { ...@@ -198,19 +224,55 @@ export default class Recharge extends Vue {
const coin = method.coin; const coin = method.coin;
const downloadUrl = method.download_url; const downloadUrl = method.download_url;
this.$router.push({ localStorage.setItem('payUrl', pay_url);
name: 'ViewCode',
query: { this.goToQrPayPage(pay_url, coin, downloadUrl)
locationUrl: pay_url,
payment: JSON.stringify(true),
coin,
downloadUrl
}
})
}else{ }else{
// 支付宝和微信支付走👇流程 // 支付宝和微信支付走👇流程
location.href = this.getSelectedPayMethodType === EPayMethod.alipay ? pay_url : `${pay_url}&redirect_url=${redirectUrl}`; const url = this.getSelectedPayMethodType === EPayMethod.alipay ? pay_url : `${pay_url}&redirect_url=${redirectUrl}`;
localStorage.setItem('payUrl', url);
location.href = url;
}
}
private async confrimPayed() {
const { protocol, host } = location;
this.orderId = String(localStorage.getItem('orderId'));
const redirectUrl = String(localStorage.getItem('payUrl'));
if (!this.orderId || !redirectUrl) {
return this.redirectToRecharge();
} }
const { status } = await this.$api.order.get(this.orderId);
if (status === 2) { // 0:未支付 1:支付中 2:支付成功 3:支付失败
this.$router.replace({name: 'RechargeSuccess'});
} else {
this.$dialog.confirm({
title: '提示',
message: '您当前还没有完成付款,请点击[继续付款]进行支付',
confirmButtonText: '继续付款',
cancelButtonText: '取消',
}).then(() => {
const methodId: number = JSON.parse(localStorage.getItem('methodId') || '')
const payMethod = this.payMethods.find(method => method.id === methodId)
if(payMethod?.type === EPayMethod.biqianbaopay){
this.goToQrPayPage(redirectUrl, payMethod.coin, payMethod.download_url);
}else{
location.href = redirectUrl;
}
}).catch((err) => {
this.$router.push({path: '/userCenter/index'});
});
}
}
private redirectToRecharge() {
localStorage.setItem('orderId', '');
localStorage.setItem('payUrl', '');
this.$router.replace({name: 'Recharge'});
}
private rePay() {
this.redirectToRecharge();
} }
} }
</script> </script>
......
import { EPayMethod } from './const';
export interface IMethod { export interface IMethod {
id: number;
coin: string; coin: string;
download_url: string; download_url: string;
type: EPayMethod;
[props: string]: any; [props: string]: any;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment