|
|
@@ -383,6 +383,57 @@ export default {
|
|
|
this.$message.error(err.message);
|
|
|
});
|
|
|
},
|
|
|
+ canDeleteAddedStation(row) {
|
|
|
+ const statusCode = Number(row?.status?.code);
|
|
|
+ return row?.isNew === 1 && statusCode !== 0 && statusCode !== 1;
|
|
|
+ },
|
|
|
+ refreshProcessDateRange(item) {
|
|
|
+ this.$set(item, 'startDate', '');
|
|
|
+ this.$set(item, 'endDate', '');
|
|
|
+ const list = Array.isArray(item?.list) ? item.list : [];
|
|
|
+ list.forEach((row) => {
|
|
|
+ if (row.startTime) {
|
|
|
+ this.compareAndSetTime(row, item);
|
|
|
+ }
|
|
|
+ if (row.endTime) {
|
|
|
+ this.compareEndSetTime(row, item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ deleteRow(row, item) {
|
|
|
+ if (!this.canDeleteAddedStation(row)) {
|
|
|
+ return this.$message.warning(
|
|
|
+ '只有通过添加工位新增且状态不是保存或派单的数据才能删除'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ const list = Array.isArray(item?.list) ? item.list : [];
|
|
|
+ const nextList = list.filter((it) => it.id !== row.id);
|
|
|
+ const nextSelection = Array.isArray(item?.selection)
|
|
|
+ ? item.selection.filter((it) => it.id !== row.id)
|
|
|
+ : [];
|
|
|
+ this.$set(item, 'list', nextList);
|
|
|
+ this.$set(item, 'selection', nextSelection);
|
|
|
+ this.refreshProcessDateRange(item);
|
|
|
+ this.$nextTick(() => {
|
|
|
+ const tab = `tableRef${item.index}`;
|
|
|
+ const tableRefs = this.$refs[tab];
|
|
|
+ if (!tableRefs || !tableRefs[0]) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ tableRefs[0].setSelectedRowKeys(nextSelection.map((it) => it.id));
|
|
|
+ });
|
|
|
+ this.$message.success('删除成功');
|
|
|
+ },
|
|
|
+ applyResetViewState(row, item) {
|
|
|
+ const list = Array.isArray(item?.list) ? item.list : [];
|
|
|
+ const target = list.find((it) => it.id === row.id);
|
|
|
+ if (!target) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ this.$set(target, 'status', null);
|
|
|
+ this.$set(target, 'changeId', '');
|
|
|
+ return true;
|
|
|
+ },
|
|
|
// 重置(单个)
|
|
|
resetData(row, item) {
|
|
|
if (!row.changeId) {
|
|
|
@@ -394,6 +445,9 @@ export default {
|
|
|
this.toolbarLoading = false;
|
|
|
if (res) {
|
|
|
this.$message.success('操作成功');
|
|
|
+ if (row.isNew === 1 && this.applyResetViewState(row, item)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 更改当前表格数据
|
|
|
this.setCurrentTab(item);
|
|
|
}
|
|
|
@@ -564,8 +618,40 @@ export default {
|
|
|
this.$set(this.processList[index], 'list', [...oldList, ...newList]);
|
|
|
},
|
|
|
|
|
|
- cancel() {
|
|
|
+ hasUndeliveredDispatchTask() {
|
|
|
+ if (!Array.isArray(this.processList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return this.processList.some((process) =>
|
|
|
+ (process.list || []).some(
|
|
|
+ (row) => row?.status && Number(row.status.code) === 1
|
|
|
+ )
|
|
|
+ );
|
|
|
+ },
|
|
|
+ closeDispatchDialog(done) {
|
|
|
this.$emit('update:dispatchVisible', false);
|
|
|
+ if (typeof done === 'function') {
|
|
|
+ done();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cancel(done) {
|
|
|
+ if (!this.hasUndeliveredDispatchTask()) {
|
|
|
+ this.closeDispatchDialog(done);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$confirm(
|
|
|
+ '当前存在已派单但未下发的任务,是否仍要退出?',
|
|
|
+ '提示',
|
|
|
+ {
|
|
|
+ type: 'warning',
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消'
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ this.closeDispatchDialog(done);
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
},
|
|
|
// 按钮操作成功后 更改当前的表格数据
|
|
|
setCurrentTab(row) {
|
|
|
@@ -692,7 +778,7 @@ export default {
|
|
|
this.toolbarLoading = false;
|
|
|
if (response) {
|
|
|
this.$message.success('操作成功');
|
|
|
- this.cancel();
|
|
|
+ this.closeDispatchDialog();
|
|
|
this.$emit('createSuccess');
|
|
|
}
|
|
|
} catch (err) {
|
|
|
@@ -739,7 +825,7 @@ export default {
|
|
|
this.toolbarLoading = false;
|
|
|
if (res) {
|
|
|
this.$message.success('操作成功');
|
|
|
- this.cancel();
|
|
|
+ this.closeDispatchDialog();
|
|
|
this.$emit('createSuccess');
|
|
|
}
|
|
|
})
|
|
|
@@ -912,6 +998,7 @@ export default {
|
|
|
// },
|
|
|
operationalData(index, res, list) {
|
|
|
const dataRow = this.processList[index];
|
|
|
+ const oldList = structuredClone(Array.isArray(dataRow.list) ? dataRow.list : []);
|
|
|
if (!dataRow) {
|
|
|
console.warn('operationalData skip invalid process index:', index);
|
|
|
return;
|
|
|
@@ -967,6 +1054,10 @@ export default {
|
|
|
}
|
|
|
listArr = this.applyExecutionTimeToList(listArr, dataRow);
|
|
|
|
|
|
+ if (Number(dataRow.assignType) === 1) {
|
|
|
+ listArr = this.mergeAddedStationRows(oldList, listArr);
|
|
|
+ }
|
|
|
+
|
|
|
let listMap = {};
|
|
|
listArr.map((el, idx) => (listMap[el.id] = idx));
|
|
|
let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
|
|
|
@@ -990,7 +1081,6 @@ export default {
|
|
|
});
|
|
|
|
|
|
// ====== 修复:合并新增工位 ======
|
|
|
- const oldList = Array.isArray(dataRow.list) ? dataRow.list : [];
|
|
|
const finalList = this.mergeNewRows(oldList, listArr);
|
|
|
|
|
|
this.$set(dataRow, 'list', finalList);
|
|
|
@@ -1011,6 +1101,14 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ mergeAddedStationRows(oldList, newList) {
|
|
|
+ const existIds = new Set((newList || []).map((i) => i.id));
|
|
|
+ const addedRows = (oldList || []).filter(
|
|
|
+ (i) => i.isNew === 1 && !existIds.has(i.id)
|
|
|
+ );
|
|
|
+ return [...newList, ...addedRows];
|
|
|
+ },
|
|
|
+
|
|
|
mergeNewRows(oldList, newList) {
|
|
|
const existIds = new Set(newList.map((i) => i.id));
|
|
|
const tempRows = oldList.filter(
|
|
|
@@ -1224,6 +1322,9 @@ export default {
|
|
|
if (!row.startTime) {
|
|
|
return;
|
|
|
}
|
|
|
+ if (!this.checkPlanTimeRange(row, 'startTime', '计划开始时间')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.selectedListData(row, item);
|
|
|
// 这一道工序的开始时间 不能小于前一道工序的结束时间
|
|
|
const startTime = new Date(row.startTime); // 开始时间
|
|
|
@@ -1304,6 +1405,9 @@ export default {
|
|
|
if (!row.endTime) {
|
|
|
return;
|
|
|
}
|
|
|
+ if (!this.checkPlanTimeRange(row, 'endTime', '计划完成时间')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.selectedListData(row, item);
|
|
|
const endTime = new Date(row.endTime); // 结束时间
|
|
|
// 当前工序的结束时间 不能大于后一道工序的开始时间
|
|
|
@@ -1348,15 +1452,36 @@ export default {
|
|
|
}
|
|
|
this.checkEndTimeValid(row, item);
|
|
|
},
|
|
|
+ // 校验时间是否在生产计划范围内,不符合则提示并清空当前字段
|
|
|
+ checkPlanTimeRange(row, field, label) {
|
|
|
+ const currentTime = row[field];
|
|
|
+ if (!currentTime) return true;
|
|
|
+ const { planStartTime, planCompleteTime } = this.current || {};
|
|
|
+ const chooseTime = new Date(currentTime);
|
|
|
+ if (planStartTime && chooseTime < new Date(planStartTime)) {
|
|
|
+ this.$message.closeAll();
|
|
|
+ this.$message.info(`${label}不能小于计划开始时间${planStartTime}`);
|
|
|
+ row[field] = '';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (planCompleteTime && chooseTime > new Date(planCompleteTime)) {
|
|
|
+ this.$message.closeAll();
|
|
|
+ this.$message.info(`${label}不能大于计划结束时间${planCompleteTime}`);
|
|
|
+ row[field] = '';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
// 时间校验
|
|
|
checkEndTimeValid(row) {
|
|
|
const { startTime: start, endTime: end } = row;
|
|
|
- // if (!start || !end) return; // 开始/结束时间未填,跳过
|
|
|
+ if (!start || !end) return;
|
|
|
const startTime = new Date(start); // 开始时间
|
|
|
const endTime = new Date(end); // 结束时间
|
|
|
if (endTime < startTime) {
|
|
|
- row.endTime = new Date(startTime); // 修正为开始时间
|
|
|
- this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
|
|
|
+ row.endTime = '';
|
|
|
+ this.$message.closeAll();
|
|
|
+ this.$message.info('计划完成时间不能小于计划开始时间');
|
|
|
}
|
|
|
}
|
|
|
}
|