fix: 修复床位分配对象展示与卫生检查提交误报校验
恢复房间床位详情完整关联查询以显示学院/班级/学生;修复卫生检查 Web/移动端表单校验误报,并将房间学生 ID 以字符串返回避免精度丢失。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3518ea697e
commit
6a0f1206fa
6 files changed
+193
-131
No files matched your search
@@ -110,7 +110,7 @@
|
||||
</u-form-item>
|
||||
|
||||
<!-- 宿舍扣分 -->
|
||||
<u-form-item label="宿舍扣分" prop="totalScore">
|
||||
<u-form-item label="宿舍扣分">
|
||||
<u-input
|
||||
v-model="formData.totalScore"
|
||||
type="digit"
|
||||
@@ -1013,19 +1013,16 @@ export default {
|
||||
syncClassOptionsFromStudents(students, preferClassId) {
|
||||
const map = new Map();
|
||||
(students || []).forEach((student) => {
|
||||
if (
|
||||
student.classId == null ||
|
||||
student.classId === '' ||
|
||||
student.classId === 0 ||
|
||||
student.classId === '0'
|
||||
) {
|
||||
const classId = student.classId != null ? student.classId : student.class_id;
|
||||
const className = student.className || student.class_name;
|
||||
if (classId == null || classId === '' || classId === 0 || classId === '0') {
|
||||
return;
|
||||
}
|
||||
const key = String(student.classId);
|
||||
const key = String(classId);
|
||||
if (!map.has(key)) {
|
||||
map.set(key, {
|
||||
classId: student.classId,
|
||||
className: student.className || key,
|
||||
classId: key,
|
||||
className: className || key,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -2466,17 +2463,12 @@ export default {
|
||||
// 提交表单
|
||||
async handleSubmit() {
|
||||
try {
|
||||
// 表单验证
|
||||
await this.$refs.formRef.validate();
|
||||
|
||||
if ((this.formData.totalScore || 0) > 100) {
|
||||
uni.showToast({ title: '宿舍合计扣分不能超过100分', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.formData.classId) {
|
||||
// 归属班级:无选项时给出明确提示(避免被统一文案掩盖)
|
||||
if (!this.classOptions.length || !this.formData.classId) {
|
||||
uni.showToast({
|
||||
title: '请选择归属班级(取自当前寝室在住学生)',
|
||||
title: this.classOptions.length
|
||||
? '请选择归属班级'
|
||||
: '当前寝室无在住学生班级,无法提交宿舍扣分',
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
@@ -2487,6 +2479,44 @@ export default {
|
||||
if (matchedClass) {
|
||||
this.formData.className = matchedClass.className;
|
||||
}
|
||||
if (!this.formData.className) {
|
||||
uni.showToast({ title: '归属班级名称缺失,请重新选择归属班级', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!this.formData.hygieneGrade) {
|
||||
uni.showToast({ title: '请选择卫生等级', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 只校验有 rules 的字段。uView 全量 validate() 会把无 prop 的 form-item
|
||||
// 当成 undefined 一并校验,内部 child.prop.split 抛错,误报「表单不完整」
|
||||
const formRef = this.$refs.formRef;
|
||||
if (formRef && typeof formRef.validateField === 'function') {
|
||||
const propsToValidate = Object.keys(this.rules || {});
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
formRef.validateField(propsToValidate, (errors) => {
|
||||
if (errors && errors.length) {
|
||||
reject(errors);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (validateError) {
|
||||
const firstMsg =
|
||||
Array.isArray(validateError) && validateError[0] && validateError[0].message
|
||||
? validateError[0].message
|
||||
: '请检查表单填写是否完整';
|
||||
uni.showToast({ title: firstMsg, icon: 'none' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((this.formData.totalScore || 0) > 100) {
|
||||
uni.showToast({ title: '宿舍合计扣分不能超过100分', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
this.submitLoading = true;
|
||||
|
||||
@@ -2498,20 +2528,23 @@ export default {
|
||||
.map((file) => file.ossId);
|
||||
this.formData.attachmentIds = attachmentOssIds.join(',');
|
||||
|
||||
// 雪花 ID 统一转字符串,避免 JS 精度丢失
|
||||
const toId = (v) => (v == null || v === '' ? undefined : String(v));
|
||||
|
||||
// 处理学生评分数据
|
||||
const studentScores = this.roomStudents.map((student) => ({
|
||||
studentId: student.studentId,
|
||||
studentId: toId(student.studentId),
|
||||
studentName: student.studentName,
|
||||
studentNo: student.studentNo,
|
||||
classId: student.classId,
|
||||
className: student.className,
|
||||
majorId: student.majorId,
|
||||
majorName: student.majorName,
|
||||
collegeId: student.collegeId,
|
||||
collegeName: student.collegeName,
|
||||
bedId: student.bedId,
|
||||
bedCode: student.bedCode,
|
||||
bedName: student.bedName,
|
||||
classId: toId(student.classId || student.class_id),
|
||||
className: student.className || student.class_name,
|
||||
majorId: toId(student.majorId || student.major_id),
|
||||
majorName: student.majorName || student.major_name,
|
||||
collegeId: toId(student.collegeId || student.college_id),
|
||||
collegeName: student.collegeName || student.college_name,
|
||||
bedId: toId(student.bedId || student.bed_id),
|
||||
bedCode: student.bedCode || student.bed_code,
|
||||
bedName: student.bedName || student.bed_name,
|
||||
studentScore: student.student_score || 0,
|
||||
attendanceStatus: student.attendance_status || '1',
|
||||
studentGrade: student.student_grade || 'A',
|
||||
@@ -2526,7 +2559,7 @@ export default {
|
||||
violations.forEach((violation) => {
|
||||
violationData.push({
|
||||
...violation,
|
||||
studentId,
|
||||
studentId: toId(studentId),
|
||||
violationSource: '1', // 宿舍卫生检查来源
|
||||
});
|
||||
});
|
||||
@@ -2537,22 +2570,24 @@ export default {
|
||||
// 基础检查信息
|
||||
checkTitle: this.checkInfo.checkTitle,
|
||||
checkDate: this.checkInfo.checkDate,
|
||||
checkerId: this.checkInfo.checkerId,
|
||||
checkerId: toId(this.checkInfo.checkerId),
|
||||
checkerName: this.checkInfo.checkerName,
|
||||
checkType: this.checkInfo.checkType,
|
||||
checkLevel: this.checkInfo.checkLevel,
|
||||
|
||||
// 房间信息
|
||||
roomId: this.roomInfo.id,
|
||||
roomId: toId(this.roomInfo.id),
|
||||
roomCode: this.roomInfo.roomCode || this.roomInfo.roomName,
|
||||
roomName: this.roomInfo.roomName,
|
||||
buildingId: this.checkInfo.buildingId,
|
||||
buildingId: toId(this.checkInfo.buildingId),
|
||||
buildingName: this.checkInfo.buildingName,
|
||||
campusId: this.checkInfo.campusId,
|
||||
campusId: toId(this.checkInfo.campusId),
|
||||
campusName: this.checkInfo.campusName,
|
||||
|
||||
// 宿舍整体评分
|
||||
...this.formData,
|
||||
classId: toId(this.formData.classId),
|
||||
className: this.formData.className,
|
||||
deductionItems: this.deductionItems,
|
||||
|
||||
// 学生评分数据
|
||||
@@ -2590,7 +2625,11 @@ export default {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('提交表单失败:', error);
|
||||
uni.showToast({ title: '请检查表单填写是否完整', icon: 'none' });
|
||||
const msg =
|
||||
(error && (error.msg || error.message)) ||
|
||||
(typeof error === 'string' ? error : '') ||
|
||||
'保存失败,请重试';
|
||||
uni.showToast({ title: msg, icon: 'none' });
|
||||
} finally {
|
||||
this.submitLoading = false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user