|
|
@@ -1,38 +1,82 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<v-container class="ma-8 pa-4">
|
|
|
- <v-row>
|
|
|
- <v-chip class="ma-2" color="primary">
|
|
|
- 热门课程
|
|
|
- </v-chip>
|
|
|
- </v-row>
|
|
|
- <v-row class="mb-4">
|
|
|
- <course-item
|
|
|
- v-for="(item, index) in courseList1"
|
|
|
- :key="index"
|
|
|
- :courseName="item.name"
|
|
|
- :description="item.description"
|
|
|
- :status="item.status"
|
|
|
- :course-color="colorList[index % colorList.length]"
|
|
|
- @buy-course="showDialog"
|
|
|
- ></course-item>
|
|
|
- </v-row>
|
|
|
- <v-row class="mb-10">
|
|
|
+ <template>
|
|
|
+ <v-card>
|
|
|
+ <v-tabs color="deep-purple accent-4" right v-model="currentTab">
|
|
|
+ <v-tab>初级课程</v-tab>
|
|
|
+ <v-tab>中级课程</v-tab>
|
|
|
+ <v-tab>高级课程</v-tab>
|
|
|
+
|
|
|
+ <v-tab-item v-for="c in [primary, medium, advanced]" :key="c.name">
|
|
|
+ <v-container fluid>
|
|
|
+ <v-row class="ma-4">
|
|
|
+ <course-item
|
|
|
+ cols="12"
|
|
|
+ md="4"
|
|
|
+ v-for="course in c.list"
|
|
|
+ :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]"
|
|
|
+ @buy-course="showDialog"
|
|
|
+ >
|
|
|
+ </course-item>
|
|
|
+ </v-row>
|
|
|
+ <v-pagination
|
|
|
+ v-model="c.currentPage"
|
|
|
+ :length="c.totalPage"
|
|
|
+ circle
|
|
|
+ ></v-pagination>
|
|
|
+ </v-container>
|
|
|
+ </v-tab-item>
|
|
|
+ </v-tabs>
|
|
|
+ </v-card>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <v-row class="ma-12">
|
|
|
<v-divider></v-divider>
|
|
|
</v-row>
|
|
|
- <v-row>
|
|
|
- <v-select :items="types" filled label="课程检索"></v-select>
|
|
|
+
|
|
|
+ <v-row class="mt-10">
|
|
|
+ <v-col cols="5">
|
|
|
+ <v-text-field
|
|
|
+ v-model="searchText"
|
|
|
+ outlined
|
|
|
+ label="搜索课程"
|
|
|
+ append-icon="mdi-magnify"
|
|
|
+ ></v-text-field>
|
|
|
+ </v-col>
|
|
|
</v-row>
|
|
|
<v-row>
|
|
|
<course-item
|
|
|
- v-for="(item, index) in courseList"
|
|
|
- :key="index"
|
|
|
- :courseName="item.name"
|
|
|
- :description="item.description"
|
|
|
- :status="item.status"
|
|
|
- :course-color="colorList[index % colorList.length]"
|
|
|
+ cols="12"
|
|
|
+ md="4"
|
|
|
+ v-for="course in searchCourse"
|
|
|
+ :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]"
|
|
|
@buy-course="showDialog"
|
|
|
- ></course-item>
|
|
|
+ >
|
|
|
+ </course-item>
|
|
|
+ </v-row>
|
|
|
+ <v-row>
|
|
|
+ <v-pagination
|
|
|
+ v-model="searchCurrentPage"
|
|
|
+ :length="searchTotalPage"
|
|
|
+ circle
|
|
|
+ ></v-pagination>
|
|
|
</v-row>
|
|
|
</v-container>
|
|
|
|
|
|
@@ -67,7 +111,7 @@
|
|
|
<v-card-title>购买课程</v-card-title>
|
|
|
|
|
|
<v-card-text>
|
|
|
- 购买成功!
|
|
|
+ {{ msg }}
|
|
|
</v-card-text>
|
|
|
|
|
|
<v-divider></v-divider>
|
|
|
@@ -80,30 +124,13 @@
|
|
|
</v-card-actions>
|
|
|
</v-card>
|
|
|
</v-dialog>
|
|
|
- <!-- 购买结果 -->
|
|
|
- <v-dialog v-model="dialog3" width="500">
|
|
|
- <v-card>
|
|
|
- <v-card-title>购买课程</v-card-title>
|
|
|
-
|
|
|
- <v-card-text>
|
|
|
- 余额不足。
|
|
|
- </v-card-text>
|
|
|
-
|
|
|
- <v-divider></v-divider>
|
|
|
-
|
|
|
- <v-card-actions>
|
|
|
- <v-spacer></v-spacer>
|
|
|
- <v-btn color="primary" text @click="dialog3 = false">
|
|
|
- 确认
|
|
|
- </v-btn>
|
|
|
- </v-card-actions>
|
|
|
- </v-card>
|
|
|
- </v-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import CourseItem from "@/components/CourseItem.vue";
|
|
|
+import { getCoursesByType, getCoursesByKey } from "@/api/course";
|
|
|
+import { createOrder } from "@/api/order";
|
|
|
|
|
|
export default {
|
|
|
name: "StudentCourseList",
|
|
|
@@ -114,79 +141,116 @@ export default {
|
|
|
return {
|
|
|
dialog: false,
|
|
|
dialog2: false,
|
|
|
- dialog3: false,
|
|
|
+ msg: "",
|
|
|
+ currentCourseId: 0,
|
|
|
currentCourseName: "",
|
|
|
- currentCoursePrice: 50,
|
|
|
+ currentCoursePrice: 0,
|
|
|
colorList: ["#26A69A", "#00B0FF", "#5C6BC0", "#FFB300", "#E57373"],
|
|
|
- types: ["软件工程", "算法", "网络"],
|
|
|
- courseList1: [
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 2,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 0,
|
|
|
- },
|
|
|
- ],
|
|
|
- courseList: [
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 0,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 2,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 0,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "软件工程",
|
|
|
- description: "介绍软件工程的方法以及实践",
|
|
|
- status: 0,
|
|
|
- },
|
|
|
- ],
|
|
|
+ currentTab: 0, // 0 1 2
|
|
|
+ primary: {
|
|
|
+ name: "初级",
|
|
|
+ totalPage: 1,
|
|
|
+ currentPage: 1,
|
|
|
+ list: [],
|
|
|
+ },
|
|
|
+ medium: {
|
|
|
+ name: "中级",
|
|
|
+ totalPage: 1,
|
|
|
+ currentPage: 1,
|
|
|
+ list: [],
|
|
|
+ },
|
|
|
+ advanced: {
|
|
|
+ name: "高级",
|
|
|
+ totalPage: 1,
|
|
|
+ currentPage: 1,
|
|
|
+ list: [],
|
|
|
+ },
|
|
|
+ searchText: "",
|
|
|
+ searchCourse: [],
|
|
|
+ searchTotalPage: 1,
|
|
|
+ searchCurrentPage: 1,
|
|
|
};
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ "primary.currentPage": {
|
|
|
+ handler: function(val) {
|
|
|
+ this.handleGetCoursesByType(val, "primary");
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ "medium.currentPage": {
|
|
|
+ handler: function(val) {
|
|
|
+ this.handleGetCoursesByType(val, "medium");
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ "advance.currentPage": {
|
|
|
+ handler: function(val) {
|
|
|
+ this.handleGetCoursesByType(val, "advanced");
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ searchCurrentPage: function() {
|
|
|
+ this.handleSearchCourse();
|
|
|
+ },
|
|
|
+
|
|
|
+ searchText: function() {
|
|
|
+ this.handleSearchCourse();
|
|
|
+ },
|
|
|
+ },
|
|
|
methods: {
|
|
|
- showDialog(courseName, coursePrice) {
|
|
|
+ showDialog(courseId, courseName, coursePrice) {
|
|
|
+ this.currentCourseId = courseId;
|
|
|
this.currentCourseName = courseName;
|
|
|
this.currentCoursePrice = coursePrice;
|
|
|
this.dialog = true;
|
|
|
},
|
|
|
|
|
|
handleBuyCourse() {
|
|
|
- Promise.resolve(1).then((res) => {
|
|
|
+ const uid = window.localStorage.getItem("userId");
|
|
|
+ createOrder({
|
|
|
+ courseId: this.currentCourseId,
|
|
|
+ courseName: this.currentCourseName,
|
|
|
+ cost: this.currentCoursePrice,
|
|
|
+ userId: uid,
|
|
|
+ status: 2,
|
|
|
+ }).then((res) => {
|
|
|
this.dialog = false;
|
|
|
- if (res) {
|
|
|
- this.dialog2 = true;
|
|
|
- } else {
|
|
|
- this.dialog3 = true;
|
|
|
- }
|
|
|
+ this.msg =
|
|
|
+ (res.code === 1 ? "「购买成功」!" : "「购买失败」!") + res.msg;
|
|
|
+ this.dialog2 = true;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ handleGetCoursesByType(page, type) {
|
|
|
+ const uid = window.localStorage.getItem("userId");
|
|
|
+ const typeMap = { primary: "初级", medium: "中级", advanced: "高级" };
|
|
|
+ getCoursesByType({ uid, type: typeMap[type], page }).then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ this[type].totalPage = res.total;
|
|
|
+ this[type].list = res.list;
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
+ handleSearchCourse() {
|
|
|
+ const uid = window.localStorage.getItem("userId");
|
|
|
+ getCoursesByKey({
|
|
|
+ uid,
|
|
|
+ key: this.searchText,
|
|
|
+ page: this.searchCurrentPage,
|
|
|
+ }).then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ this.searchCourse = res.list;
|
|
|
+ this.searchTotalPage = res.total;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ mounted() {
|
|
|
+ ["primary", "medium", "advanced"].forEach((t) => {
|
|
|
+ this.handleGetCoursesByType(1, t);
|
|
|
+ });
|
|
|
+ this.handleSearchCourse();
|
|
|
},
|
|
|
};
|
|
|
</script>
|