Commit 62a3c477 authored by chenqikuai's avatar chenqikuai

store

parent 06d00eaf
...@@ -12,7 +12,7 @@ const order = { ...@@ -12,7 +12,7 @@ const order = {
...params, ...params,
}); });
}, },
add(planId: number, method: number, params: any) { add(planId: number, method: number, params: {[name: string]: any}) {
return axios.post(`${base}/add`, { return axios.post(`${base}/add`, {
plan_id: planId, plan_id: planId,
promo_code: '', promo_code: '',
...@@ -34,5 +34,11 @@ const order = { ...@@ -34,5 +34,11 @@ const order = {
}, },
}); });
}, },
payMethods() {
return axios({
url: `${base}/pay/methods`,
method: 'get',
});
},
}; };
export default order; export default order;
...@@ -67,6 +67,8 @@ const routes: RouteConfig[] = [ ...@@ -67,6 +67,8 @@ const routes: RouteConfig[] = [
// this generates a separate chunk (about.[hash].js) for this route // this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited. // which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "view-code" */ '@/views/ViewCode.vue'), component: () => import(/* webpackChunkName: "view-code" */ '@/views/ViewCode.vue'),
props: ({query}) => ({locationUrl: query.locationUrl,
isPayment: query.payment ? JSON.parse(query.payment as string) : undefined}),
meta: { requiresAuth: true }, meta: { requiresAuth: true },
}, },
{ {
......
<template> <template>
<div class="view-code"> <div class="view-code">
<!-- {{hash}} --> <!-- {{hash}} -->
<div v-if="isPayment">
应付***:**个
</div>
<div class="container"> <div class="container">
<div class="border"> <VueQr
class="qr-code"
</div> :text="locationUrl"
:size="220"
:callback="vueQrCb"
/>
<div v-if="isPayment">
</div>
<div>
<a class="btn-save" download="二维码.png" :href="dataUrl">保存二维码</a>
</div>
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import VueQr from 'vue-qr';
import { Component, Prop, Vue } from 'vue-property-decorator'; import { Component, Prop, Vue } from 'vue-property-decorator';
@Component @Component({
components: {
VueQr,
},
})
export default class ViewCode extends Vue { export default class ViewCode extends Vue {
@Prop() locationUrl!: string;
@Prop() isPayment!: boolean;
private dataUrl = '';
get hash() { get hash() {
return this.$route.query.hash; return this.$route.query.hash;
} }
private vueQrCb(dataUrl: string) {
this.dataUrl = dataUrl;
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.view-code{ .view-code {
background: #454674; min-height: 100vh;
display: flex; background: #333648;
justify-content: center; display: flex;
padding-top: 52px; justify-content: center;
.container{ padding-top: 52px;
width:277px; .container {
height: 295px; text-align: center;
display: flex; width: 332px;
justify-content: center; height: 408px;
align-items: center; background: #ffffff;
border-radius: 10px; box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.09);
background: #FFFFFF; border-radius: 5px;
.border{ border-radius: 10px;
width: 195px; .qr-code {
height: 195px; margin-top: 45px;
margin: 20px; margin-bottom: 33px;
background-image: linear-gradient(to left, #FF9F08, #FF9F08), }
linear-gradient(to left, #FF9F08, #FF9F08), .btn-save {
linear-gradient(to left, #FF9F08, #FF9F08), display: inline-block;
linear-gradient(to bottom, #FF9F08, #FF9F08), width: 200px;
linear-gradient(to left, #FF9F08, #FF9F08), height: 40px;
linear-gradient(to bottom, #FF9F08, #FF9F08), background: linear-gradient(180deg, #4667fa 0%, #5b77f4 100%);
linear-gradient(to left, #FF9F08, #FF9F08), box-shadow: 0px 2px 15px 0px rgba(63, 121, 254, 0.42);
linear-gradient(to left, #FF9F08, #FF9F08); border-radius: 4px;
background-size: 3px 20px, 20px 3px; line-height: 40px;
background-position: left top, left top, right top, right top, left bottom, left bottom, right bottom, right bottom; font-size: 14px;
background-repeat: no-repeat; font-family: PingFangSC-Regular, PingFang SC;
border-radius: 5px; font-weight: 400;
} color: #ffffff;
} }
} }
}
</style> </style>
...@@ -22,18 +22,20 @@ ...@@ -22,18 +22,20 @@
</section> </section>
<section class="method"> <section class="method">
<p class="title">选择支付方式</p> <p class="title">选择支付方式</p>
<van-radio-group v-model="method"> <van-radio-group v-model="selectedMethodId">
<van-cell <van-cell
v-for="(item, key) in payMethods" v-for="(item, key) in payMethods"
:key="key" :key="key"
:title="item.title" :title="item.title"
@click="method = item.method" @click="handleClickPayMethod(item)"
center clickable> center clickable>
<template #icon> <template #icon>
<common-svg :name="item.icon" style="margin-right:10px;"></common-svg> <img :src="item.s_image_url" style="height:20px">
<div style="flex-grow: 1">
</div>
</template> </template>
<template #right-icon> <template #right-icon>
<van-radio :name="item.method" /> <van-radio :name="item.id" />
</template> </template>
</van-cell> </van-cell>
</van-radio-group> </van-radio-group>
...@@ -57,7 +59,8 @@ ...@@ -57,7 +59,8 @@
<div style="font-size: 40px;margin-top:60px;">¥{{selectedPlan.price}}</div> <div style="font-size: 40px;margin-top:60px;">¥{{selectedPlan.price}}</div>
<div style="color:#B6B7B9;font-size: 16px;">燃料次数:{{selectedPlan.chain_times}}次</div> <div style="color:#B6B7B9;font-size: 16px;">燃料次数:{{selectedPlan.chain_times}}次</div>
<div style="text-align:left;margin-top:42px"> <div style="text-align:left;margin-top:42px">
<common-svg :name="payMethods[method].icon" style="margin-right:10px;"></common-svg>{{payMethods[method].title}} <img :src="selectedMethodImgUrl" alt="">
<!-- <common-svg :name="payMethods[method].icon" style="margin-right:10px;"></common-svg>{{payMethods[method].title}} -->
</div> </div>
<div @click="payHandler" class="slc-btn-common" style="display:inline-block;width:200px;height:40px;line-height:40px;margin-top:12px;">立即充值</div> <div @click="payHandler" class="slc-btn-common" style="display:inline-block;width:200px;height:40px;line-height:40px;margin-top:12px;">立即充值</div>
</div> </div>
...@@ -70,6 +73,8 @@ import { Component, Prop, Vue } from 'vue-property-decorator'; ...@@ -70,6 +73,8 @@ import { Component, Prop, Vue } from 'vue-property-decorator';
import { Cell, Form, Field, CellGroup, Button, Image, RadioGroup, Radio, Popup, Dialog } from 'vant'; import { Cell, Form, Field, CellGroup, Button, Image, RadioGroup, Radio, Popup, Dialog } from 'vant';
import { Getter, State } from 'vuex-class'; import { Getter, State } from 'vuex-class';
import { Route } from 'vue-router'; import { Route } from 'vue-router';
import { EPayMethod } from "./const"
@Component({ @Component({
components: { components: {
[Form.name]: Form, [Form.name]: Form,
...@@ -85,18 +90,19 @@ import { Route } from 'vue-router'; ...@@ -85,18 +90,19 @@ import { Route } from 'vue-router';
}) })
export default class Recharge extends Vue { export default class Recharge extends Vue {
@State('userInfo') private userInfo!: any; @State('userInfo') private userInfo!: any;
private readonly payMethods: any = { // private payMethods: any = {
0: { // 0: {
title: '支付宝', // title: '支付宝',
icon: 'gerenzhongxin-zhifubaozhifu', // icon: 'gerenzhongxin-zhifubaozhifu',
method: 0, // method: 0,
}, // },
1: { // 1: {
title: '微信', // title: '微信',
icon: 'gerenzhongxin-weixinzhifu2', // icon: 'gerenzhongxin-weixinzhifu2',
method: 1, // method: 1,
}, // },
}; // };
private payMethods = [];
private planList: any[] = []; private planList: any[] = [];
private selectedPlan: any = { private selectedPlan: any = {
planId: -1, planId: -1,
...@@ -104,6 +110,27 @@ export default class Recharge extends Vue { ...@@ -104,6 +110,27 @@ export default class Recharge extends Vue {
chain_times: 0, chain_times: 0,
}; };
private method: number = 0; private method: number = 0;
private selectedMethodId: null | number = null;
private getSelectedPayMethod(){
return this.payMethods.find((item: any) => item.id === this.selectedMethodId) as any
}
get selectedMethodImgUrl(){
if(this.selectedMethodId !== null){
return (this.getSelectedPayMethod()).s_image_url;
}
return "";
}
get getSelectedPayMethodType(): EPayMethod{
const selectedPayMethod = this.getSelectedPayMethod();
if(selectedPayMethod){
return selectedPayMethod.type;
}else{
throw new Error("没有选中方法")
}
}
private orderId: string = ''; private orderId: string = '';
...@@ -118,9 +145,19 @@ export default class Recharge extends Vue { ...@@ -118,9 +145,19 @@ export default class Recharge extends Vue {
chain_times, chain_times,
}; };
}); });
this.$api.order.payMethods().then((ret: any) => {
const methods = ret.pay_methods || [];
this.payMethods = methods;
this.selectedMethodId = methods[0].id;
})
} }
private handleClickPayMethod(method: any){
this.selectedMethodId = method.id;
}
private beforeRouteLeave(to: Route, from: Route, next: (params?: any) => void) { private beforeRouteLeave(to: Route, from: Route, next: (params?: any) => void) {
if (!this.confirm) { return next(); } if (!this.confirm || to.name === "ViewCode") { return next(); }
this.$dialog.confirm({ this.$dialog.confirm({
title: '提示', title: '提示',
message: '点击“返回”将中断操作,确定返回?', message: '点击“返回”将中断操作,确定返回?',
...@@ -133,15 +170,30 @@ export default class Recharge extends Vue { ...@@ -133,15 +170,30 @@ export default class Recharge extends Vue {
}); });
} }
private async recharge() { private async recharge() {
const { id } = await this.$api.order.add(this.selectedPlan.id, this.method); const { id } = await this.$api.order.add(this.selectedPlan.id);
this.confirm = true; this.confirm = true;
this.orderId = id; this.orderId = id;
} }
private async payHandler() { private async payHandler() {
const { protocol, host } = location; const { protocol, host } = location;
const { pay_url } = await this.$api.order.pay(this.orderId, this.method);
const params:any = {};
if(this.getSelectedPayMethodType === EPayMethod.biqianbaopay) params.coin = this.getSelectedPayMethod().coin;
const { pay_url } = await this.$api.order.pay(this.orderId, this.getSelectedPayMethodType, params);
const redirectUrl = encodeURIComponent(`${protocol}//${host}/#/rechargeSuccess`); const redirectUrl = encodeURIComponent(`${protocol}//${host}/#/rechargeSuccess`);
location.href = this.method === 0 ? pay_url : `${pay_url}&redirect_url=${redirectUrl}`; if(this.getSelectedPayMethodType === EPayMethod.biqianbaopay){
// 币钱包 需要展示二维码
this.$router.push({
name: 'ViewCode',
query: {
locationUrl: pay_url,
payment: JSON.stringify(true),
}
})
}else{
// 支付宝和微信支付走👇流程
location.href = this.getSelectedPayMethodType === EPayMethod.alipay ? pay_url : `${pay_url}&redirect_url=${redirectUrl}`;
}
} }
} }
</script> </script>
......
export enum EPayMethod {
alipay = 0,
weixinpay = 1,
biqianbaopay = 2,
}
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