提交代码
This commit is contained in:
1 parent
4cf21648f5
commit
4e8b6d77b6
1 file changed
+117
-70
@@ -623,74 +623,75 @@ const handleLeaveTypeChange = (value: string) => {
|
||||
form.leaveTypeCode = leaveType.leaveTypeCode;
|
||||
|
||||
// 1. 处理销假状态逻辑
|
||||
if (leaveType.needCancelForNonLeave === '0') {
|
||||
// 当 need_cancel_for_non_leave 为 0-否 时
|
||||
if (form.isLeaveSchool === '0') {
|
||||
// 当 isLeaveSchool = 0 时,cancelStatus = 3 (无需销假)
|
||||
form.cancelStatus = '3';
|
||||
form.needCancel = '0';
|
||||
} else {
|
||||
// 其他时候,cancelStatus = 0 (未销假)
|
||||
form.cancelStatus = '0';
|
||||
form.needCancel = '1';
|
||||
}
|
||||
} else {
|
||||
// 当 need_cancel_for_non_leave 为 1-是 时,保持原有逻辑
|
||||
form.cancelStatus = '0';
|
||||
form.needCancel = '1';
|
||||
}
|
||||
// if (leaveType.needCancelForNonLeave === '0') {
|
||||
// // 当 need_cancel_for_non_leave 为 0-否 时
|
||||
// if (form.isLeaveSchool === '0') {
|
||||
// // 当 isLeaveSchool = 0 时,cancelStatus = 3 (无需销假)
|
||||
// form.cancelStatus = '3';
|
||||
// form.needCancel = '0';
|
||||
// } else {
|
||||
// // 其他时候,cancelStatus = 0 (未销假)
|
||||
// form.cancelStatus = '0';
|
||||
// form.needCancel = '1';
|
||||
// }
|
||||
// } else {
|
||||
// // 当 need_cancel_for_non_leave 为 1-是 时,保持原有逻辑
|
||||
// form.cancelStatus = '0';
|
||||
// form.needCancel = '1';
|
||||
// }
|
||||
|
||||
// 2. 处理是否可以提前请假的逻辑
|
||||
if (leaveType.canApplyInAdvance === '0') {
|
||||
// 不可以提前请假,开始时间不能选择今天之后的日期(只能选择今天之前的日期)
|
||||
// 这里我们通过日期选择器的 disabledDate 来控制
|
||||
// 在模板中已经设置了相应的限制
|
||||
}
|
||||
// if (leaveType.canApplyInAdvance === '0') {
|
||||
// // 不可以提前请假,开始时间不能选择今天之后的日期(只能选择今天之前的日期)
|
||||
// // 这里我们通过日期选择器的 disabledDate 来控制
|
||||
// // 在模板中已经设置了相应的限制
|
||||
// }
|
||||
|
||||
// 3. 处理最大申请时长的逻辑
|
||||
if (leaveType.maxApplyDuration && leaveType.maxApplyDuration > 0) {
|
||||
// 有最大申请时长限制,通过日期选择器的 disabledDate 来控制
|
||||
// 在模板中已经设置了相应的限制
|
||||
}
|
||||
// if (leaveType.maxApplyDuration && leaveType.maxApplyDuration > 0) {
|
||||
// // 有最大申请时长限制,通过日期选择器的 disabledDate 来控制
|
||||
// // 在模板中已经设置了相应的限制
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
// 清空选择时,同时清空类型编码和相关状态
|
||||
form.leaveTypeCode = '';
|
||||
form.cancelStatus = '0';
|
||||
form.needCancel = '1';
|
||||
}
|
||||
};
|
||||
|
||||
// 开始时间禁用逻辑
|
||||
const disabledStartDate = (time: Date) => {
|
||||
if (!currentLeaveType.value) return false;
|
||||
// if (!currentLeaveType.value) return false;
|
||||
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
// const today = new Date();
|
||||
// today.setHours(0, 0, 0, 0);
|
||||
|
||||
// 处理是否可以提前请假的逻辑
|
||||
if (currentLeaveType.value.canApplyInAdvance === '0') {
|
||||
// 不可以提前请假,开始时间不能选择今天之后的日期(只能选择今天之前的日期)
|
||||
if (time.getTime() > today.getTime()) {
|
||||
return true; // 禁用今天之后的日期
|
||||
}
|
||||
}
|
||||
// // 处理是否可以提前请假的逻辑
|
||||
// if (currentLeaveType.value.canApplyInAdvance === '0') {
|
||||
// // 不可以提前请假,开始时间不能选择今天之后的日期(只能选择今天之前的日期)
|
||||
// if (time.getTime() > today.getTime()) {
|
||||
// return true; // 禁用今天之后的日期
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// 结束时间禁用逻辑
|
||||
const disabledEndDate = (time: Date) => {
|
||||
if (!currentLeaveType.value) return false;
|
||||
// if (!currentLeaveType.value) return false;
|
||||
|
||||
// 结束时间不受 can_apply_in_advance 限制,可以选择任何日期
|
||||
// 但需要确保结束时间不能早于开始时间
|
||||
if (form.startTime) {
|
||||
const startDate = new Date(form.startTime);
|
||||
// 修改逻辑:允许选择与开始时间同一天及之后的日期
|
||||
if (time.getTime() < startDate.getTime()) {
|
||||
return true; // 只禁用早于开始时间的日期,允许同一天
|
||||
}
|
||||
}
|
||||
// // 结束时间不受 can_apply_in_advance 限制,可以选择任何日期
|
||||
// // 但需要确保结束时间不能早于开始时间
|
||||
// if (form.startTime) {
|
||||
// const startDate = new Date(form.startTime);
|
||||
// // 修改逻辑:允许选择与开始时间同一天及之后的日期
|
||||
// if (time.getTime() < startDate.getTime()) {
|
||||
// return true; // 只禁用早于开始时间的日期,允许同一天
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
};
|
||||
@@ -706,17 +707,17 @@ const calculateLeaveDuration = () => {
|
||||
const totalDays = diffInMilliseconds / (1000 * 60 * 60 * 24);
|
||||
|
||||
// 处理最大申请时长的逻辑
|
||||
if (currentLeaveType.value && currentLeaveType.value.maxApplyDuration && currentLeaveType.value.maxApplyDuration > 0) {
|
||||
console.log('totalDays', totalDays);
|
||||
console.log('currentLeaveType.value.maxApplyDuration', currentLeaveType.value.maxApplyDuration);
|
||||
if (totalDays > currentLeaveType.value.maxApplyDuration) {
|
||||
ElMessage.warning(`请假时长不能超过${currentLeaveType.value.maxApplyDuration}天`);
|
||||
// 清空结束时间
|
||||
form.endTime = '';
|
||||
form.leaveDuration = '';
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if (currentLeaveType.value && currentLeaveType.value.maxApplyDuration && currentLeaveType.value.maxApplyDuration > 0) {
|
||||
// console.log('totalDays', totalDays);
|
||||
// console.log('currentLeaveType.value.maxApplyDuration', currentLeaveType.value.maxApplyDuration);
|
||||
// if (totalDays > currentLeaveType.value.maxApplyDuration) {
|
||||
// ElMessage.warning(`请假时长不能超过${currentLeaveType.value.maxApplyDuration}天`);
|
||||
// // 清空结束时间
|
||||
// form.endTime = '';
|
||||
// form.leaveDuration = '';
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 格式化请假时长显示,保留2位小数
|
||||
form.leaveDuration = `${totalDays.toFixed(2)}`;
|
||||
@@ -851,6 +852,51 @@ const submitForm = (status: string) => {
|
||||
ElMessage.error('请假时间不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
// ====== 新增:请假类型相关校验逻辑 ======
|
||||
// 1. 默认需要销假
|
||||
form.needCancel = '1';
|
||||
form.cancelStatus = '0';
|
||||
|
||||
// 获取当前选中的请假类型配置
|
||||
const leaveType = currentLeaveType.value;
|
||||
if (!leaveType) {
|
||||
ElMessage.error('请先选择请假类型');
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 校验 needCancelForNonLeave(非离校请假是否需要销假)
|
||||
// needCancelForNonLeave = '0' 且 isLeaveSchool = '0' 时,不需要销假
|
||||
if (leaveType.needCancelForNonLeave === '0' && form.isLeaveSchool === '0') {
|
||||
form.needCancel = '0';
|
||||
form.cancelStatus = '3';
|
||||
// 业务上如有特殊cancelStatus要求可补充
|
||||
}
|
||||
|
||||
// 3. 校验 canApplyInAdvance(是否可以提前请假)
|
||||
if (leaveType.canApplyInAdvance === '0') {
|
||||
// 只能选择今天及以前的日期
|
||||
const now = new Date();
|
||||
now.setHours(23, 59, 59, 999);
|
||||
const start = new Date(form.startTime);
|
||||
if (start.getTime() > now.getTime()) {
|
||||
ElMessage.error('该请假类型不允许提前请假,开始时间不能大于今天!');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 校验 maxApplyDuration(最大申请时长,天)
|
||||
if (leaveType.maxApplyDuration && leaveType.maxApplyDuration > 0) {
|
||||
const start = new Date(form.startTime);
|
||||
const end = new Date(form.endTime);
|
||||
const diffDays = (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24);
|
||||
if (diffDays > leaveType.maxApplyDuration) {
|
||||
ElMessage.error(`请假时长不能超过${leaveType.maxApplyDuration}天!`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// ====== end ======
|
||||
|
||||
console.log('status111:', status);
|
||||
studentLeaveFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
@@ -930,20 +976,21 @@ const cancel = () => {
|
||||
};
|
||||
|
||||
// 监听 isLeaveSchool 字段变化,更新销假状态
|
||||
watch(
|
||||
() => form.isLeaveSchool,
|
||||
(newValue) => {
|
||||
if (currentLeaveType.value && currentLeaveType.value.needCancelForNonLeave === '0') {
|
||||
if (newValue === '0') {
|
||||
// 当 isLeaveSchool = 0 时,cancelStatus = 3 (无需销假)
|
||||
form.cancelStatus = '3';
|
||||
} else {
|
||||
// 其他时候,cancelStatus = 0 (未销假)
|
||||
form.cancelStatus = '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
// watch(
|
||||
// () => form.isLeaveSchool,
|
||||
// (newValue) => {
|
||||
// console.log('newValue:', newValue);
|
||||
// // if (currentLeaveType.value && currentLeaveType.value.needCancelForNonLeave === '0') {
|
||||
// // if (newValue === '0') {
|
||||
// // // 当 isLeaveSchool = 0 时,cancelStatus = 3 (无需销假)
|
||||
// // form.cancelStatus = '3';
|
||||
// // } else {
|
||||
// // // 其他时候,cancelStatus = 0 (未销假)
|
||||
// // form.cancelStatus = '0';
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
// );
|
||||
|
||||
// 根据id获取学生请假信息
|
||||
const getStudentLeaveInfo = async (id: string | number) => {
|
||||
|
||||
Reference in new issue
Block a user