班组bug
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: zwq
|
||||
* @Date: 2025-10-13 15:07:24
|
||||
* @LastEditors: zwq
|
||||
* @LastEditTime: 2025-11-11 15:32:04
|
||||
* @LastEditTime: 2025-11-27 14:41:59
|
||||
* @Description:
|
||||
-->
|
||||
<template>
|
||||
@@ -138,7 +138,14 @@
|
||||
<el-tag type="warning" style="color: black" v-if="!isClassTimePass">
|
||||
<i class="el-icon-warning" style="color: #ffbd02"></i>
|
||||
两班倒和三班倒的班次设置时间
|
||||
<span style="color: red">不能重叠,且必须连续覆盖24小时。</span>
|
||||
<span style="color: red">不能重叠</span>
|
||||
,且 在24小时。
|
||||
</el-tag>
|
||||
<el-tag type="warning" style="color: black" v-if="!covers24Hours">
|
||||
<i class="el-icon-warning" style="color: #ffbd02"></i>
|
||||
两班倒和三班倒的班次设置时间,班次时间
|
||||
<span style="color: red">必须连续</span>
|
||||
在24小时。
|
||||
</el-tag>
|
||||
</small-title>
|
||||
<base-table
|
||||
@@ -443,7 +450,7 @@ export default {
|
||||
},
|
||||
],
|
||||
stepNum: 1, // 当前第几步
|
||||
isEdit: false, //是否是编辑状态,编辑的时候,让前端上一步和取消都不用接口
|
||||
isEdit: false, //是否是编辑状态,编辑的时候,让前端上一步和取消都不用接口
|
||||
shiftTypeEdit: undefined, //该值为编辑时获取的shiftType,到第二步,判断dataForm.shiftType是否改变,同时改变班次信息
|
||||
//第一步参数
|
||||
dataForm: {
|
||||
@@ -531,7 +538,8 @@ export default {
|
||||
btnName: '编辑',
|
||||
},
|
||||
].filter((v) => v),
|
||||
isClassTimePass: true, //修改班次时间后,需要判断时间是否有覆盖,且是否覆盖24小时
|
||||
isClassTimePass: true, //修改班次时间后,需要判断时间是否有重叠,且是否在24小时内 true是没问题的
|
||||
covers24Hours: true, //修改班次时间后,需要判断时间是否覆盖24小时连续的时间 true是没问题的
|
||||
tableData1: [],
|
||||
tableProps2,
|
||||
tableBtn2: [
|
||||
@@ -621,9 +629,9 @@ export default {
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
init(id,isEdit) {
|
||||
init(id, isEdit) {
|
||||
this.dataForm.id = id || undefined;
|
||||
this.isEdit = isEdit || false
|
||||
this.isEdit = isEdit || false;
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].resetFields();
|
||||
if (this.dataForm.id) {
|
||||
@@ -638,8 +646,10 @@ export default {
|
||||
if (item.isProduction) {
|
||||
lineName = this.setLineName(item.bindLineTree);
|
||||
}
|
||||
this.$set(this.tableData2[index], 'lineName', lineName);
|
||||
this.$set(this.tableData2[index], 'lineName', lineName.join(';'));
|
||||
});
|
||||
this.stepNum = 3;
|
||||
this.getThreeGroup(7); // 第三步,进来加载预览排班,默认7天预览周期
|
||||
});
|
||||
} else {
|
||||
getCode().then((res) => {
|
||||
@@ -757,7 +767,7 @@ export default {
|
||||
}
|
||||
|
||||
//班次验证
|
||||
if (!this.isClassTimePass) {
|
||||
if (!this.isClassTimePass || !this.covers24Hours) {
|
||||
this.$message('班次内时间有误,请重新填写!');
|
||||
return;
|
||||
}
|
||||
@@ -777,9 +787,10 @@ export default {
|
||||
data.groupPlanClassesBaseVOList.push(obj);
|
||||
});
|
||||
data.groupPlanTeamBaseVOList = []; //排班-班组信息list
|
||||
this.tableData2.forEach((item) => {
|
||||
this.tableData2.forEach((item, index) => {
|
||||
const obj = {
|
||||
teamId: item.id,
|
||||
sort: index + 1,
|
||||
teamId: item.teamId || item.id,
|
||||
name: item.name,
|
||||
leaderName: item.leaderName,
|
||||
leaderPhone: item.leaderPhone,
|
||||
@@ -788,9 +799,13 @@ export default {
|
||||
data.groupPlanTeamBaseVOList.push(obj);
|
||||
});
|
||||
createStepTwo(data).then((res) => {
|
||||
this.stepNum += 1;
|
||||
this.$emit('setSN', this.stepNum);
|
||||
this.getThreeGroup(7); // 第三步,进来加载预览排班,默认7天预览周期
|
||||
if (res.code === 200 || res.code === 0) {
|
||||
this.stepNum += 1;
|
||||
this.$emit('setSN', this.stepNum);
|
||||
this.getThreeGroup(7); // 第三步,进来加载预览排班,默认7天预览周期
|
||||
} else {
|
||||
this.$message(res.msg);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -799,7 +814,7 @@ export default {
|
||||
data.groupPlanTeamBaseVOList = []; //排班-班组信息list
|
||||
this.tableData2.forEach((item) => {
|
||||
const obj = {
|
||||
teamId: item.id,
|
||||
teamId: item.teamId || item.id,
|
||||
name: item.name,
|
||||
bindData: JSON.stringify(item.bindLineTree),
|
||||
};
|
||||
@@ -943,6 +958,57 @@ export default {
|
||||
return start1Min < end2Min && end1Min > start2Min;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 检查多个班次是否连续覆盖24小时
|
||||
* @param {Array} shifts - 班次数组,每个班次包含startTime和endTime
|
||||
* @returns {boolean} 是否连续覆盖24小时
|
||||
*/
|
||||
isCover24Hours(shifts) {
|
||||
if (!shifts || shifts.length === 0) return false;
|
||||
|
||||
const totalMinutes = 24 * 60;
|
||||
|
||||
// 将班次转换为时间段对象
|
||||
const intervals = shifts.map((shift) => ({
|
||||
start: this.timeToMinutes(shift.startTime),
|
||||
end: this.timeToMinutes(shift.endTime),
|
||||
}));
|
||||
|
||||
// 处理跨天情况:如果结束时间小于开始时间,加上24小时
|
||||
const normalizedIntervals = intervals.map((interval) => {
|
||||
let { start, end } = interval;
|
||||
if (end < start) {
|
||||
end += totalMinutes;
|
||||
}
|
||||
return { start, end, originalEnd: interval.end };
|
||||
});
|
||||
|
||||
// 按开始时间排序
|
||||
normalizedIntervals.sort((a, b) => a.start - b.start);
|
||||
|
||||
// 检查是否连续覆盖
|
||||
let coveredUntil = normalizedIntervals[0].end;
|
||||
let hasGap = false;
|
||||
|
||||
for (let i = 1; i < normalizedIntervals.length; i++) {
|
||||
const current = normalizedIntervals[i];
|
||||
|
||||
// 如果当前班次的开始时间大于已覆盖的结束时间,说明有间隔
|
||||
if (current.start > coveredUntil) {
|
||||
hasGap = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// 更新已覆盖的结束时间
|
||||
coveredUntil = Math.max(coveredUntil, current.end);
|
||||
}
|
||||
|
||||
// 检查是否覆盖完整的24小时
|
||||
const firstStart = normalizedIntervals[0].start;
|
||||
|
||||
// 判断条件:没有间隔且覆盖时间达到24小时
|
||||
return !hasGap && coveredUntil - firstStart >= totalMinutes;
|
||||
},
|
||||
//编辑班次
|
||||
handleClick1(val) {
|
||||
this.addOrUpdateVisible1 = true;
|
||||
@@ -1023,7 +1089,7 @@ export default {
|
||||
this.tableData1.forEach((item, index) => {
|
||||
item.sort = index + 1;
|
||||
});
|
||||
//修改班次时间后,需要判断时间是否有覆盖,且是否覆盖24小时,isTimeOverlap方法返回false才是校验通过
|
||||
//修改班次时间后,需要判断时间是否有重叠,且是否在24小时内,isTimeOverlap方法返回false才是校验通过
|
||||
if (this.dataForm.shiftType == 2) {
|
||||
const twoClass = this.tableData1.map(({ startTime, endTime }) => ({
|
||||
startTime,
|
||||
@@ -1061,6 +1127,11 @@ export default {
|
||||
);
|
||||
this.isClassTimePass = !(result1 || result2 || result3);
|
||||
}
|
||||
//修改班次时间后,两班倒和三班倒需要判断时间是否连续覆盖24小时内
|
||||
if (this.dataForm.shiftType > 1) {
|
||||
this.covers24Hours = this.isCover24Hours(this.tableData1);
|
||||
console.log(1111, this.covers24Hours);
|
||||
}
|
||||
this.cancel1();
|
||||
},
|
||||
refreshTableData2(val) {
|
||||
@@ -1069,39 +1140,45 @@ export default {
|
||||
},
|
||||
refreshTableData3(index, val) {
|
||||
this.tableData2[index].bindLineTree = val;
|
||||
let lineName = '';
|
||||
lineName = this.setLineName(val);
|
||||
let lineName = this.setLineName(val);
|
||||
if (lineName) {
|
||||
this.$set(this.tableData2[index], 'lineName', lineName);
|
||||
this.$set(this.tableData2[index], 'lineName', lineName.join(';'));
|
||||
}
|
||||
this.cancel3();
|
||||
},
|
||||
//提取绑定的产线工段名展示出来
|
||||
setLineName(val) {
|
||||
if (!val || val.length === 0) return '';
|
||||
setLineName(data) {
|
||||
const paths = [];
|
||||
|
||||
const currentLevelNames = val.map((item) => item.name);
|
||||
const processNode = (node, currentPath = []) => {
|
||||
const newPath = [...currentPath, node.name];
|
||||
|
||||
// 处理当前层级显示
|
||||
let currentDisplay = '';
|
||||
if (currentLevelNames.length > 1) {
|
||||
currentDisplay = `(${currentLevelNames.join(' 、 ')})`;
|
||||
} else {
|
||||
currentDisplay = currentLevelNames[0];
|
||||
}
|
||||
if (node.children && node.children.length > 0) {
|
||||
// 检查子节点是否都是叶子节点
|
||||
const allChildrenAreLeaves = node.children.every(
|
||||
(child) => !child.children || child.children.length === 0
|
||||
);
|
||||
|
||||
// 查找所有子节点(取第一个有子节点的元素)
|
||||
const childNode = val.find(
|
||||
(item) => item.children && item.children.length > 0
|
||||
);
|
||||
if (childNode) {
|
||||
const childPath = this.setLineName(childNode.children);
|
||||
if (childPath) {
|
||||
return `${currentDisplay} / ${childPath}`;
|
||||
if (allChildrenAreLeaves && node.children.length > 1) {
|
||||
// 如果所有子节点都是叶子节点且多于1个,用括号合并显示
|
||||
const leafNames = node.children
|
||||
.map((child) => child.name)
|
||||
.join(' 、 ');
|
||||
paths.push(`${newPath.join('/')}/(${leafNames})`);
|
||||
} else if (allChildrenAreLeaves && node.children.length === 1) {
|
||||
// 只有一个叶子子节点,用括号显示
|
||||
paths.push(`${newPath.join('/')}/(${node.children[0].name})`);
|
||||
} else {
|
||||
// 继续处理子节点
|
||||
node.children.forEach((child) => processNode(child, newPath));
|
||||
}
|
||||
} else {
|
||||
// 没有子节点的节点(如原片产线1),用括号显示
|
||||
paths.push(`${currentPath.join('/')}/(${node.name})`);
|
||||
}
|
||||
}
|
||||
|
||||
return currentDisplay;
|
||||
};
|
||||
data.forEach((node) => processNode(node));
|
||||
return paths;
|
||||
},
|
||||
//第三步
|
||||
// 进来加载预览排班
|
||||
|
||||
Reference in New Issue
Block a user