|
|
@@ -1,6 +1,41 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<v-container class="ma-8 pa-4">
|
|
|
+ <!-- 热门课程 -->
|
|
|
+ <v-row class="mt-8 mb-2">
|
|
|
+ <v-chip
|
|
|
+ class="ma-2"
|
|
|
+ color="deep-purple lighten-3"
|
|
|
+ label
|
|
|
+ text-color="white"
|
|
|
+ >
|
|
|
+ <v-icon left>
|
|
|
+ mdi-label
|
|
|
+ </v-icon>
|
|
|
+ 热门课程
|
|
|
+ </v-chip>
|
|
|
+ </v-row>
|
|
|
+ <v-row>
|
|
|
+ <course-item
|
|
|
+ cols="12"
|
|
|
+ md="4"
|
|
|
+ v-for="course in hotCourseList"
|
|
|
+ :key="course.id"
|
|
|
+ :courseName="course.name"
|
|
|
+ :courseId="course.id"
|
|
|
+ :description="course.intro"
|
|
|
+ :type="course.type"
|
|
|
+ :cost="course.cost"
|
|
|
+ :bought="course.bought"
|
|
|
+ :manageable="course.manageable"
|
|
|
+ :course-color="colorList[course.id % colorList.length]"
|
|
|
+ :course-likes="course.likes"
|
|
|
+ @buy-course="showDialog"
|
|
|
+ @set-like="setLike"
|
|
|
+ >
|
|
|
+ </course-item>
|
|
|
+ </v-row>
|
|
|
+
|
|
|
<template>
|
|
|
<!-- 分类课程 -->
|
|
|
<v-row class="mt-2 mb-8">
|
|
|
@@ -38,7 +73,9 @@
|
|
|
:bought="course.bought"
|
|
|
:manageable="course.manageable"
|
|
|
:course-color="colorList[course.id % colorList.length]"
|
|
|
+ :course-likes="course.likes"
|
|
|
@buy-course="showDialog"
|
|
|
+ @set-like="setLike"
|
|
|
>
|
|
|
</course-item>
|
|
|
</v-row>
|
|
|
@@ -90,7 +127,9 @@
|
|
|
:bought="course.bought"
|
|
|
:manageable="course.manageable"
|
|
|
:course-color="colorList[course.id % colorList.length]"
|
|
|
+ :course-likes="course.likes"
|
|
|
@buy-course="showDialog"
|
|
|
+ @set-like="setLike"
|
|
|
>
|
|
|
</course-item>
|
|
|
</v-row>
|
|
|
@@ -135,17 +174,26 @@
|
|
|
:bought="course.bought"
|
|
|
:manageable="course.manageable"
|
|
|
:course-color="colorList[course.id % colorList.length]"
|
|
|
+ :course-likes="course.likes"
|
|
|
@buy-course="showDialog"
|
|
|
+ @set-like="setLike"
|
|
|
>
|
|
|
</course-item>
|
|
|
</v-row>
|
|
|
</v-container>
|
|
|
|
|
|
<!-- 购买提示对话框 -->
|
|
|
- <v-dialog v-model="dialog" width="500">
|
|
|
+ <v-dialog v-model="dialog" width="1000">
|
|
|
<v-card>
|
|
|
<v-card-title>购买课程</v-card-title>
|
|
|
-
|
|
|
+ <v-data-table
|
|
|
+ :headers="couponHeaders"
|
|
|
+ :items="coupons"
|
|
|
+ class="elevation-1"
|
|
|
+ show-select
|
|
|
+ @item-selected="onSelectCoupon"
|
|
|
+ >
|
|
|
+ </v-data-table>
|
|
|
<v-card-text>
|
|
|
是否花费 「{{ currentCoursePrice }}元」购买课程 「{{
|
|
|
currentCourseName
|
|
|
@@ -185,6 +233,9 @@
|
|
|
</v-card-actions>
|
|
|
</v-card>
|
|
|
</v-dialog>
|
|
|
+ <v-snackbar v-model="showLikeAlert" :color="setLikeColor" top>
|
|
|
+ {{ setLikeMsg }}
|
|
|
+ </v-snackbar>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -193,7 +244,7 @@ import CourseItem from "@/components/CourseItem.vue";
|
|
|
import {
|
|
|
getCoursesByType,
|
|
|
getCoursesByKey,
|
|
|
- getBoughtCourses,
|
|
|
+ getBoughtCourses, getHotCourses, setCourseLike,
|
|
|
} from "@/api/course";
|
|
|
import { createOrder } from "@/api/order";
|
|
|
|
|
|
@@ -238,6 +289,47 @@ export default {
|
|
|
searchCurrentPage: 1,
|
|
|
//
|
|
|
boughtCoursesList: [],
|
|
|
+ hotCourseList: [],
|
|
|
+ showLikeAlert: false,
|
|
|
+ setLikeMsg: '',
|
|
|
+ setLikeColor: 'success',
|
|
|
+ couponHeaders:[
|
|
|
+ {
|
|
|
+ text: "优惠券名称",
|
|
|
+ value: "name"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "优惠券类型",
|
|
|
+ value: "type"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "优惠券描述",
|
|
|
+ value: "description"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "优惠额度",
|
|
|
+ value: "cutDown"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "优惠比例",
|
|
|
+ value: "discount"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: "与其他优惠券同时使用",
|
|
|
+ value: "sharable"
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ coupons:[{
|
|
|
+ id: 1,
|
|
|
+ name:"name",
|
|
|
+ type:"universal",
|
|
|
+ description:"description",
|
|
|
+ cutDown: 20,
|
|
|
+ discount: 0,
|
|
|
+ sharable: false,
|
|
|
+ selected: false
|
|
|
+ }],
|
|
|
+ selectedCoupons:[]
|
|
|
};
|
|
|
},
|
|
|
|
|
|
@@ -285,12 +377,13 @@ export default {
|
|
|
cost: this.currentCoursePrice,
|
|
|
userId: uid,
|
|
|
status: 2,
|
|
|
+ origin: this.currentCoursePrice
|
|
|
}).then((res) => {
|
|
|
this.dialog = false;
|
|
|
this.msg =
|
|
|
(res.code === 1 ? "「购买成功」!" : "「购买失败」!") + res.msg;
|
|
|
this.dialog2 = true;
|
|
|
- this.getUserBoughtCourses();
|
|
|
+ this.fetchData()
|
|
|
});
|
|
|
},
|
|
|
|
|
|
@@ -317,20 +410,59 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ handleHotCourse(){
|
|
|
+ getHotCourses().then(res=>{
|
|
|
+ this.hotCourseList = res.list
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
getUserBoughtCourses() {
|
|
|
const uid = window.localStorage.getItem("userId");
|
|
|
getBoughtCourses(uid).then((res) => {
|
|
|
this.boughtCoursesList = res || [];
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
+ fetchData(){
|
|
|
+ ["primary", "medium", "advanced"].forEach((t) => {
|
|
|
+ this.handleGetCoursesByType(1, t);
|
|
|
+ });
|
|
|
+ this.handleSearchCourse();
|
|
|
+ this.getUserBoughtCourses();
|
|
|
+ this.handleHotCourse()
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ onSelectCoupon({item, value}){
|
|
|
+ if(value){
|
|
|
+ this.selectedCoupons.push(item)
|
|
|
+ }else{
|
|
|
+ this.selectedCoupons = this.selectedCoupons.filter((val)=>{
|
|
|
+ return val.id !== item.id
|
|
|
+ })
|
|
|
+ }
|
|
|
+ console.log(this.selectedCoupons)
|
|
|
+ },
|
|
|
+
|
|
|
+ setLike(courseId){
|
|
|
+ const uid = window.localStorage.getItem('userId')
|
|
|
+ setCourseLike(uid, courseId).then(res=>{
|
|
|
+ if (res.code === 1){
|
|
|
+ this.setLikeMsg = res.msg
|
|
|
+ this.setLikeColor = 'success'
|
|
|
+ this.showLikeAlert = true
|
|
|
+ this.fetchData()
|
|
|
+ }else{
|
|
|
+ this.setLikeMsg = res.msg
|
|
|
+ this.setLikeColor = 'warning'
|
|
|
+ this.showLikeAlert = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
mounted() {
|
|
|
- ["primary", "medium", "advanced"].forEach((t) => {
|
|
|
- this.handleGetCoursesByType(1, t);
|
|
|
- });
|
|
|
- this.handleSearchCourse();
|
|
|
- this.getUserBoughtCourses();
|
|
|
+ this.fetchData()
|
|
|
},
|
|
|
};
|
|
|
</script>
|