add create order
This commit is contained in:
1 parent
0b6bb8d173
commit
e67dfadac7
9 files changed
+94
-18
No files matched your search
@@ -18,7 +18,7 @@ body {
|
||||
|
||||
.el-card {
|
||||
word-wrap: break-word;
|
||||
border-radius: 0.375rem;
|
||||
border-radius: 1rem;
|
||||
border: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</div>
|
||||
<div v-else class="mt-3 pr-10 float-right">
|
||||
<el-dropdown trigger="click">
|
||||
<img :src="user.avatar || defaultAvatar" class="avatar" />
|
||||
<img :src="user?.avatar || defaultAvatar" class="avatar" />
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="onProfile">{{ $t('common.button.profile') }}</el-dropdown-item>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default {
|
||||
paidSuccessfully: '支付成功',
|
||||
paid: '已经购买成功',
|
||||
needPay: '需要购买',
|
||||
needPay: '您需要购买完整课程才能观看',
|
||||
wechatPayHelp: '请打开手机微信,扫一扫完成支付',
|
||||
createOrderFailed: '创建订单失败',
|
||||
creatingOrder: '正在生成订单',
|
||||
|
||||
@@ -34,15 +34,16 @@
|
||||
</div>
|
||||
<div class="operation">
|
||||
<p v-if="paid === false">
|
||||
<el-button @click="onBuy" type="danger" :loading="buying">
|
||||
<el-icon class="icon" v-if="!buying">
|
||||
<span v-if="course.price" class="price">¥{{ (course?.price / 100).toFixed(2) }}</span>
|
||||
<el-button type="danger" :loading="buying" @click="onBuy">
|
||||
<el-icon v-if="!buying" class="icon">
|
||||
<goods />
|
||||
</el-icon>
|
||||
{{ $t('course.button.buy') }}
|
||||
</el-button>
|
||||
</p>
|
||||
<p v-if="paid === true">
|
||||
<el-button @click="onStudy" type="danger">
|
||||
<el-button type="danger" @click="onStudy">
|
||||
<el-icon class="icon"> <video-play /> </el-icon>
|
||||
{{ $t('course.button.startStudy') }}
|
||||
</el-button>
|
||||
@@ -150,8 +151,7 @@ export default defineComponent({
|
||||
MagicStick,
|
||||
VerificationAlert,
|
||||
VideoPlay,
|
||||
Goods,
|
||||
Loading
|
||||
Goods
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
@@ -213,6 +213,9 @@ export default defineComponent({
|
||||
name: 'order-detail',
|
||||
params: {
|
||||
id: this.order.id
|
||||
},
|
||||
query: {
|
||||
redirect: window.location.href
|
||||
}
|
||||
});
|
||||
})
|
||||
@@ -248,6 +251,14 @@ export default defineComponent({
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.price {
|
||||
display: block;
|
||||
font-size: 30px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.thumbnail {
|
||||
text-align: center;
|
||||
img {
|
||||
|
||||
@@ -29,7 +29,18 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="paid === false && !episode?.isFree">
|
||||
{{ $t('course.message.needPay') }}
|
||||
<el-card class="unpaid">
|
||||
<el-result icon="info" :title="undefined" :sub-title="$t('course.message.needPay')">
|
||||
<template #extra>
|
||||
<el-button type="danger" :loading="buying" class="buy" @click="onBuy">
|
||||
<el-icon v-if="!buying" class="icon">
|
||||
<goods />
|
||||
</el-icon>
|
||||
{{ $t('course.button.buy') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-result>
|
||||
</el-card>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -45,12 +56,19 @@ import CoursePreviewCard from '@/components/course/PreviewCard.vue';
|
||||
import { courseService } from '@/services/course/service';
|
||||
import { ICourse, ICourseDetailResponse, ICoursePaidStatusResponse } from '@/services/course/types';
|
||||
import { IResource, IResourceDetailResponse } from '@/services/resource/types';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { orderService } from '@/services/order/service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { IOrder, IOrderDetailResponse } from '@/services/order/types';
|
||||
import { Goods } from '@element-plus/icons-vue';
|
||||
|
||||
interface IData {
|
||||
course: ICourse | undefined;
|
||||
episode: IEpisode | undefined;
|
||||
resource: IResource | undefined;
|
||||
episodes: IEpisode[];
|
||||
order: IOrder | undefined;
|
||||
buying: boolean;
|
||||
loading: boolean;
|
||||
prepared: boolean;
|
||||
paid: boolean | undefined;
|
||||
@@ -62,13 +80,16 @@ export default defineComponent({
|
||||
components: {
|
||||
EpisodeSideList,
|
||||
EpisodePlayer,
|
||||
CoursePreviewCard
|
||||
CoursePreviewCard,
|
||||
Goods
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
course: undefined,
|
||||
episode: undefined,
|
||||
buying: false,
|
||||
loading: false,
|
||||
order: undefined,
|
||||
episodes: [],
|
||||
resource: undefined,
|
||||
paid: undefined,
|
||||
@@ -126,6 +147,33 @@ export default defineComponent({
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 0);
|
||||
},
|
||||
onBuy() {
|
||||
this.buying = true;
|
||||
ElMessage.info(this.$t('course.message.creatingOrder'));
|
||||
orderService
|
||||
.create({
|
||||
id: uuidv4().replaceAll(/-/g, ''),
|
||||
courses: [this.courseId],
|
||||
description: `${this.$t('common.title.orderDescription')} - ${this.courseId}`
|
||||
})
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
this.buying = false;
|
||||
this.order = data;
|
||||
this.$router.push({
|
||||
name: 'order-detail',
|
||||
params: {
|
||||
id: this.order.id
|
||||
},
|
||||
query: {
|
||||
redirect: window.location.href
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error(this.$t('course.message.createOrderFailed'));
|
||||
this.buying = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -140,6 +188,7 @@ $width: 300px;
|
||||
width: $width;
|
||||
}
|
||||
.main {
|
||||
position: relative;
|
||||
width: calc(100% - $width);
|
||||
background-image: radial-gradient(circle at 0 2%, #283e63, #172337 99%);
|
||||
}
|
||||
@@ -159,4 +208,18 @@ $width: 300px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.unpaid {
|
||||
width: 400px;
|
||||
// height: 200px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
.buy {
|
||||
.icon {
|
||||
margin-right: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -108,6 +108,9 @@ export default defineComponent({
|
||||
},
|
||||
id() {
|
||||
return this.$route.params.id.toString();
|
||||
},
|
||||
redirect() {
|
||||
return this.$route.query.redirect;
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
@@ -132,6 +135,11 @@ export default defineComponent({
|
||||
this.order = data;
|
||||
if (this.order.state === ORDER_STATE_PAID) {
|
||||
ElMessage.success(this.$t('course.message.paidSuccessfully'));
|
||||
setTimeout(() => {
|
||||
if (this.redirect) {
|
||||
window.location.replace(this.redirect?.toString());
|
||||
}
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<template></template>
|
||||
@@ -6,11 +6,6 @@ export default {
|
||||
},
|
||||
component: () => import('@/layouts/Order.vue'),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'order-list',
|
||||
component: () => import('@/pages/order/List.vue')
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
name: 'order-detail',
|
||||
|
||||
+2
-2
@@ -23,10 +23,10 @@ const getAcademyEndpoint = () => {
|
||||
case 'local':
|
||||
return 'http://localhost:8002';
|
||||
case 'test':
|
||||
return 'https://auth.test.zhishuyun.com';
|
||||
return 'https://academy.test.zhishuyun.com';
|
||||
case 'production':
|
||||
default:
|
||||
return 'https://auth.zhishuyun.com';
|
||||
return 'https://academy.zhishuyun.com';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user