提交代码

This commit is contained in:
zlwu committed 2025-08-16 22:44:56 +08:00
1 parent 8e1c094d6e
commit 788daa3638
16 files changed
+1462 -56

No files matched your search

@@ -641,7 +641,7 @@ export interface DormHygieneCheckCompleteForm extends DormHygieneCheckForm {
/**
* 学生评分数据列表
*/
studentData?: DormHygieneStudentScoreForm[];
studentScores?: DormHygieneStudentScoreForm[];
}
@@ -491,11 +491,22 @@ const setCachedData = (key: string, data: any[]) => {
cacheTimestamps.value.set(key, Date.now());
};
// 生成默认检查标题的辅助函数
const generateDefaultCheckTitle = () => {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const defaultTitle = `${year}${month}${day}宿舍卫生检查`;
console.log('生成默认检查标题:', defaultTitle);
return defaultTitle;
};
// 表单数据
const initFormData: DormHygieneCheckForm = {
id: undefined,
deleted: undefined,
checkTitle: undefined,
checkTitle: generateDefaultCheckTitle(), // 默认以时间开头的检查标题
checkDate: new Date().toISOString().slice(0, 19).replace('T', ' '), // 默认当前时间
checkerId: undefined, // 将在组件挂载时通过API获取当前登录用户ID
checkerName: undefined, // 将在组件挂载时通过API获取当前登录用户姓名
@@ -602,6 +613,11 @@ watch(
// 如果是新增(没有id),设置默认值
if (!newData.id) {
// 检查标题默认值 - 修复判断逻辑
if (!newData.checkTitle || newData.checkTitle === '') {
defaultData.checkTitle = generateDefaultCheckTitle();
}
// 检查日期默认值
if (!newData.checkDate) {
defaultData.checkDate = new Date().toISOString().slice(0, 19).replace('T', ' ');
@@ -642,7 +658,27 @@ watch(
}
}
Object.assign(form, { ...defaultData, ...newData });
// 确保新增时默认值正确设置
if (!newData.id) {
// 新增时,优先使用默认值,然后合并传入的数据
// 过滤掉空字符串,确保默认值不被覆盖
const filteredNewData: any = {};
Object.keys(newData).forEach((key) => {
const value = (newData as any)[key];
if (value !== '' && value !== null && value !== undefined) {
filteredNewData[key] = value;
}
});
console.log('原始传入数据:', newData);
console.log('过滤后数据:', filteredNewData);
console.log('默认数据:', defaultData);
Object.assign(form, { ...defaultData, ...filteredNewData });
console.log('新增模式 - 设置表单数据:', form);
} else {
// 编辑时,直接使用传入的数据
Object.assign(form, { ...defaultData, ...newData });
console.log('编辑模式 - 设置表单数据:', form);
}
if (newData.id) {
handleAttachmentData();
@@ -669,6 +705,7 @@ const handleClose = () => {
const resetForm = () => {
const resetData = { ...initFormData };
resetData.checkDate = new Date().toISOString().slice(0, 19).replace('T', ' '); // 重置时使用当前时间
resetData.checkTitle = generateDefaultCheckTitle(); // 重置时重新生成检查标题
Object.assign(form, resetData);
// 异步获取并设置当前登录用户信息
@@ -705,29 +742,43 @@ const submitForm = () => {
form.attachmentIds = attachmentOssIds.join(',');
// 处理学生信息数据,转换为符合API接口的格式
const studentData = roomStudents.value.map((student: any) => ({
studentId: student.studentId,
studentName: student.studentName,
studentNo: student.studentNo,
className: student.className,
majorName: student.majorName,
collegeName: student.collegeName,
bedId: student.bedId,
bedCode: student.bedName, // 使用bedName作为bedCode
studentScore: student.student_score, // 转换为驼峰命名
attendanceStatus: student.attendance_status, // 转换为驼峰命名
studentGrade: student.student_grade, // 转换为驼峰命名
isResponsiblePerson: student.isResponsiblePerson || 0,
scoreRemarks: student.scoreRemarks || '',
improvementNotes: student.improvementNotes || ''
}));
const studentScores = roomStudents.value.map((student: any) => {
const studentScore: any = {
studentId: Number(student.studentId), // 确保是数字类型
studentName: student.studentName,
studentNo: student.studentNo,
className: student.className,
majorName: student.majorName,
collegeName: student.collegeName,
bedId: student.bedId ? Number(student.bedId) : undefined,
bedCode: student.bedName, // 使用bedName作为bedCode
studentScore: student.student_score ? Number(student.student_score) : undefined, // 确保是数字类型
attendanceStatus: student.attendance_status,
studentGrade: student.student_grade,
isResponsiblePerson: student.isResponsiblePerson ? Number(student.isResponsiblePerson) : 0, // 确保是数字类型
scoreRemarks: student.scoreRemarks || '',
improvementNotes: student.improvementNotes || ''
};
// 编辑时包含学生评分记录的ID,新增时不包含
if (form.id && student.id) {
studentScore.id = student.id;
}
return studentScore;
});
// 构建完整的提交数据
const submitData: DormHygieneCheckCompleteForm = {
...form,
studentData: studentData
studentScores: studentScores
};
// 调试日志:输出提交的数据结构
console.log('提交的完整数据:', submitData);
console.log('学生评分数据:', studentScores);
console.log('是否为编辑模式:', !!form.id);
emit('submit', submitData);
} catch (error) {
console.error('提交表单时发生错误:', error);
@@ -1056,6 +1107,50 @@ const loadRoomStudents = async () => {
roomStudentsLoading.value = true;
try {
// 如果是编辑模式且有检查记录ID,优先从学生评分表获取历史数据
if (form.id) {
console.log('编辑模式:从学生评分表获取历史数据,检查记录ID:', form.id);
// 调用获取学生评分数据的接口
const studentScoresRes = await request({
url: '/dormHygieneStudentScore/dormHygieneStudentScore/getByCheckId/' + form.id,
method: 'get'
});
if (studentScoresRes.code === 200 && studentScoresRes.data && studentScoresRes.data.length > 0) {
console.log('获取到历史学生评分数据:', studentScoresRes.data);
// 将历史评分数据转换为表格显示格式
roomStudents.value = studentScoresRes.data.map((studentScore: any) => ({
// 保存学生评分记录的ID,用于编辑时提交
id: studentScore.id,
studentId: studentScore.studentId,
studentName: studentScore.studentName,
studentNo: studentScore.studentNo,
className: studentScore.className,
majorName: studentScore.majorName,
collegeName: studentScore.collegeName,
bedId: studentScore.bedId,
bedName: studentScore.bedCode, // 使用bedCode作为bedName显示
gender: studentScore.gender || '1', // 默认女性,如果没有性别字段
// 使用历史评分数据
student_score: studentScore.studentScore || null,
attendance_status: studentScore.attendanceStatus || '1',
student_grade: studentScore.studentGrade || 'A',
isResponsiblePerson: studentScore.isResponsiblePerson || 0,
scoreRemarks: studentScore.scoreRemarks || '',
improvementNotes: studentScore.improvementNotes || ''
}));
console.log('转换后的学生数据:', roomStudents.value);
return;
} else {
console.log('未获取到历史学生评分数据,从房间学生表获取基础数据');
}
}
// 新增模式或没有历史数据时,从房间学生表获取基础数据
console.log('从房间学生表获取基础数据,房间ID:', form.roomId);
const res = await request({
url: '/dormBedStudent/dormBedStudent/getRoomStudents',
method: 'get',
@@ -1385,7 +1480,7 @@ const handleStudentGradeChange = (student: any) => {
// 处理宿舍总分变化 - 自动填写学生个人得分
const handleTotalScoreChange = () => {
// 验证宿舍总分范围
if (form.totalScore !== null && form.totalScore !== undefined && form.totalScore !== '' && form.totalScore !== 0) {
if (form.totalScore !== null && form.totalScore !== undefined && form.totalScore !== 0 && String(form.totalScore) !== '0') {
const score = parseFloat(form.totalScore.toString());
if (isNaN(score) || score < 0 || score > 100) {
ElMessage.warning('宿舍总分必须在0-100分之间');