677 lines
15 KiB
Vue
Raw Normal View History

2025-04-30 01:43:23 +08:00
<template>
<view class="interest-course">
<!-- 选课信息头部 - 固定部分 -->
<view class="selection-header">
<view class="header-content">
<view class="title-section">
<view class="title">
<text v-if="xkData && xkData.xkmc">{{ xkData.xkmc }}</text>
<text v-else>选课信息</text>
2025-04-30 01:43:23 +08:00
</view>
<!-- <view class="subtitle">互动兴趣课程</view> -->
2025-04-30 01:43:23 +08:00
</view>
<!-- 学生选择部分 -->
<view class="student-selector-bar" @click="showStudentSelector">
<view class="user-avatar">
<image
:src="currentStudent.avatar || '/static/base/home/11222.png'"
class="w-full h-full"
></image>
2025-04-30 01:43:23 +08:00
</view>
<view class="student-info">
<text class="student-name">{{ currentStudent.xm }}</text>
<text class="student-class"
>{{ currentStudent.njmc }} {{ currentStudent.bjmc }}</text
2025-05-06 13:03:49 +08:00
>
2025-04-30 01:43:23 +08:00
</view>
<view class="switch-btn" v-if="studentList.length > 1">切换</view>
</view>
</view>
</view>
2025-05-06 13:03:49 +08:00
<!-- 可滚动的内容区域 -->
<view class="scrollable-content">
<!-- 课程网格列表 -->
<view class="course-grid" v-if="courseListData.length > 0">
<view
v-for="(course, index) in courseListData"
:key="course.id || index"
class="course-item"
:class="{ selected: course.isSelected }"
>
<view class="course-name">{{ course.kcmc }}</view>
<view class="register-info">
<text>上课人数</text>
<text class="register-count">{{ course.ybmr }}</text>
2025-04-30 01:43:23 +08:00
</view>
<view class="detail-btn" @click.stop="viewCourseDetail(course)"
>详情</view
>
<view v-if="course.isSelected" class="selected-mark">
<uni-icons
type="checkbox-filled"
color="#3FBF72"
size="22"
></uni-icons>
2025-04-30 01:43:23 +08:00
</view>
</view>
</view>
2025-05-06 13:03:49 +08:00
<!-- 暂无数据提示 -->
<view v-else class="empty-course-list">
<view class="empty-icon">
<u-icon name="list" size="50" color="#C8C9CC"></u-icon>
2025-04-30 01:43:23 +08:00
</view>
<view class="empty-text">暂无课程数据</view>
</view>
</view>
2025-05-06 13:03:49 +08:00
<view>
<!-- 学生选择弹窗 -->
<u-popup
:show="showSelector"
@close="showSelector = false"
mode="bottom"
round="10"
>
<view class="student-selector">
<view class="selector-header">
<text class="selector-title">选择学生</text>
<u-icon
name="close"
size="20"
@click="showSelector = false"
></u-icon>
</view>
<view class="student-list">
<view
v-for="(student, index) in studentList"
:key="index"
class="student-item"
:class="{
'student-item-active': currentStudent.id === student.id,
}"
@click="switchStudent(student)"
>
<view class="student-avatar">
<image
:src="student.avatar || '/static/base/home/11222.png'"
class="w-full h-full"
></image>
</view>
<view class="student-info">
<text class="student-name">{{ student.xm }}</text>
<text class="student-class"
>{{ student.njmc }} {{ student.bjmc }}</text
>
</view>
<u-icon
v-if="currentStudent.id === student.id"
name="checkmark"
color="#409EFF"
size="20"
></u-icon>
</view>
</view>
2025-04-30 01:43:23 +08:00
</view>
</u-popup>
2025-04-30 01:43:23 +08:00
</view>
</view>
</template>
<script setup lang="ts">
import { navigateTo } from "@/utils/uniapp";
import {
ref,
computed,
reactive,
onBeforeUnmount,
watch,
onMounted,
} from "vue";
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
import { xkListApi, xsXkListApi } from "@/api/base/server";
import dayjs from "dayjs";
const { getUser } = useUserStore();
const { getData, setKcData, setData } = useDataStore();
const { sign_file } = getData;
// 学生列表数据
const studentList = computed(() => {
return getUser.xsList;
});
const currentStudent = ref();
// 控制选择器显示状态
const showSelector = ref(false);
if (studentList.value.length > 1) {
showSelector.value = true;
}
2025-04-30 01:43:23 +08:00
const xkData = ref();
const kcStatus = ref(false);
// 添加选课是否已结束的标记
const isEnrollmentEnded = ref(false);
// 添加轮询定时器变量
let pollTimer: number | null = null;
const courseInfo = ref({});
// 更新课程报名人数
const updateEnrollmentCount = (
data: Array<{ xkkcId: string; bmrs: number }>
) => {
if (!Array.isArray(courseListData.value) || courseListData.value.length === 0)
return;
let hasUpdates = false;
courseListData.value.forEach((course) => {
const newCount = data.find((item) => item.xkkcId === course.id);
if (newCount && course.ybmr !== newCount.bmrs) {
course.ybmr = newCount.bmrs;
hasUpdates = true;
}
});
// 如果有更新,强制重新渲染列表
if (hasUpdates) {
courseListData.value = [...courseListData.value];
}
};
// 在组件挂载时开始轮询
onMounted(() => {
});
// 加载课程列表
const loadCourseList = (currentStudent: any) => {
if (!currentStudent) {
uni.hideLoading();
return;
}
xsXkListApi({
xsId: currentStudent.id,
njId: currentStudent.njId,
xklxId: "962488654",
})
.then((res) => {
if (res.resultCode == 1) {
if (res.result && res.result.length) {
xkData.value = res.result[0];
} else {
xkData.value = [];
}
uni.hideLoading();
}
})
.catch(() => {
uni.hideLoading();
});
};
if (studentList.value.length > 0 && studentList.value.length === 1) {
currentStudent.value = studentList.value[0];
// 先加载课程列表,不立即检查报名状态
uni.showLoading({
title: "加载中...",
});
loadCourseList(currentStudent.value);
2025-04-30 01:43:23 +08:00
}
// 显示学生选择器
function showStudentSelector() {
if (studentList.value.length > 1) {
showSelector.value = true;
}
2025-04-30 01:43:23 +08:00
}
// 切换学生
function switchStudent(student: any) {
currentStudent.value = student;
showSelector.value = false;
2025-05-06 13:03:49 +08:00
// 显示加载中
uni.showLoading({
title: "加载中...",
});
2025-05-06 13:03:49 +08:00
// 显示切换成功提示
uni.showToast({
title: `已切换到${student.xm}`,
icon: "none",
});
2025-05-06 13:03:49 +08:00
// 先加载当前学生的课程列表,课程数据加载完成后会自动检查报名状态
loadCourseList(student);
}
2025-05-06 13:03:49 +08:00
// 从课程数据中提取课程列表
const displayCourseList = computed(() => {
if (
!xkData.value ||
!xkData.value.xkkcs ||
!Array.isArray(xkData.value.xkkcs)
) {
return [];
}
// 获取本地存储的已选课程ID
const selectedCourseId = uni.getStorageSync("selectedCourseId");
// 为课程添加选中状态属性
return xkData.value.xkkcs.map((course: any) => ({
...course,
isSelected: selectedCourseId && course.id === selectedCourseId,
}));
});
// 可修改的课程列表数据
const courseListData = ref<any[]>([]);
// 监听计算属性变化,更新可修改的数据
watch(
displayCourseList,
(newVal) => {
courseListData.value = JSON.parse(JSON.stringify(newVal));
// 初始化时将已选课程的全部信息存入courseInfo
const selectedCourseId = uni.getStorageSync("selectedCourseId");
if (selectedCourseId) {
const selectedCourse = newVal.find(
(course: any) => course.id === selectedCourseId
);
if (selectedCourse) {
courseInfo.value = selectedCourse;
2025-04-30 01:43:23 +08:00
}
}
},
{ immediate: true }
);
// 查看课程详情
const viewCourseDetail = (course: any) => {
setKcData(course);
uni.navigateTo({
url: `/pages/base/course-selection/detail`,
});
};
// 页面卸载前清除定时器
onBeforeUnmount(() => {
});
</script>
<style lang="scss" scoped>
.interest-course {
min-height: 100%;
background-color: #f5f7fa;
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
2025-04-30 01:43:23 +08:00
}
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px;
height: 44px;
background-color: #fff;
2025-05-06 13:03:49 +08:00
.nav-left {
width: 40px;
height: 40px;
2025-04-30 01:43:23 +08:00
display: flex;
align-items: center;
}
2025-05-06 13:03:49 +08:00
.nav-title {
font-size: 18px;
font-weight: 500;
color: #333;
2025-04-30 01:43:23 +08:00
}
2025-05-06 13:03:49 +08:00
.nav-right {
width: 40px;
2025-04-30 01:43:23 +08:00
display: flex;
justify-content: flex-end;
}
}
2025-05-06 13:03:49 +08:00
.selection-header {
background: linear-gradient(135deg, #4a90e2, #2879ff);
padding: 20px 15px;
color: #fff;
border-radius: 0 0 15px 15px;
box-shadow: 0 4px 12px rgba(40, 121, 255, 0.2);
position: sticky;
top: 0;
left: 0;
right: 0;
z-index: 10;
.header-content {
display: flex;
flex-direction: column;
gap: 15px;
2025-05-06 13:03:49 +08:00
.title-section {
.title {
font-size: 24px;
font-weight: bold;
}
2025-05-06 13:03:49 +08:00
.subtitle {
font-size: 14px;
opacity: 0.8;
2025-04-30 01:43:23 +08:00
}
}
2025-05-06 13:03:49 +08:00
// 学生选择栏样式
.student-selector-bar {
display: flex;
align-items: center;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 10px;
.user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #fff;
overflow: hidden;
margin-right: 10px;
}
.student-info {
flex: 1;
2025-04-30 01:43:23 +08:00
display: flex;
flex-direction: column;
2025-05-06 13:03:49 +08:00
.student-name {
font-size: 16px;
font-weight: 500;
margin-bottom: 2px;
2025-04-30 01:43:23 +08:00
}
2025-05-06 13:03:49 +08:00
.student-class {
font-size: 12px;
opacity: 0.8;
2025-04-30 01:43:23 +08:00
}
}
2025-05-06 13:03:49 +08:00
.switch-btn {
padding: 4px 12px;
background-color: rgba(255, 255, 255, 0.2);
color: #fff;
border-radius: 20px;
font-size: 13px;
}
}
.countdown-section {
.countdown-title {
font-size: 14px;
margin-bottom: 8px;
}
.countdown-timer {
display: flex;
align-items: center;
.time-block {
background-color: rgba(255, 255, 255, 0.2);
border-radius: 6px;
min-width: 40px;
padding: 5px 8px;
text-align: center;
.time-value {
font-size: 20px;
font-weight: bold;
display: block;
}
.time-unit {
font-size: 12px;
opacity: 0.9;
}
}
.time-separator {
font-size: 20px;
font-weight: bold;
margin: 0 5px;
2025-04-30 01:43:23 +08:00
}
}
}
}
}
// 可滚动内容区域样式
.scrollable-content {
flex: 1;
overflow-y: auto;
-webkit-overflow-scrolling: touch; // 增强iOS滚动体验
}
2025-05-06 13:03:49 +08:00
.course-grid {
display: flex;
flex-wrap: wrap;
padding: 15px 15px 0 15px;
.course-item {
position: relative;
width: calc(50% - 10px);
margin-bottom: 15px;
background-color: #fff;
border-radius: 8px;
padding: 15px;
box-sizing: border-box;
border: 1px solid transparent;
transition: all 0.3s ease;
&:nth-child(odd) {
margin-right: 10px;
}
&:nth-child(even) {
margin-left: 10px;
}
2025-05-06 13:03:49 +08:00
&.selected {
border: 1px solid #3fbf72;
background-color: rgba(63, 191, 114, 0.05);
box-shadow: 0 2px 8px rgba(63, 191, 114, 0.15);
}
.course-name {
2025-04-30 01:43:23 +08:00
font-size: 16px;
font-weight: 500;
color: #333;
margin-bottom: 10px;
2025-04-30 01:43:23 +08:00
}
2025-05-06 13:03:49 +08:00
.register-info {
font-size: 14px;
color: #666;
margin-bottom: 12px;
2025-05-06 13:03:49 +08:00
.register-count {
color: #2879ff;
2025-04-30 01:43:23 +08:00
}
}
2025-05-06 13:03:49 +08:00
.detail-btn {
display: inline-block;
color: #2879ff;
font-size: 14px;
2025-04-30 01:43:23 +08:00
}
2025-05-06 13:03:49 +08:00
.selected-mark {
position: absolute;
top: -6px;
right: -6px;
2025-04-30 01:43:23 +08:00
}
}
}
.register-btn-container {
position: sticky;
bottom: 0;
left: 0;
right: 0;
padding: 15px;
background-color: #fff;
z-index: 10;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
.register-btn {
height: 50px;
line-height: 50px;
text-align: center;
background-color: #2879ff;
color: #fff;
border-radius: 25px;
font-size: 16px;
font-weight: 500;
}
}
/* 学生选择器弹窗样式 */
.student-selector {
2025-04-30 01:43:23 +08:00
background-color: #ffffff;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
padding-bottom: 20px;
2025-05-06 13:03:49 +08:00
.selector-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
2025-04-30 01:43:23 +08:00
border-bottom: 1px solid #f2f2f2;
2025-05-06 13:03:49 +08:00
.selector-title {
2025-04-30 01:43:23 +08:00
font-size: 16px;
font-weight: 500;
color: #303133;
}
}
2025-05-06 13:03:49 +08:00
.student-list {
padding: 0 15px;
2025-05-06 13:03:49 +08:00
.student-item {
display: flex;
align-items: center;
padding: 15px 0;
border-bottom: 1px solid #f2f2f2;
2025-05-06 13:03:49 +08:00
&:last-child {
border-bottom: none;
}
&-active {
background-color: rgba(64, 158, 255, 0.05);
}
.student-avatar {
width: 45px;
height: 45px;
border-radius: 50%;
background-color: #f0f0f0;
overflow: hidden;
flex-shrink: 0;
2025-04-30 01:43:23 +08:00
}
2025-05-06 13:03:49 +08:00
.student-info {
flex: 1;
margin-left: 12px;
.student-name {
font-size: 15px;
font-weight: 500;
color: #303133;
margin-bottom: 4px;
}
.student-class {
font-size: 13px;
color: #606266;
}
2025-04-30 01:43:23 +08:00
}
}
}
}
/* 全局图片样式 */
.w-full {
width: 100%;
}
.h-full {
height: 100%;
}
// 暂无数据样式
.empty-course-list {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 20px;
text-align: center;
.empty-icon {
margin-bottom: 20px;
background-color: #f5f6f7;
width: 80px;
height: 80px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.empty-text {
font-size: 18px;
font-weight: 500;
color: #303133;
margin-bottom: 8px;
}
.empty-desc {
font-size: 14px;
color: #909399;
max-width: 80%;
line-height: 1.5;
}
}
/* 选课已结束样式 */
.enrollment-ended {
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 8px;
padding: 12px 15px;
font-size: 16px;
font-weight: 500;
color: #fff;
gap: 8px;
}
2025-05-06 13:03:49 +08:00
</style>