✨ 运单导入新增与已有运单重复页签
This commit is contained in:
@@ -95,3 +95,5 @@ export const exportImportFailures = data =>
|
|||||||
});
|
});
|
||||||
export const confirmImport = data =>
|
export const confirmImport = data =>
|
||||||
request({ url: `${baseUrl}/import-batch/confirm`, method: 'post', data, timeout: 120000 });
|
request({ url: `${baseUrl}/import-batch/confirm`, method: 'post', data, timeout: 120000 });
|
||||||
|
export const checkImportDuplicates = data =>
|
||||||
|
request({ url: `${baseUrl}/import-batch/duplicates`, method: 'post', data, timeout: 120000 });
|
||||||
|
|||||||
@@ -484,20 +484,24 @@
|
|||||||
</div>
|
</div>
|
||||||
<el-tabs v-model="previewTab"
|
<el-tabs v-model="previewTab"
|
||||||
><el-tab-pane :label="`运单数(${rows.length})`" name="all" /><el-tab-pane
|
><el-tab-pane :label="`运单数(${rows.length})`" name="all" /><el-tab-pane
|
||||||
:label="`疑似重复(${duplicateRows.length})`"
|
:label="`Excel内重复(${duplicateRows.length})`"
|
||||||
name="duplicate" /></el-tabs
|
name="duplicate" /><el-tab-pane
|
||||||
|
:label="`与已有运单重复(${historyDuplicateRows.length})`"
|
||||||
|
name="history" /></el-tabs
|
||||||
><el-table
|
><el-table
|
||||||
:data="previewRows"
|
:data="previewRows"
|
||||||
border
|
border
|
||||||
max-height="440"
|
max-height="440"
|
||||||
:row-class-name="({ row }) => (row._duplicate ? 'is-duplicate-row' : '')"
|
:row-class-name="
|
||||||
|
({ row }) => (row._duplicate || row._historyWaybillNo ? 'is-duplicate-row' : '')
|
||||||
|
"
|
||||||
@selection-change="rowSelection = $event"
|
@selection-change="rowSelection = $event"
|
||||||
><el-table-column type="selection" width="55" /><el-table-column
|
><el-table-column type="selection" width="55" /><el-table-column
|
||||||
type="index"
|
type="index"
|
||||||
label="序号"
|
label="序号"
|
||||||
width="65"
|
width="65"
|
||||||
/><el-table-column
|
/><el-table-column
|
||||||
v-for="column in detailColumns"
|
v-for="column in previewColumns"
|
||||||
:key="column.prop"
|
:key="column.prop"
|
||||||
:prop="column.prop"
|
:prop="column.prop"
|
||||||
:label="column.label"
|
:label="column.label"
|
||||||
@@ -583,8 +587,6 @@
|
|||||||
><el-link type="primary" @click="saveRow(row)">保存</el-link
|
><el-link type="primary" @click="saveRow(row)">保存</el-link
|
||||||
><el-link type="primary" @click="cancelRow(row)">取消</el-link></template
|
><el-link type="primary" @click="cancelRow(row)">取消</el-link></template
|
||||||
><template v-else
|
><template v-else
|
||||||
><el-link v-if="row._duplicate" type="primary" @click="confirmDuplicateRow(row)"
|
|
||||||
>确认</el-link
|
|
||||||
><el-link type="primary" @click="editRow(row)">编辑</el-link
|
><el-link type="primary" @click="editRow(row)">编辑</el-link
|
||||||
><el-link type="danger" @click="deleteRow(row)">删除</el-link></template
|
><el-link type="danger" @click="deleteRow(row)">删除</el-link></template
|
||||||
></div
|
></div
|
||||||
@@ -716,9 +718,12 @@ const transportTypeOptions = ref([]),
|
|||||||
const rowSelection = ref([]),
|
const rowSelection = ref([]),
|
||||||
previewTab = ref('all');
|
previewTab = ref('all');
|
||||||
const duplicateRows = computed(() => rows.value.filter(row => row._duplicate));
|
const duplicateRows = computed(() => rows.value.filter(row => row._duplicate));
|
||||||
const previewRows = computed(() =>
|
const historyDuplicateRows = computed(() => rows.value.filter(row => row._historyWaybillNo));
|
||||||
previewTab.value === 'duplicate' ? duplicateRows.value : rows.value
|
const previewRows = computed(() => {
|
||||||
);
|
if (previewTab.value === 'duplicate') return duplicateRows.value;
|
||||||
|
if (previewTab.value === 'history') return historyDuplicateRows.value;
|
||||||
|
return rows.value;
|
||||||
|
});
|
||||||
const carrierContractsLoaded = ref(false),
|
const carrierContractsLoaded = ref(false),
|
||||||
hasCarrierContracts = ref(null);
|
hasCarrierContracts = ref(null);
|
||||||
const carrierTypes = ['承运商', '自运'];
|
const carrierTypes = ['承运商', '自运'];
|
||||||
@@ -795,6 +800,16 @@ const detailColumns = [
|
|||||||
{ prop: 'remark', label: '备注', editor: 'textarea', minWidth: 200 },
|
{ prop: 'remark', label: '备注', editor: 'textarea', minWidth: 200 },
|
||||||
{ prop: 'waybillIdentifier', label: '同一运单标识号', editor: 'input', minWidth: 150 },
|
{ prop: 'waybillIdentifier', label: '同一运单标识号', editor: 'input', minWidth: 150 },
|
||||||
];
|
];
|
||||||
|
// 与已有运单重复页签的列与明细一致,只在运单批次号后多一列已有运单号。
|
||||||
|
const previewColumns = computed(() =>
|
||||||
|
previewTab.value === 'history'
|
||||||
|
? [
|
||||||
|
detailColumns[0],
|
||||||
|
{ prop: '_historyWaybillNo', label: '已有运单号', minWidth: 220 },
|
||||||
|
...detailColumns.slice(1),
|
||||||
|
]
|
||||||
|
: detailColumns
|
||||||
|
);
|
||||||
const requiredDetailFields = [
|
const requiredDetailFields = [
|
||||||
{ prop: 'vehicleNo', label: '车牌号/船班号/船次号/班次号' },
|
{ prop: 'vehicleNo', label: '车牌号/船班号/船次号/班次号' },
|
||||||
{ prop: 'transportType', label: '运输方式' },
|
{ prop: 'transportType', label: '运输方式' },
|
||||||
@@ -1187,6 +1202,7 @@ const loadBatchRows = async batchId => {
|
|||||||
batchNo: item.batchNo || form.batchNo,
|
batchNo: item.batchNo || form.batchNo,
|
||||||
}));
|
}));
|
||||||
refreshDuplicateFlags();
|
refreshDuplicateFlags();
|
||||||
|
await refreshHistoryDuplicates();
|
||||||
rowSelection.value = [];
|
rowSelection.value = [];
|
||||||
previewTab.value = 'all';
|
previewTab.value = 'all';
|
||||||
};
|
};
|
||||||
@@ -1509,6 +1525,8 @@ const fileChange = async (file, list) => {
|
|||||||
if (isValid) {
|
if (isValid) {
|
||||||
// 校验通过,填充表格数据
|
// 校验通过,填充表格数据
|
||||||
rows.value = parsedRows;
|
rows.value = parsedRows;
|
||||||
|
// 传 rows.value(响应式代理),否则后续写入不触发重新渲染
|
||||||
|
await refreshHistoryDuplicates(rows.value);
|
||||||
} else {
|
} else {
|
||||||
// 校验失败,清空数据
|
// 校验失败,清空数据
|
||||||
rows.value = [];
|
rows.value = [];
|
||||||
@@ -1526,16 +1544,12 @@ const IMPORT_BATCH_SIZE = 100;
|
|||||||
|
|
||||||
const importFieldText = value => String(value ?? '').trim();
|
const importFieldText = value => String(value ?? '').trim();
|
||||||
|
|
||||||
/** 同一运单批次号下,全部导入字段一致时标记为疑似重复。已在线确认的行不再标为重复。 */
|
/** 同一运单批次号下,全部导入字段一致时标记为 Excel 内重复。 */
|
||||||
const refreshDuplicateFlags = (list = rows.value) => {
|
const refreshDuplicateFlags = (list = rows.value) => {
|
||||||
const groups = new Map();
|
const groups = new Map();
|
||||||
list.forEach(row => {
|
list.forEach(row => {
|
||||||
const signature = detailColumns.map(column => importFieldText(row[column.prop])).join('\u0001');
|
const signature = detailColumns.map(column => importFieldText(row[column.prop])).join('\u0001');
|
||||||
const batchNo = importFieldText(row.batchNo || form.batchNo);
|
const batchNo = importFieldText(row.batchNo || form.batchNo);
|
||||||
if (row._duplicateConfirmed && row._duplicateSignature !== signature) {
|
|
||||||
row._duplicateConfirmed = false;
|
|
||||||
}
|
|
||||||
row._duplicateSignature = signature;
|
|
||||||
const groupKey = `${batchNo}\u0002${signature}`;
|
const groupKey = `${batchNo}\u0002${signature}`;
|
||||||
const group = groups.get(groupKey) || [];
|
const group = groups.get(groupKey) || [];
|
||||||
group.push(row);
|
group.push(row);
|
||||||
@@ -1544,19 +1558,39 @@ const refreshDuplicateFlags = (list = rows.value) => {
|
|||||||
groups.forEach(group => {
|
groups.forEach(group => {
|
||||||
const duplicated = group.length > 1;
|
const duplicated = group.length > 1;
|
||||||
group.forEach(row => {
|
group.forEach(row => {
|
||||||
row._duplicate = duplicated && !row._duplicateConfirmed;
|
row._duplicate = duplicated;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmDuplicateRow = row => {
|
/** 逐行提交给后端与项目下已有运单比对,命中的行带上已有运单号。比对失败不影响导入。 */
|
||||||
row._duplicateConfirmed = true;
|
const refreshHistoryDuplicates = async (list = rows.value) => {
|
||||||
refreshDuplicateFlags();
|
if (!list.length || !form.projectId) {
|
||||||
ElMessage.success('已确认,该行将按正常数据导入');
|
list.forEach(row => {
|
||||||
|
row._historyWaybillNo = '';
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let duplicates = [];
|
||||||
|
try {
|
||||||
|
const res = await api.checkImportDuplicates(buildImportPayload(form.status, list));
|
||||||
|
const data = res?.data?.data ?? res?.data ?? res;
|
||||||
|
duplicates = Array.isArray(data) ? data : [];
|
||||||
|
} catch (error) {
|
||||||
|
console.error('与已有运单重复校验失败:', error);
|
||||||
|
duplicates = [];
|
||||||
|
}
|
||||||
|
const numbersByRow = new Map(
|
||||||
|
duplicates.map(item => [item.rowIndex, (item.waybillNos || []).filter(Boolean)])
|
||||||
|
);
|
||||||
|
list.forEach((row, index) => {
|
||||||
|
row._historyWaybillNo = (numbersByRow.get(index) || []).join('、');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const stripInternalRowFields = row => {
|
const stripInternalRowFields = row => {
|
||||||
const { _key, _duplicate, _duplicateKey, _duplicateConfirmed, _duplicateSignature, _editing, _editSnapshot, ...data } = row;
|
const { _key, _duplicate, _duplicateKey, _editing, _editSnapshot, _historyWaybillNo, ...data } =
|
||||||
|
row;
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1771,6 +1805,7 @@ const saveRow = row => {
|
|||||||
row._editing = false;
|
row._editing = false;
|
||||||
delete row._editSnapshot;
|
delete row._editSnapshot;
|
||||||
refreshDuplicateFlags();
|
refreshDuplicateFlags();
|
||||||
|
refreshHistoryDuplicates();
|
||||||
};
|
};
|
||||||
const cancelRow = row => {
|
const cancelRow = row => {
|
||||||
if (row._editSnapshot) Object.assign(row, row._editSnapshot);
|
if (row._editSnapshot) Object.assign(row, row._editSnapshot);
|
||||||
@@ -1780,12 +1815,14 @@ const cancelRow = row => {
|
|||||||
const deleteRow = row => {
|
const deleteRow = row => {
|
||||||
rows.value = rows.value.filter(item => item !== row);
|
rows.value = rows.value.filter(item => item !== row);
|
||||||
refreshDuplicateFlags();
|
refreshDuplicateFlags();
|
||||||
|
refreshHistoryDuplicates();
|
||||||
};
|
};
|
||||||
const removeSelectedRows = () => {
|
const removeSelectedRows = () => {
|
||||||
const keys = new Set(rowSelection.value.map(row => row._key));
|
const keys = new Set(rowSelection.value.map(row => row._key));
|
||||||
rows.value = rows.value.filter(row => !keys.has(row._key));
|
rows.value = rows.value.filter(row => !keys.has(row._key));
|
||||||
rowSelection.value = [];
|
rowSelection.value = [];
|
||||||
refreshDuplicateFlags();
|
refreshDuplicateFlags();
|
||||||
|
refreshHistoryDuplicates();
|
||||||
};
|
};
|
||||||
const normalizeOptionalPlanId = value => {
|
const normalizeOptionalPlanId = value => {
|
||||||
if (value === undefined || value === null || value === '') return null;
|
if (value === undefined || value === null || value === '') return null;
|
||||||
@@ -1849,7 +1886,11 @@ const confirmImport = async () => {
|
|||||||
await formRef.value?.validate();
|
await formRef.value?.validate();
|
||||||
if (!validateImportRows()) return;
|
if (!validateImportRows()) return;
|
||||||
const count = rows.value.filter(row => row._duplicate).length;
|
const count = rows.value.filter(row => row._duplicate).length;
|
||||||
if (count) await ElMessageBox.confirm(`当前导入有${count}条疑似重复数据,是否确认导入?`, '提示');
|
if (count)
|
||||||
|
await ElMessageBox.confirm(`当前导入有${count}条Excel内重复数据,是否确认导入?`, '提示');
|
||||||
|
const historyCount = rows.value.filter(row => row._historyWaybillNo).length;
|
||||||
|
if (historyCount)
|
||||||
|
await ElMessageBox.confirm(`当前导入有${historyCount}条与已有运单重复,是否确认导入?`, '提示');
|
||||||
if (form.importType === 'settlement' && form.status === 'completed')
|
if (form.importType === 'settlement' && form.status === 'completed')
|
||||||
await ElMessageBox.confirm('确认后将同时生成运单、应收应付明细、计结算单,是否继续?', '提示');
|
await ElMessageBox.confirm('确认后将同时生成运单、应收应付明细、计结算单,是否继续?', '提示');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user