diff --git a/src/views/process/outApply/index.vue b/src/views/process/outApply/index.vue index 83b76c8..5017bbc 100644 --- a/src/views/process/outApply/index.vue +++ b/src/views/process/outApply/index.vue @@ -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); + } } },