diff --git a/src/pages/temporary-outing/details.vue b/src/pages/temporary-outing/details.vue
index 15e7188..388ddb1 100644
--- a/src/pages/temporary-outing/details.vue
+++ b/src/pages/temporary-outing/details.vue
@@ -16,11 +16,21 @@
+
+ 外出结束时间上下午
+
+
+
外出结束时间
+
+ 外出结束时间上下午
+
+
+
外出时长(天)
diff --git a/src/pages/temporary-outing/index.vue b/src/pages/temporary-outing/index.vue
index 0676b99..af81ba1 100644
--- a/src/pages/temporary-outing/index.vue
+++ b/src/pages/temporary-outing/index.vue
@@ -70,6 +70,21 @@
+
+ 外出开始时间上下午
+
+
+ {{ ['请选择','上午', '下午'][formData.leaveStartInterval ] }}
+
+
+
+
外出结束时间
+
+ 外出结束时间上下午
+
+
+ {{ ['请选择','上午', '下午'][formData.leaveEndInterval] }}
+
+
+
外出时长(天)
@@ -265,7 +294,9 @@
userName: '',
leaveType: null,
leaveStartDate: '',
+ leaveStartInterval:'',
leaveEndDate: '',
+ leaveEndInterval:'',
leaveDuration: '',
location: '',
isAgree: '1',
@@ -292,6 +323,7 @@
hostUserNames: '', // 显示的选中名字
isCheckboxGroupVisibles: false,
isEdit: false, // 判断是否为编辑状态
+ daysNumber: "", //时间之间的差
}
},
mounted() {
@@ -353,11 +385,29 @@
this.formData.leaveStartDate = startDate
this.validateAndCalculateDuration(startDate, this.formData.leaveEndDate)
},
+ onStartAmPmChange(e) {
+ if(e.detail.value ==0){
+ return;
+ }
+ console.log("开始",e.detail.value)
+ this.formData.leaveStartInterval = e.detail.value;
+ this.handleDateChanges()
+ },
+
onEndDateChange(e) {
const endDate = e.detail.value
this.formData.leaveEndDate = endDate
this.validateAndCalculateDuration(this.formData.leaveStartDate, endDate)
},
+ onEndAmPmChange(e) {
+ if(e.detail.value ==0){
+ return;
+ }
+ console.log("结束",e.detail.value)
+ this.formData.leaveEndInterval = e.detail.value;
+ this.handleDateChanges()
+ },
+
validateAndCalculateDuration(startDate, endDate) {
// 清除之前的错误信息
this.errors.leaveStartDate = ''
@@ -390,13 +440,48 @@
getDays(dateData).then((response) => {
if (response.status === 200) {
console.log(response)
- this.formData.leaveDuration = response.data
+ // this.formData.leaveDuration = response.data
+ this.daysNumber = response.data
+ this.handleDateChanges()
} else {
this.formData.leaveDuration = ''
}
})
}
},
+ handleDateChanges() {
+ if (this.formData.leaveStartDate && this.formData.leaveEndDate && this.formData.leaveStartInterval && this.formData.leaveEndInterval ) {
+ // 比较开始日期和结束日期
+ const startDate = new Date(this.formData.leaveStartDate);
+ const endDate = new Date(this.formData.leaveEndDate);
+
+ if (startDate > endDate ||
+ (startDate.getTime() === endDate.getTime() &&
+ this.formData.leaveStartInterval > this.formData.leaveEndInterval)) {
+ this.errors.leaveStartDate = '开始时间应该早于结束时间'
+ this.formData.leaveStartDate = ''
+ this.formData.leaveEndDate = ''
+ this.formData.leaveStartInterval = ''
+ this.formData.leaveEndInterval = ''
+ return
+ // 这里可以添加更多的用户提示或者处理逻辑
+ return;
+ }
+
+ if (startDate.getTime() === endDate.getTime()) { // 同一天
+ if (this.formData.leaveStartInterval == 1 && this.formData.leaveEndInterval == 2) {
+ this.formData.leaveDuration = 1; // 上午到下午,算作1天
+ } else {
+ this.formData.leaveDuration = 0.5; // 其他情况,上/下午到同一天的上/下午,算作半天
+ }
+ } else { // 不同天
+ let totalDays = this.daysNumber;
+ if (this.formData.leaveStartInterval == 1) totalDays -= 0.5; // 开始当天只算半天
+ if (this.formData.leaveEndInterval == 1) totalDays -= 0.5; // 结束当天只算半天
+ this.formData.leaveDuration = totalDays;
+ }
+ }
+ },
onApprovalChange(e) {
this.formData.isApproved = e.detail.value
},
@@ -541,6 +626,8 @@
leaveDuration,
leaveEndDate,
leaveStartDate,
+ leaveStartInterval,
+ leaveEndInterval,
leaveType,
location,
remark,
@@ -560,6 +647,8 @@
leaveDuration,
leaveEndDate,
leaveStartDate,
+ leaveStartInterval,
+ leaveEndInterval,
leaveType,
location,
remark,