密炼生产计划维护表更改

This commit is contained in:
2026-06-17 16:39:39 +08:00
parent 2ec2b6a628
commit 816af5df6e
9 changed files with 384 additions and 240 deletions

View File

@@ -14,15 +14,7 @@
<a-button preIcon="ant-design:reload-outlined" :loading="refreshing" :disabled="saving" @click="handleRefresh">刷新</a-button>
</div>
<a-table
:columns="columns"
:data-source="rows"
:pagination="false"
:scroll="{ x: 1560 }"
row-key="_rowKey"
size="small"
bordered
>
<a-table :columns="columns" :data-source="rows" :pagination="false" :scroll="{ x: 1560 }" row-key="_rowKey" size="small" bordered>
<template #bodyCell="{ column, record, index }">
<template v-if="column.dataIndex === 'machineName'">
<a-input
@@ -108,13 +100,15 @@
import MesXslMixingPlanOrderSelectModal from './components/MesXslMixingPlanOrderSelectModal.vue';
import { list, saveAll } from './MesXslMixingProductionPlan.api';
type ShiftKey = 'morning' | 'noon' | 'night';
const { createMessage } = useMessage();
const saving = ref(false);
const refreshing = ref(false);
const querying = ref(false);
const queryPlanDate = ref<string>('');
const rows = ref<Recordable[]>([]);
const pickerContext = ref<{ rowIndex: number; shift?: 'morning' | 'noon' | 'night' } | null>(null);
const pickerContext = ref<{ rowIndex: number; shift?: ShiftKey } | null>(null);
const [registerEquipmentModal, { openModal: openEquipmentModal }] = useModal();
const [registerOrderModal, { openModal: openOrderModal }] = useModal();
@@ -158,11 +152,14 @@
function createEmptyRow(): Recordable {
return {
_rowKey: buildUUID(),
id: '',
planDate: queryPlanDate.value || '',
machineId: '',
machineName: '',
morningId: '',
morningShiftFlag: 1,
morningPlanId: '',
morningPlanType: '',
morningSourceOrderId: '',
morningOrderNo: '',
morningOrderDate: '',
morningFormulaName: '',
@@ -172,8 +169,11 @@
morningFinishedCarCount: null,
morningPlanCount: null,
morningRemark: '',
noonId: '',
noonShiftFlag: 2,
noonPlanId: '',
noonPlanType: '',
noonSourceOrderId: '',
noonOrderNo: '',
noonOrderDate: '',
noonFormulaName: '',
@@ -183,8 +183,11 @@
noonFinishedCarCount: null,
noonPlanCount: null,
noonRemark: '',
nightId: '',
nightShiftFlag: 3,
nightPlanId: '',
nightPlanType: '',
nightSourceOrderId: '',
nightOrderNo: '',
nightOrderDate: '',
nightFormulaName: '',
@@ -197,7 +200,7 @@
};
}
function shiftByOrderField(field: string): 'morning' | 'noon' | 'night' {
function shiftByOrderField(field: string): ShiftKey {
if (field.startsWith('morning')) return 'morning';
if (field.startsWith('noon')) return 'noon';
return 'night';
@@ -240,7 +243,7 @@
pickerContext.value = null;
}
function openOrderPicker(rowIndex: number, shift: 'morning' | 'noon' | 'night') {
function openOrderPicker(rowIndex: number, shift: ShiftKey) {
const row = rows.value[rowIndex];
if (!row?.machineId && !row?.machineName) {
createMessage.warning('请先选择机台信息');
@@ -283,6 +286,102 @@
return Math.max(0, remain);
}
function applyShiftRecord(row: Recordable, shift: ShiftKey, record: Recordable) {
if (!record) return;
row[`${shift}Id`] = record.id || '';
row[`${shift}ShiftFlag`] = record.shiftFlag ?? (shift === 'morning' ? 1 : shift === 'noon' ? 2 : 3);
row[`${shift}PlanId`] = record.planId || '';
row[`${shift}PlanType`] = record.planType || '';
row[`${shift}SourceOrderId`] = record.sourceOrderId || '';
row[`${shift}OrderNo`] = record.orderNo || '';
row[`${shift}OrderDate`] = record.orderDate || '';
row[`${shift}FormulaName`] = record.formulaName || '';
row[`${shift}PlanWeight`] = record.planWeight ?? null;
row[`${shift}PlannedCarCount`] = record.plannedCarCount ?? null;
row[`${shift}ScheduledCarCount`] = record.scheduledCarCount ?? null;
row[`${shift}FinishedCarCount`] = record.finishedCarCount ?? null;
row[`${shift}PlanCount`] = record.planCount ?? null;
row[`${shift}Remark`] = record.remark || '';
}
function convertSharedRecordsToDisplayRows(records: Recordable[]) {
const groupMap = new Map<string, { machineId: string; machineName: string; planDate: string; morning: Recordable[]; noon: Recordable[]; night: Recordable[] }>();
(records || []).forEach((rec) => {
const machineId = rec.machineId || '';
const machineName = rec.machineName || '';
const planDate = rec.planDate || '';
const key = `${planDate}__${machineId}__${machineName}`;
if (!groupMap.has(key)) {
groupMap.set(key, {
machineId,
machineName,
planDate,
morning: [],
noon: [],
night: [],
});
}
const group = groupMap.get(key)!;
const flag = Number(rec.shiftFlag);
if (flag === 1) group.morning.push(rec);
else if (flag === 2) group.noon.push(rec);
else group.night.push(rec);
});
const result: Recordable[] = [];
Array.from(groupMap.values()).forEach((group) => {
const maxLen = Math.max(group.morning.length, group.noon.length, group.night.length);
for (let i = 0; i < maxLen; i++) {
const row = createEmptyRow();
row._rowKey = buildUUID();
row.planDate = group.planDate;
row.machineId = group.machineId;
row.machineName = group.machineName;
applyShiftRecord(row, 'morning', group.morning[i]);
applyShiftRecord(row, 'noon', group.noon[i]);
applyShiftRecord(row, 'night', group.night[i]);
result.push(row);
}
});
return result;
}
function hasShiftData(row: Recordable, shift: ShiftKey) {
return !!(
row?.[`${shift}PlanId`] ||
row?.[`${shift}OrderNo`] ||
row?.[`${shift}FormulaName`] ||
row?.[`${shift}PlanCount`] != null ||
row?.[`${shift}Remark`]
);
}
function buildSharedShiftRecord(row: Recordable, shift: ShiftKey): Recordable | null {
if (!hasShiftData(row, shift) || (!row?.machineId && !row?.machineName)) {
return null;
}
const shiftFlag = shift === 'morning' ? 1 : shift === 'noon' ? 2 : 3;
return {
id: row?.[`${shift}Id`] || '',
planDate: row?.planDate || queryPlanDate.value || '',
machineId: row?.machineId || '',
machineName: row?.machineName || '',
shiftFlag,
planId: row?.[`${shift}PlanId`] || '',
planType: row?.[`${shift}PlanType`] || '',
sourceOrderId: row?.[`${shift}SourceOrderId`] || '',
orderNo: row?.[`${shift}OrderNo`] || '',
orderDate: row?.[`${shift}OrderDate`] || '',
formulaName: row?.[`${shift}FormulaName`] || '',
planWeight: row?.[`${shift}PlanWeight`] ?? null,
plannedCarCount: row?.[`${shift}PlannedCarCount`] ?? null,
scheduledCarCount: row?.[`${shift}ScheduledCarCount`] ?? null,
finishedCarCount: row?.[`${shift}FinishedCarCount`] ?? null,
planCount: row?.[`${shift}PlanCount`] ?? null,
remark: row?.[`${shift}Remark`] || '',
};
}
async function loadRows() {
const res = await list({
pageNo: 1,
@@ -290,18 +389,29 @@
planDate: queryPlanDate.value || undefined,
});
const records = (res?.records || res?.result?.records || []) as Recordable[];
rows.value = (records || []).map((item) => ({ ...createEmptyRow(), ...item, _rowKey: item.id || buildUUID() }));
rows.value = convertSharedRecordsToDisplayRows(records);
const minRows = 20;
if (!rows.value.length) {
rows.value = createBlankRows();
rows.value = createBlankRows(minRows);
return;
}
if (rows.value.length < minRows) {
rows.value.push(...createBlankRows(minRows - rows.value.length));
}
}
async function handleSaveAll() {
saving.value = true;
try {
const payload = rows.value.map((r) => {
const { _rowKey, ...rest } = r;
return rest;
const payload = rows.value.flatMap((row) => {
const list: Recordable[] = [];
const morning = buildSharedShiftRecord(row, 'morning');
const noon = buildSharedShiftRecord(row, 'noon');
const night = buildSharedShiftRecord(row, 'night');
if (morning) list.push(morning);
if (noon) list.push(noon);
if (night) list.push(night);
return list;
});
await saveAll({ rows: payload });
createMessage.success('保存成功');