Commit 39d3f34f by 无尘

feat: 增加班次计算

parent cabbca7c
......@@ -4,7 +4,7 @@
* @Author: 无尘
* @Date: 2019-10-21 14:27:29
* @LastEditors: 无尘
* @LastEditTime: 2019-12-13 17:08:36
* @LastEditTime: 2019-12-14 17:52:54
-->
<!--
......@@ -59,7 +59,7 @@ import createWorkClass from '@/components/app/dailyAttendance/create-work-class.
<div class="cell m-t-20">
<span class="font-12 color-606266">下班</span>
<el-time-picker :clearable="false" :editable="false" class="w-106" v-model="scope.row.endTime" format="HH:mm" value-format="HH:mm" @change="changeEnd($event, scope.row)"> </el-time-picker>
<el-tag v-if="Number(scope.row.endTime.split(':')[0]) <= Number(scope.row.startTime.split(':')[0]) && Number(scope.row.endTime.split(':')[1]) <= Number(scope.row.startTime.split(':')[1])" class="across-tag" type="danger">次日</el-tag>
<el-tag v-if="checkNextFlag(scope.row.startTime, scope.row.endTime)" class="across-tag" type="danger">次日</el-tag>
</div>
</template>
</el-table-column>
......@@ -81,6 +81,7 @@ import createWorkClass from '@/components/app/dailyAttendance/create-work-class.
>
</el-time-picker>
<span class="font-12 color-606266"></span>
<span class="font-12 color-606266"></span>
<el-time-picker
:clearable="false"
:picker-options="{
......@@ -144,14 +145,14 @@ import createWorkClass from '@/components/app/dailyAttendance/create-work-class.
<span v-if="formData.isAllowLate" class="font-14 color-606266">分钟以内打上班卡不算迟到</span>
</div>
<div class="m-b-10">
<el-checkbox v-model="formData.isMostLate">严重迟到</el-checkbox>
<el-input-number v-if="formData.isMostLate" class="w-90 m-l-20" v-model="formData.mostLateDate" controls-position="right" :min="1" :max="3600"></el-input-number>
<span v-if="formData.isMostLate" class="font-14 color-606266">分钟以上打上班卡算严重迟到</span>
<el-checkbox v-model="formData.isMoreLate">严重迟到</el-checkbox>
<el-input-number v-if="formData.isMoreLate" class="w-90 m-l-20" v-model="formData.moreLateDate" controls-position="right" :min="1" :max="3600"></el-input-number>
<span v-if="formData.isMoreLate" class="font-14 color-606266">分钟以上打上班卡算严重迟到</span>
</div>
<div class="m-b-10">
<el-checkbox v-model="formData.isMoreLate">旷工迟到</el-checkbox>
<el-input-number v-if="formData.isMoreLate" class="w-90 m-l-20" v-model="formData.moreLateDate" controls-position="right" :min="1" :max="3600"></el-input-number>
<span v-if="formData.isMoreLate" class="font-14 color-606266">分钟以上打上班卡算旷工</span>
<el-checkbox v-model="formData.isMostLate">旷工迟到</el-checkbox>
<el-input-number v-if="formData.isMostLate" class="w-90 m-l-20" v-model="formData.mostLateDate" controls-position="right" :min="1" :max="3600"></el-input-number>
<span v-if="formData.isMostLate" class="font-14 color-606266">分钟以上打上班卡算旷工</span>
</div>
<div class="m-b-10">
<el-checkbox :disabled="maxLate < 1.5" v-model="formData.lateRule" @change="handleChangeLate">晚走次日晚到</el-checkbox>
......@@ -250,11 +251,11 @@ export default {
relaxStartDate: '12:00',
relaxEndDate: '13:00',
isAllowLate: false, // 允许迟到
isMostLate: false, // 严重迟到
isMoreLate: false, // 旷工迟到
isMoreLate: false, // 严重迟到
isMostLate: false, // 旷工迟到
allowLateDate: '30', // 允许迟到 分
mostLateDate: '35', // 严重迟到 分
moreLateDate: '60', // 旷工迟到 分
moreLateDate: '35', // 严重迟到 分
mostLateDate: '60', // 旷工迟到 分
lateRule: false, // 晚走次日晚到
lateRuleJson: []
},
......@@ -268,6 +269,14 @@ export default {
},
methods: {
/**
* 判断次日
*/
checkNextFlag(start, end) {
let startTime = String(start).split(':');
let endTime = String(end).split(':');
return parseInt(startTime[0]) > parseInt(endTime[0]) || (parseInt(startTime[0]) >= parseInt(endTime[0]) && parseInt(startTime[1]) >= parseInt(endTime[1]));
},
/**
* 改变次数控制
*/
changeTimes(e) {
......@@ -378,18 +387,124 @@ export default {
*/
compareDate(t1, t2) {
let date = new Date();
let a = t1.split(':');
let b = t2.split(':');
let a = String(t1).split(':');
let b = String(t2).split(':');
return date.setHours(a[0], a[1]) < date.setHours(b[0], b[1]);
},
/**
* 计算禁用区间
* 计算上班开始可打卡禁用区间
*/
async calcForbidTime(item) {
async forbidStartBeginTime(item) {
const that = this;
let arr = [];
let rangeStart = await that.hmMinuxhm(item.startTime, await that.hourTohm(8));
let rangeEnd = await that.hmMinuxhm(item.startTime, '00:01');
console.log(rangeStart);
// 判断是否小于下班时间
console.log('上班时间-8之后和下班时间比较:', await that.compareDate(rangeStart, item.endTime));
const diff = parseInt(item.startTime.split(':')[0]) - 8;
console.log('上班时间-8:', diff);
if (diff < 0 && (await that.compareDate(rangeStart, item.endTime))) {
rangeStart = await that.hmMinuxhm(item.endTime, '00:01'); // 上班时间 - 8 ,如果比下班时间还小,就把下班时间作为可打卡开始的最小时间
}
// 跨天了(次日)
// 上班 < 下班, 上班-8 <0 && 差大于 下班
if (!(await that.compareDate(item.startTime, item.endTime)) && diff < 0 && !(await that.compareDate(rangeStart, item.endTime))) {
rangeStart = await that.hmPlushm(item.endTime, '00:01');
}
// 上班 < 下班, 上班-8 >0 && 差小于 下班
if (!(await that.compareDate(item.startTime, item.endTime)) && diff > 0 && (await that.compareDate(rangeStart, item.endTime))) {
rangeStart = await that.hmPlushm(item.endTime, '00:01');
}
// 比较开始于结束,如果开始大于结束,分段计算
if (!(await that.compareDate(rangeStart, rangeEnd))) {
arr.push([rangeStart + ':00', '23:59:00'].join('-'));
arr.push(['00:00:00', rangeEnd + ':00'].join('-'));
return arr;
}
return [[rangeStart + ':00', rangeEnd + ':00'].join('-')];
},
/**
* 计算上班最后可打卡禁用区间
*/
async forbidStartEndTime(item) {
const that = this;
let arr = [];
let rangeStart = await that.hmPlushm(item.startTime, '00:01');
let rangeEnd = await that.hmPlushm(item.startTime, '12:00');
// 判断是否大于上班时间
console.log('下班时间+12 之后和上班时间比较:', await that.compareDate(rangeEnd, item.endTime));
const diff = parseInt(item.startTime.split(':')[0]) + 12;
console.log('下班时间+12:', diff, rangeEnd, await that.compareDate(item.endTime, rangeEnd));
if ((await that.compareDate(item.startTime, item.endTime)) && diff < 24 && (await that.compareDate(item.endTime, rangeEnd))) {
// 如: 07:00-17:00 17 < 7+12 可是 06:00-02:00,符合,但是不能走这个,所以加 是否跨日
rangeEnd = await that.hmMinuxhm(item.endTime, '00:01');
}
if ((await that.compareDate(item.startTime, item.endTime)) && diff > 24 && !(await that.compareDate(item.endTime, rangeEnd))) {
// 如 20:00- 23:00 23 > 20+12 = 8:00
rangeEnd = await that.hmMinuxhm(item.endTime, '00:01'); // 上班时间 - 8 ,如果比下班时间还小,就把下班时间作为可打卡开始的最小时间
}
// 跨天了(次日)
if (!(await that.compareDate(item.startTime, item.endTime)) && diff > 24 && (await that.compareDate(item.endTime, rangeEnd))) {
// 18:00-02:00 2 < 18+12 = 6:00
rangeEnd = await that.hmMinuxhm(item.endTime, '00:01');
}
// 比较开始于结束,如果开始大于结束,分段计算
if (!(await that.compareDate(rangeStart, rangeEnd))) {
arr.push([rangeStart + ':00', '23:59:00'].join('-'));
arr.push(['00:00:00', rangeEnd + ':00'].join('-'));
return arr;
}
return [[rangeStart + ':00', rangeEnd + ':00'].join('-')];
},
/**
* 计算下班开始可打卡禁用区间
*/
async forbidEndStartTime(item) {
const that = this;
let arr = [];
let rangeStart = await that.hmMinuxhm(item.endTime, '08:00');
let rangeEnd = await that.hmMinuxhm(item.endTime, '00:01');
// 判断是否大于上班时间
console.log('下班时间-8 之后和上班时间比较:', await that.compareDate(item.startTime, rangeStart));
const diff = parseInt(item.endTime.split(':')[0]) - 8;
console.log('下班时间-8:', diff, rangeStart, await that.compareDate(item.startTime, rangeStart));
if (((await that.compareDate(item.startTime, item.endTime)) && diff < 0 && (await that.compareDate(item.startTime, rangeStart))) || (diff > 0 && !(await that.compareDate(item.startTime, rangeStart)))) {
// 如 00:00-07:00 12:00-18:00
rangeStart = await that.hmPlushm(item.startTime, '00:01'); // 下班时间 - 8 ,如果比上班时间还小,就把上班时间之前作为可打卡开始的最小时间
}
// 跨天了(次日)
if (!(await that.compareDate(item.startTime, item.endTime)) && diff < 0 && !(await that.compareDate(item.startTime, rangeStart))) {
rangeStart = await that.hmPlushm(item.startTime, '00:01'); // 下班时间 - 8 ,如果比上班时间还小,就把上班时间之前作为可打卡开始的最小时间
}
/* if (!(await that.compareDate(item.startTime, item.endTime)) && diff > 0 && !(await that.compareDate(item.startTime, rangeStart))) {
// 09:07-09:05
rangeStart = await that.hmPlushm(item.startTime, '00:01'); // 下班时间 - 8 ,如果比上班时间还小,就把上班时间之前作为可打卡开始的最小时间
} */
console.log('下班可以开始时间:', rangeStart, rangeEnd);
// 比较开始于结束,如果开始大于结束,分段计算
if (!(await that.compareDate(rangeStart, rangeEnd))) {
arr.push([rangeStart + ':00', '23:59:00'].join('-'));
arr.push(['00:00:00', rangeEnd + ':00'].join('-'));
return arr;
}
return [[rangeStart + ':00', rangeEnd + ':00'].join('-')];
},
/**
* 计算下班最后可打卡禁用区间
*/
async forbidEndEndTime(item) {
const that = this;
let arr = [];
let rangeStart = await that.hmPlushm(item.endTime, '00:01');
let rangeEnd = await that.hmPlushm(item.endTime, '12:00');
// 判断是否大于上班时间
console.log('下班时间+12 之后和上班时间比较:', await that.compareDate(rangeEnd, item.startTime));
const diff = parseInt(item.endTime.split(':')[0]) + 12;
console.log('下班时间+12:', diff, rangeEnd, await that.compareDate(item.startTime, rangeEnd));
if (diff > 24 && (await that.compareDate(item.startTime, rangeEnd))) {
rangeEnd = await that.hmMinuxhm(item.startTime, '00:01'); // 上班时间 - 8 ,如果比下班时间还小,就把下班时间作为可打卡开始的最小时间
}
// 比较开始于结束,如果开始大于结束,分段计算
if (!(await that.compareDate(rangeStart, rangeEnd))) {
arr.push([rangeStart + ':00', '23:59:00'].join('-'));
......@@ -403,12 +518,15 @@ export default {
*/
async changeStart(e, item) {
const that = this;
let hours = 10;
let hours = 10.5;
console.log(e);
const startTime = e;
const endTime = that.formData.classessTimesJson[0].endTime;
if (await that.compareDate(startTime, endTime)) {
hours = await that.timeDifference(startTime, endTime);
} else {
// 跨天了(次日)如 21:00-04:00
hours = Number(await that.timeDifference(startTime, '24:00')) + Number(await that.timeDifference('00:00', endTime));
}
// 计算时间间隔
that.maxLate = hours - 0.5; // 可设置的时间数必须小于最大的限制数 0.5
......@@ -417,12 +535,14 @@ export default {
that.formData.lateRule = false; // 最大时间间隔小于 2小时,不能设置晚到规则
that.formData.lateRuleJson = [];
}
if (that.maxLate >= 10.5) {
that.maxLate = 10; // 最大只能填写是 10
}
// 计算当前禁用时间段
console.log(await that.calcForbidTime(item));
item.forbidStartBeginTime = await that.calcForbidTime(item); //await that.calcForbidTime(item);
item.forbidStartEndTime = ['18:30:00 - 20:30:00'];
item.forbidEndStartTime = ['18:30:00 - 20:30:00'];
item.forbidEndEndTime = ['18:30:00 - 20:30:00'];
item.forbidStartBeginTime = await that.forbidStartBeginTime(item);
item.forbidStartEndTime = await that.forbidStartEndTime(item);
item.forbidEndStartTime = await that.forbidEndStartTime(item);
item.forbidEndEndTime = await that.forbidEndEndTime(item);
console.log(item);
that.$forceUpdate();
},
......@@ -431,12 +551,15 @@ export default {
*/
async changeEnd(e, item) {
const that = this;
let hours = 10;
let hours = 10.5;
console.log(e);
const startTime = that.formData.classessTimesJson[0].startTime;
const endTime = e;
if (await that.compareDate(startTime, endTime)) {
hours = await that.timeDifference(startTime, endTime);
} else {
// 跨天了(次日)
hours = Number(await that.timeDifference(startTime, '24:00')) + Number(await that.timeDifference('00:00', endTime));
}
// 计算时间间隔
that.maxLate = hours - 0.5; // 可设置的时间数必须小于最大的限制数 0.5
......@@ -445,6 +568,14 @@ export default {
that.formData.lateRule = false; // 最大时间间隔小于 2小时,不能设置晚到规则
that.formData.lateRuleJson = [];
}
if (that.maxLate >= 10.5) {
that.maxLate = 10;
}
// 计算当前禁用时间段
item.forbidStartBeginTime = await that.forbidStartBeginTime(item);
item.forbidStartEndTime = await that.forbidStartEndTime(item);
item.forbidEndStartTime = await that.forbidEndStartTime(item);
item.forbidEndEndTime = await that.forbidEndEndTime(item);
},
/**
* 开启晚走规则
......@@ -545,19 +676,19 @@ export default {
showMsg.showmsg('请填写允许迟到时间', 'warning');
return false;
}
if (that.formData.isMostLate && !that.formData.mostLateDate) {
if (that.formData.isMoreLate && !that.formData.moreLateDate) {
showMsg.showmsg('请填写严重迟到时间', 'warning');
return false;
}
if (that.formData.isAllowLate && that.formData.isMostLate && that.formData.allowLateDate >= that.formData.mostLateDate) {
if (that.formData.isAllowLate && that.formData.isMoreLate && that.formData.allowLateDate >= that.formData.moreLateDate) {
showMsg.showmsg('严重迟到时间必须大于迟到允许时间', 'warning');
return false;
}
if (that.formData.isMoreLate && !that.formData.moreLateDate) {
if (that.formData.isMostLate && !that.formData.mostLateDate) {
showMsg.showmsg('请填写旷工迟到时间', 'warning');
return false;
}
if (that.formData.isMoreLate && that.formData.isMostLate && that.formData.mostLateDate >= that.formData.moreLateDate) {
if (that.formData.isMoreLate && that.formData.isMostLate && that.formData.moreLateDate >= that.formData.mostLateDate) {
showMsg.showmsg('旷工迟到时间必须大于严重迟到时间', 'warning');
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment