选课调整

This commit is contained in:
hebo 2025-08-11 21:14:06 +08:00
parent 259c50828a
commit b1dbb96435
4 changed files with 159 additions and 26 deletions

View File

@ -18,6 +18,21 @@ export const xkgzsApi = async (params: any) => {
return await get("/api/gzs/findPage", params);
};
/**
*
*/
export const getLatestInterestCourseApi = async (params: any) => {
return await get("/api/xk/getLatestInterestCourse", params);
};
/**
*
*/
export const getCurrentSemesterTeacherCoursesApi = async (jsId?: string) => {
const params = jsId ? { jsId } : {};
return await get("/api/xkkc/getCurrentSemesterTeacherCourses", params);
};
/**
*
*/

View File

@ -20,6 +20,10 @@
<text class="register-count">{{ xkkc.hasNum || 0 }}</text>
<text> | {{ xkkc.maxNum || 0 }}</text>
</view>
<view class="study-time-info" v-if="xkkc.studyTime">
<text></text>
<text class="study-time">{{ xkkc.studyTime }}</text>
</view>
<view v-if="xkkc.isSelected" class="selected-mark">
<uni-icons
type="checkbox-filled"
@ -82,26 +86,53 @@ const toggleSelection = (xkkc: any) => {
}
// xkkc.hasNum--;
} else {
//
//
const maxNum = xkkc.maxNum || 0;
const hasNum = xkkc.hasNum || 0;
if (maxNum > hasNum) {
if (props.multiple) {
//
if (!selectedXkkcIds.includes(xkkc.id)) {
selectedXkkcIds.push(xkkc.id);
// xkkc.hasNum++;
}
} else {
//
selectedXkkcIds = [xkkc.id];
//
xkkcList.value.forEach((xkkc: any) => {
xkkc.isSelected = false;
});
}
xkkc.isSelected = true;
if (maxNum <= hasNum) {
uni.showToast({
title: '该课程已满员',
icon: 'none',
duration: 2000
});
return;
}
//
if (xkkc.studyTime && props.multiple) {
const hasTimeConflict = xkkcList.value.some((item: any) => {
//
return item.isSelected &&
item.id !== xkkc.id &&
item.studyTime === xkkc.studyTime;
});
if (hasTimeConflict) {
uni.showToast({
title: '上课时间重复,请重新选择!',
icon: 'none',
duration: 3000
});
return;
}
}
//
if (props.multiple) {
//
if (!selectedXkkcIds.includes(xkkc.id)) {
selectedXkkcIds.push(xkkc.id);
}
} else {
//
selectedXkkcIds = [xkkc.id];
//
xkkcList.value.forEach((item: any) => {
item.isSelected = false;
});
}
xkkc.isSelected = true;
}
//
uni.setStorageSync("selectedXkkcIds", selectedXkkcIds);
@ -214,12 +245,24 @@ if (props.xk && props.xk.xkkcs) {
.register-info {
font-size: 14px;
color: #666;
margin-bottom: 8px;
.register-count {
color: #2879ff;
}
}
.study-time-info {
font-size: 14px;
color: #666;
margin-bottom: 8px;
.study-time {
color: #ff6b35;
font-weight: 500;
}
}
.selected-mark {
position: absolute;
top: -6px;

View File

@ -51,9 +51,9 @@ const selectedXkkcIds = ref<any>([]);
const xsFlag = ref(true);
//
//
const checkEnrollmentStatus = (xk: any) => {
if (!xk || !xk.xkjstime) return;
if (!xk || !xk.xkjstime) return false;
const now = new Date().getTime();
const endTime = new Date(xk.xkjstime).getTime();
@ -76,7 +76,7 @@ const switchXk = (xk: any) => {
selectedXkkcIds.value = [];
uni.setStorageSync("selectedXkkcIds", []);
//
// xkXqk.vue
if (checkEnrollmentStatus(xk)) {
return;
}
@ -86,7 +86,7 @@ const switchXs = (xs: any) => {
xsFlag.value = false;
}
//
//
const xkTimeOver = (val: any) => {
console.log('选课时间结束:', val);
//
@ -109,7 +109,7 @@ const submit = async () => {
return;
}
//
//
if (curXk.value && curXk.value.xkkstime) {
const now = dayjs().valueOf();
const startTime = dayjs(curXk.value.xkkstime).valueOf();

View File

@ -1,6 +1,7 @@
import { defineStore } from "pinia";
import { authenticationApi, loginCode, loginPass, weChatLogin, checkOpenId } from "@/api/system/login";
import { checkXsXkByTypeApi, xsKxApi } from "@/api/base/xkApi";
import { getLatestInterestCourseApi } from "@/api/base/server";
import { jcGetJcBzListApi } from "@/api/base/jcApi";
import { AUTH_KEY } from "@/config";
import { imagUrl } from "@/utils";
@ -244,9 +245,77 @@ export const useUserStore = defineStore({
});
}
},
// 验证选课状态(时间验证)- 通用版本
async validateEnrollmentStatus(xklxId: string, courseType: string = '兴趣课') {
try {
// 获取选课信息进行验证
const res = await getLatestInterestCourseApi({ xklxId });
const xkInfo = res.result;
if (!xkInfo) {
uni.showToast({
title: '获取选课信息失败',
icon: 'none'
});
return false;
}
// 检查选课状态:如果 xkzt 等于 0表示未发布
if (xkInfo.xkzt === 0) {
// 选课未发布,跳转到课程报名尚未开放页面
uni.setStorageSync('title', courseType);
uni.reLaunch({
url: "/pages/base/xk/qk/wks",
});
return false;
}
// 检查选课是否已结束
if (xkInfo.xkjstime) {
const now = new Date().getTime();
const endTime = new Date(xkInfo.xkjstime).getTime();
if (now > endTime) {
// 选课已结束,跳转到结束页面
const courseInfo = encodeURIComponent(JSON.stringify(xkInfo));
uni.navigateTo({
url: `/pages/base/xk/qk/yjz?courseInfo=${courseInfo}`
});
return false;
}
}
// 所有验证通过
return true;
} catch (error) {
console.error('验证选课状态失败:', error);
uni.showToast({
title: '验证选课状态失败',
icon: 'none'
});
return false;
}
},
// 验证兴趣课选课状态(保持向后兼容)
async validateInterestCourseEnrollmentStatus() {
return this.validateEnrollmentStatus("962488654", "兴趣课");
},
// 验证俱乐部选课状态
async validateClubEnrollmentStatus() {
return this.validateEnrollmentStatus("816059832", "俱乐部");
},
// 校验兴趣课 - 优化版本
async checkXqk() {
try {
// 先验证选课状态(时间验证)
const validateResult = await this.validateInterestCourseEnrollmentStatus();
if (!validateResult) {
return; // 验证失败,已处理跳转
}
// 使用getXsKx接口获取详细选课信息
const res = await xsKxApi({
xsId: this.curXs.id,
@ -264,9 +333,9 @@ export const useUserStore = defineStore({
url: "/pages/base/xk/pay/index",
});
return;
case 2: // 可选课列表 - 跳转到抢课页面
case 2: // 可选课列表 - 跳转到告知书页
uni.reLaunch({
url: "/pages/base/xk/qk/xqk",
url: "/pages/base/gzs/xkXqk",
});
return;
case 3: // 已支付 - 跳转到详情页
@ -324,6 +393,12 @@ export const useUserStore = defineStore({
// 校验俱乐部 - 优化版本
async checkJlb() {
try {
// 先验证俱乐部选课状态(时间验证)
const validateResult = await this.validateClubEnrollmentStatus();
if (!validateResult) {
return; // 验证失败,已处理跳转
}
// 使用getXsKx接口获取详细选课信息
const res = await xsKxApi({
xsId: this.curXs.id,
@ -341,9 +416,9 @@ export const useUserStore = defineStore({
url: "/pages/base/xk/pay/index",
});
return;
case 2: // 可选课列表 - 跳转到抢课页面
case 2: // 可选课列表 - 跳转到告知书
uni.reLaunch({
url: "/pages/base/xk/qk/jlb",
url: "/pages/base/gzs/xkJlb",
});
return;
case 3: // 已支付 - 跳转到详情页