Browse Source

1.午休时间字段名修改

master
wangqiang 2 days ago
parent
commit
1726992c5f
1 changed files with 21 additions and 21 deletions
  1. 21
    21
      src/views/oa/attendance/groups/index.vue

+ 21
- 21
src/views/oa/attendance/groups/index.vue View File

format="HH:mm" format="HH:mm"
value-format="HH:mm" value-format="HH:mm"
placeholder="选择午休开始时间" placeholder="选择午休开始时间"
@change="calculateLunchHours"
@change="calculatelunchTime"
></el-time-picker> ></el-time-picker>
</el-form-item> </el-form-item>


format="HH:mm" format="HH:mm"
value-format="HH:mm" value-format="HH:mm"
placeholder="选择午休结束时间" placeholder="选择午休结束时间"
@change="calculateLunchHours"
@change="calculatelunchTime"
></el-time-picker> ></el-time-picker>
</el-form-item> </el-form-item>


<el-form-item label="午休时间" prop="lunchHours">
<el-form-item label="午休时间" prop="lunchTime">
<el-input <el-input
v-model="lunchHoursDisplay"
v-model="lunchTimeDisplay"
placeholder="午休时间(小时)" placeholder="午休时间(小时)"
readonly readonly
style="width: 200px" style="width: 200px"
workEndTime: '18:00', workEndTime: '18:00',
lunchStartTime: '12:00', lunchStartTime: '12:00',
lunchEndTime: '13:00', lunchEndTime: '13:00',
lunchHours: 1,
lunchTime: 1,
allowLate: false, allowLate: false,
lateRange: 15, lateRange: 15,
allowEarly: false, allowEarly: false,
workEndTime: '18:00', workEndTime: '18:00',
lunchStartTime: '12:00', lunchStartTime: '12:00',
lunchEndTime: '13:00', lunchEndTime: '13:00',
lunchHours: 1,
lunchTime: 1,
allowLate: false, allowLate: false,
lateRange: 15, lateRange: 15,
allowEarly: false, allowEarly: false,
); );
}, },
// 午休时间显示 // 午休时间显示
lunchHoursDisplay() {
lunchTimeDisplay() {
// 实时计算午休时间 // 实时计算午休时间
if (!this.attendanceGroup.lunchStartTime || !this.attendanceGroup.lunchEndTime) { if (!this.attendanceGroup.lunchStartTime || !this.attendanceGroup.lunchEndTime) {
return '0'; return '0';
console.log('午休开始时间变化:', newVal); console.log('午休开始时间变化:', newVal);
if (newVal && this.attendanceGroup.lunchEndTime) { if (newVal && this.attendanceGroup.lunchEndTime) {
this.$nextTick(() => { this.$nextTick(() => {
this.calculateLunchHours();
this.calculatelunchTime();
}); });
} }
}, },
console.log('午休结束时间变化:', newVal); console.log('午休结束时间变化:', newVal);
if (newVal && this.attendanceGroup.lunchStartTime) { if (newVal && this.attendanceGroup.lunchStartTime) {
this.$nextTick(() => { this.$nextTick(() => {
this.calculateLunchHours();
this.calculatelunchTime();
}); });
} }
}, },
}, },


// 计算午休时间 // 计算午休时间
calculateLunchHours() {
calculatelunchTime() {
if (!this.attendanceGroup.lunchStartTime || !this.attendanceGroup.lunchEndTime) { if (!this.attendanceGroup.lunchStartTime || !this.attendanceGroup.lunchEndTime) {
this.attendanceGroup.lunchHours = 0;
this.attendanceGroup.lunchTime = 0;
return; return;
} }


const endTime = this.parseTimeToMinutes(this.attendanceGroup.lunchEndTime); const endTime = this.parseTimeToMinutes(this.attendanceGroup.lunchEndTime);


if (endTime <= startTime) { if (endTime <= startTime) {
this.attendanceGroup.lunchHours = 0;
this.attendanceGroup.lunchTime = 0;
return; return;
} }




// 以0.5为基准进行向下取整计算 // 以0.5为基准进行向下取整计算
// 例如:0.7按0.5算,1.7按1.5算 // 例如:0.7按0.5算,1.7按1.5算
this.attendanceGroup.lunchHours = Math.floor(hours * 2) / 2;
this.attendanceGroup.lunchTime = Math.floor(hours * 2) / 2;


// 调试输出 // 调试输出
console.log(`午休时间计算: ${this.attendanceGroup.lunchStartTime} - ${this.attendanceGroup.lunchEndTime} = ${hours}小时,计算结果: ${this.attendanceGroup.lunchHours}小时`);
console.log(`午休时间计算: ${this.attendanceGroup.lunchStartTime} - ${this.attendanceGroup.lunchEndTime} = ${hours}小时,计算结果: ${this.attendanceGroup.lunchTime}小时`);
}, },


test(){ test(){
// this.reset() // this.reset()
this.attendanceGroup = { ...this.attendanceGroupModel } this.attendanceGroup = { ...this.attendanceGroupModel }
// 确保午休时间正确初始化 // 确保午休时间正确初始化
this.calculateLunchHours();
this.calculatelunchTime();
this.open = true this.open = true
}, },


if (!this.attendanceGroup.lunchEndTime) { if (!this.attendanceGroup.lunchEndTime) {
this.attendanceGroup.lunchEndTime = '13:00'; this.attendanceGroup.lunchEndTime = '13:00';
} }
if (this.attendanceGroup.lunchHours === undefined) {
this.attendanceGroup.lunchHours = 1;
if (this.attendanceGroup.lunchTime === undefined) {
this.attendanceGroup.lunchTime = 1;
} }


// 重新计算午休时间 // 重新计算午休时间
this.calculateLunchHours();
this.calculatelunchTime();


this.selectGroup(area.id) this.selectGroup(area.id)


this.$refs.groupForm.validate(valid => { this.$refs.groupForm.validate(valid => {
if (valid) { if (valid) {
// 计算午休时间 // 计算午休时间
this.calculateLunchHours();
this.calculatelunchTime();


// 实际项目中调用API创建 // 实际项目中调用API创建
const newGroup = { const newGroup = {
workEndTime: this.attendanceGroup.workEndTime, workEndTime: this.attendanceGroup.workEndTime,
lunchStartTime: this.attendanceGroup.lunchStartTime, lunchStartTime: this.attendanceGroup.lunchStartTime,
lunchEndTime: this.attendanceGroup.lunchEndTime, lunchEndTime: this.attendanceGroup.lunchEndTime,
lunchHours: this.attendanceGroup.lunchHours,
lunchTime: this.attendanceGroup.lunchTime,
allowLate: this.attendanceGroup.allowLate, allowLate: this.attendanceGroup.allowLate,
lateRange: this.attendanceGroup.lateRange, lateRange: this.attendanceGroup.lateRange,
allowEarly: this.attendanceGroup.allowEarly, allowEarly: this.attendanceGroup.allowEarly,
workEndTime: '18:00', workEndTime: '18:00',
lunchStartTime: '12:00', lunchStartTime: '12:00',
lunchEndTime: '13:00', lunchEndTime: '13:00',
lunchHours: 1,
lunchTime: 1,
allowLate: true, allowLate: true,
lateRange: 15, lateRange: 15,
allowEarly: true, allowEarly: true,

Loading…
Cancel
Save