临时外出申请 外出时长(天) 计算规则变更

This commit is contained in:
lSun 2025-08-05 10:58:26 +08:00
parent 47d305a63b
commit 622df8e79f
1 changed files with 36 additions and 2 deletions

View File

@ -503,15 +503,19 @@ export default {
},
async handleDateChange() {
if (this.form.leaveStartDate && this.form.leaveEndDate) {
// API
this.handleDateChanges();
}
/* if (this.form.leaveStartDate && this.form.leaveEndDate) {
await this.daysBetween(this.form.leaveStartDate, this.form.leaveEndDate)
if(this.form.leaveStartDate && this.form.leaveEndDate){
this.handleDateChanges()
}
}
} */
},
handleDateChanges() {
if (this.form.leaveStartDate && this.form.leaveEndDate) {
/* if (this.form.leaveStartDate && this.form.leaveEndDate) {
if (this.form.leaveStartInterval == 1 && this.form.leaveEndInterval == 1) {
this.form.leaveDuration = Number(this.daysNumber) - 0.5
} else if (this.form.leaveStartInterval == 1 && this.form.leaveEndInterval == 2) {
@ -521,6 +525,36 @@ export default {
} else if (this.form.leaveStartInterval == 2 && this.form.leaveEndInterval == 1) {
this.form.leaveDuration = this.daysNumber
}
} */
if (this.form.leaveStartDate && this.form.leaveEndDate) {
const startDate = new Date(this.form.leaveStartDate);
const endDate = new Date(this.form.leaveEndDate);
//
if (endDate < startDate) {
this.form.leaveDuration = 0;
return;
}
//
const timeDiff = endDate.getTime() - startDate.getTime();
const daysDiff = timeDiff / (1000 * 3600 * 24);
const fullDays = Math.round(daysDiff) + 1; // 1
// /
if (this.form.leaveStartInterval == 1 && this.form.leaveEndInterval == 1) {
// - 1 + 0.5 = - 0.5
this.form.leaveDuration = Math.max(0, fullDays - 0.5);
} else if (this.form.leaveStartInterval == 1 && this.form.leaveEndInterval == 2) {
//
this.form.leaveDuration = fullDays;
} else if (this.form.leaveStartInterval == 2 && this.form.leaveEndInterval == 2) {
// - 1 + 0.5 = - 0.5
this.form.leaveDuration = Math.max(0, fullDays - 0.5);
} else if (this.form.leaveStartInterval == 2 && this.form.leaveEndInterval == 1) {
// - 1 = - 1
this.form.leaveDuration = Math.max(0, fullDays - 1);
}
}
},