|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<view class="container">
|
|
|
<!-- 搜索 -->
|
|
|
- <u-search @search="search" :show-action="false" shape="round" placeholder="搜索您想要的内容"
|
|
|
+ <u-search @search="toSearch" :show-action="false" shape="round" placeholder="搜索您想要的内容"
|
|
|
v-model="searchForm.keyword"></u-search>
|
|
|
<!-- tabs -->
|
|
|
<view style="padding-top: 20rpx;display: flex;">
|
|
@@ -22,7 +22,7 @@
|
|
|
<text>{{ course.courseName }}</text>
|
|
|
<image style="width: 25rpx;height: 25rpx;padding-left: 20rpx;"
|
|
|
:src="course.hasFavi ? 'https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/edu-icon/favi-icon.png' : 'https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/edu-icon/no-favi-icon.png'"
|
|
|
- @click.stop="collectCourse(course.id, index)">
|
|
|
+ @click.stop="collectCourse(course.id, index, course.hasFavi)">
|
|
|
</image>
|
|
|
</view>
|
|
|
<view class="course-type">{{ course.courseType }}</view>
|
|
@@ -41,18 +41,24 @@
|
|
|
<u-line />
|
|
|
</view>
|
|
|
</view>
|
|
|
+ <view>
|
|
|
+ <uni-load-more :status="loadMoreStatus"></uni-load-more>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
import {
|
|
|
- ref,onMounted,watch
|
|
|
+ ref, onMounted, watch,
|
|
|
} from 'vue';
|
|
|
import {
|
|
|
+ onReachBottom
|
|
|
} from '@dcloudio/uni-app'
|
|
|
- import { loadCourseCate, loadCourseList } from "@/api/edu.js"
|
|
|
+ import { loadCourseCate, loadCourseList, courseFavi, courseCancelFavi } from "@/api/edu.js"
|
|
|
import { useCourseStore } from "@/store/courseStore.js"
|
|
|
+ import { useAuthStore } from '@/store/authStore.js';
|
|
|
const courseStore = useCourseStore();
|
|
|
+ const authStore = useAuthStore();
|
|
|
const isMember = ref(false);
|
|
|
const tabsList = ref([]);
|
|
|
const currentTab = ref(courseStore.currentTab);
|
|
@@ -61,6 +67,11 @@
|
|
|
pageNumber: 1,
|
|
|
pageSize: 10,
|
|
|
})
|
|
|
+ const pageNumber = ref(1)
|
|
|
+ const pageSize = ref(10)
|
|
|
+ const total = ref(0)
|
|
|
+ const loadMoreStatus = ref('more')
|
|
|
+
|
|
|
const courseMember = {
|
|
|
1: "免费",
|
|
|
2: "会员免费",
|
|
@@ -80,78 +91,6 @@
|
|
|
hasFavi: true,
|
|
|
payType: "免费" // 新增字段,标识课程的付费类型
|
|
|
},
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- courseName: "Vue.js 从入门到精通",
|
|
|
- courseType: "领袖锻造营",
|
|
|
- name: "李老师",
|
|
|
- courseDate: "2023-09-15",
|
|
|
- imgUrl: "https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c",
|
|
|
- price: 199.00,
|
|
|
- hasBuy: false,
|
|
|
- hasFavi: false,
|
|
|
- payType: "会员免费"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- courseName: "React 开发实战",
|
|
|
- courseType: "领袖锻造营",
|
|
|
- name: "王老师",
|
|
|
- courseDate: "2023-11-05",
|
|
|
- imgUrl: "https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M03/00/0C/Cg-4zFS8bC-Ie9zBADCvovJAqiEAATJ8wDX__cAMK-6184.jpg",
|
|
|
- price: 149.00,
|
|
|
- hasBuy: false,
|
|
|
- hasFavi: false,
|
|
|
- payType: "付费"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 4,
|
|
|
- courseName: "Node.js 全栈开发",
|
|
|
- courseType: "合规专训营",
|
|
|
- name: "赵老师",
|
|
|
- courseDate: "2023-08-20",
|
|
|
- imgUrl: "https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c",
|
|
|
- price: 299.00,
|
|
|
- hasBuy: true,
|
|
|
- hasFavi: false,
|
|
|
- payType: "付费"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 5,
|
|
|
- courseName: "移动端开发技巧",
|
|
|
- courseType: "精英训练营",
|
|
|
- name: "钱老师",
|
|
|
- courseDate: "2025-07-18",
|
|
|
- imgUrl: "https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M03/00/0C/Cg-4zFS8bC-Ie9zBADCvovJAqiEAATJ8wDX__cAMK-6184.jpg",
|
|
|
- price: 89.00,
|
|
|
- hasBuy: true,
|
|
|
- hasFavi: false,
|
|
|
- payType: "付费"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 6,
|
|
|
- courseName: "11Vue.js 从入门到精通",
|
|
|
- courseType: "领袖锻造营",
|
|
|
- name: "李老师11",
|
|
|
- courseDate: "2023-09-15",
|
|
|
- imgUrl: "https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c",
|
|
|
- price: 199.00,
|
|
|
- hasBuy: true,
|
|
|
- hasFavi: false,
|
|
|
- payType: "会员免费"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 7,
|
|
|
- courseName: "113Vue.js 从入门到精通",
|
|
|
- courseType: "领袖锻造营",
|
|
|
- name: "李老师11",
|
|
|
- courseDate: "2025-09-15",
|
|
|
- imgUrl: "https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c",
|
|
|
- price: 199.00,
|
|
|
- hasBuy: true,
|
|
|
- hasFavi: false,
|
|
|
- payType: "会员免费"
|
|
|
- },
|
|
|
]);
|
|
|
|
|
|
// 按钮的文字
|
|
@@ -159,10 +98,10 @@
|
|
|
const currentDate = new Date();
|
|
|
const classDate = new Date(course.courseDate);
|
|
|
|
|
|
- if (course.payType === "免费") {
|
|
|
+ if (course.payType === '1') {
|
|
|
return "免费";
|
|
|
}
|
|
|
- if (course.payType === "会员免费") {
|
|
|
+ if (course.payType === '2') {
|
|
|
if (isMember.value) return "会员免费";
|
|
|
if (!course.hasBuy && !isMember.value) return "会员免费";
|
|
|
if (course.hasBuy) {
|
|
@@ -170,7 +109,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (course.payType === "付费") {
|
|
|
+ if (course.payType === '3') {
|
|
|
if (!course.hasBuy) return "点击购买";
|
|
|
return currentDate < classDate ? "点击查看" : "点击查看回放";
|
|
|
}
|
|
@@ -181,13 +120,13 @@
|
|
|
|
|
|
// 按钮的样式
|
|
|
function getButtonClass(course) {
|
|
|
- if (courseMember[course.payType] === "免费") return 'free';
|
|
|
- if (courseMember[course.payType] === "会员免费") {
|
|
|
+ if (courseMember[course.payType] === '免费') return 'free';
|
|
|
+ if (courseMember[course.payType] === '会员免费') {
|
|
|
if (isMember.value) return 'member-free';
|
|
|
return course.hasBuy ? (new Date() < new Date(course.courseDate) ? 'purchased' : 'replay') :
|
|
|
'member-free';
|
|
|
}
|
|
|
- if (courseMember[course.payType] === "付费") {
|
|
|
+ if (courseMember[course.payType] === '付费') {
|
|
|
return course.hasBuy ? (new Date() < new Date(course.courseDate) ? 'purchased' : 'replay') : 'purchase';
|
|
|
}
|
|
|
return 'error';
|
|
@@ -216,15 +155,54 @@
|
|
|
}
|
|
|
filterCourses.value = courses.value.filter(item => item.courseType == tabsList.value[index].name)
|
|
|
}
|
|
|
+ function toSearch(e){
|
|
|
+ pageNumber.value = 1
|
|
|
+ search(e)
|
|
|
+ }
|
|
|
// 搜索
|
|
|
function search(e) {
|
|
|
- console.log(e, "searchForm.keyword")
|
|
|
+ searchForm.value.keyword = e
|
|
|
+ searchForm.value.pageNumber = pageNumber.value
|
|
|
+ searchForm.value.pageSize = pageSize.value
|
|
|
+ courses.value = pageNumber.value == 1? [] : courses.value
|
|
|
+ loadMoreStatus.value = 'loading'
|
|
|
+ loadCourseList(searchForm.value).then(res=>{
|
|
|
+ if(res?.data){
|
|
|
+ total.value = res.count;
|
|
|
+ courses.value = [...courses.value,...res.data];
|
|
|
+ const i = currentTab.value
|
|
|
+ if( i == 0){
|
|
|
+ filterCourses.value = [...courses.value];
|
|
|
+ }else{
|
|
|
+ filterCourses.value = courses.value.filter(item => item.courseType == tabsList.value[i].name)
|
|
|
+ }
|
|
|
+ loadMoreStatus.value = total.value === courses.value.length ? 'nomore': 'more';
|
|
|
+ pageNumber.value++;
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
// 收藏
|
|
|
- function collectCourse(id,index) {
|
|
|
+ async function collectCourse(id,index,hasFavi) {
|
|
|
+ try{
|
|
|
+ let res;
|
|
|
+ if(hasFavi){
|
|
|
+ res = await courseCancelFavi({
|
|
|
+ id
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ res = await courseFavi({id})
|
|
|
+ }
|
|
|
+ if(res.code == 0){
|
|
|
+ courses.value[index].hasFavi = !courses.value[index].hasFavi
|
|
|
+ }
|
|
|
+ }catch(err){
|
|
|
+ courses.value[index].hasFavi = courses.value[index].hasFavi
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 联调后端,
|
|
|
// 返回成功后
|
|
|
- courses.value[index].hasFavi = !courses.value[index].hasFavi
|
|
|
+
|
|
|
}
|
|
|
// 初始化
|
|
|
function init() {
|
|
@@ -233,13 +211,8 @@
|
|
|
tabsList.value = [{ code: '', name: '全部'}, ...res.data]
|
|
|
}
|
|
|
})
|
|
|
- searchForm.value.keyword = ""
|
|
|
- loadCourseList(searchForm.value).then(res=>{
|
|
|
- if(res?.data){
|
|
|
- courses.value = res.data;
|
|
|
- filterCourses.value = [...courses.value];
|
|
|
- }
|
|
|
- })
|
|
|
+ pageNumber.value = 1;
|
|
|
+ search("");
|
|
|
// 初始化页面,获取数据
|
|
|
// filterCourses.value = courses.value
|
|
|
}
|
|
@@ -250,13 +223,18 @@
|
|
|
});
|
|
|
}
|
|
|
onMounted(() => {
|
|
|
- const userInfo = uni.getStorageSync("userinfo");
|
|
|
- isMember.value = userInfo.isMember
|
|
|
+ isMember.value = authStore.userInfo.isMember
|
|
|
init();
|
|
|
watch(currentTab, (newValue) => {
|
|
|
courseStore.setCurrentTab(newValue); // 如果需要在切换时更新 Pinia 状态
|
|
|
});
|
|
|
});
|
|
|
+ onReachBottom(()=>{
|
|
|
+ if(courses.value.length === total.value){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ search(searchForm.value.keyword);
|
|
|
+ })
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|