整天请假按当天实际考勤时段提交(修复常规周五生成3条的问题)
1. 新增后端接口 /api/admin/attendance/full-day-leave:按作息判断当天实际时段后再提交请假 2. 时段规则:正常上课日3段、放假前一天1段(仅上午)、节前上课2段(早+中)、返校晚修1段 3. 每时段按"请假"配置扣分;已有对应时段记录会更新为请假 4. 前端整天请假改为调用新接口;文档同步
This commit is contained in:
1 parent
ad50f82c7b
commit
97f2de5d83
5 files changed
+165
-69
No files matched your search
@@ -389,45 +389,24 @@ async function submitFullDayLeave() {
|
||||
showToast('请选择日期', 'warning');
|
||||
return;
|
||||
}
|
||||
if (!confirm('确定为选中的学生提交整天请假吗?(按当天实际考勤时段生成:正常上课日3条、假前半天1条、节前上课2条、返校晚修1条;每时段按请假扣分)')) return;
|
||||
|
||||
// 整天请假 = 早/中/晚 三个时段,各按"请假"扣分
|
||||
const perDeduction = attendanceDeductionMap.leave || 0;
|
||||
const totalPerStudent = perDeduction * 3;
|
||||
const confirmText = perDeduction > 0
|
||||
? '确定为选中的学生提交整天请假吗?(早/中/晚各扣' + perDeduction + '分,共' + totalPerStudent + '分/人)'
|
||||
: '确定为选中的学生提交整天请假吗?(早/中/晚三个时段)';
|
||||
if (!confirm(confirmText)) return;
|
||||
|
||||
const studentIds = Array.from(selectedCells).map(cell => parseInt(cell.dataset.id));
|
||||
const reason = document.getElementById('attendanceReason').value;
|
||||
const slots = ['morning', 'afternoon', 'evening'];
|
||||
const promises = [];
|
||||
|
||||
selectedCells.forEach(cell => {
|
||||
const studentId = parseInt(cell.dataset.id);
|
||||
slots.forEach(slot => {
|
||||
const payload = {
|
||||
student_id: studentId,
|
||||
date: date,
|
||||
slot: slot,
|
||||
status: 'leave',
|
||||
reason: reason,
|
||||
apply_deduction: true
|
||||
};
|
||||
if (perDeduction > 0) {
|
||||
payload.custom_deduction = perDeduction;
|
||||
}
|
||||
promises.push(apiPost('/api/admin/attendance', payload));
|
||||
try {
|
||||
const res = await apiPost('/api/admin/attendance/full-day-leave', {
|
||||
date: date,
|
||||
student_ids: studentIds,
|
||||
reason: reason
|
||||
});
|
||||
});
|
||||
|
||||
const results = await Promise.allSettled(promises);
|
||||
const succeeded = results.filter(r => r.status === 'fulfilled' && r.value?.success).length;
|
||||
const failed = results.length - succeeded;
|
||||
|
||||
if (failed === 0) {
|
||||
showToast(`整天请假提交成功(${succeeded}条` + (perDeduction > 0 ? `,${totalPerStudent}分/人` : '') + ')');
|
||||
} else {
|
||||
showToast(`提交完成:成功${succeeded}条,失败${failed}条`, 'error');
|
||||
if (res && res.success) {
|
||||
showToast(res.message || '整天请假提交成功');
|
||||
} else {
|
||||
showToast((res && (res.message || res.detail)) || '提交失败', 'error');
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('提交失败:' + (err && err.message ? err.message : '未知错误'), 'error');
|
||||
}
|
||||
|
||||
deselectAllStudents();
|
||||
|
||||
Reference in new issue
Block a user