feat(qc): 新增厂家卷号匹配功能,优化卷号录入体验
本次改动在检验任务、化学成分报告、物理性能报告模块中: 1. 支持通过入场卷号和厂家卷号双向搜索匹配 2. 新增多选卷号标签式展示与删除功能 3. 新增批量导入时厂家卷号自动匹配入场卷号的逻辑,包含多匹配结果弹窗选择 4. 在表格中新增厂家卷号展示列,更新导入模板支持厂家卷号字段
This commit is contained in:
@@ -132,11 +132,22 @@
|
||||
<el-autocomplete
|
||||
v-model="form.coilNo"
|
||||
:fetch-suggestions="queryCoilNo"
|
||||
placeholder="请输入入场钢卷号(输入2个字符以上自动搜索)"
|
||||
placeholder="输入入场钢卷号搜索"
|
||||
:loading="coilNoLoading"
|
||||
:trigger-on-focus="false"
|
||||
clearable
|
||||
/>
|
||||
<el-autocomplete
|
||||
v-model="tempSupplierCoilNo"
|
||||
:fetch-suggestions="querySupplierCoilNo"
|
||||
placeholder="或输入厂家卷号自动匹配"
|
||||
:loading="supplierCoilNoLoading"
|
||||
:trigger-on-focus="false"
|
||||
clearable
|
||||
size="small"
|
||||
@select="handleSelectSupplierCoilNo"
|
||||
style="margin-top: 6px;"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="炉号" prop="heatNo">
|
||||
<el-input v-model="form.heatNo" placeholder="请输入炉号" />
|
||||
@@ -248,6 +259,7 @@
|
||||
:row-class-name="importTableRowClassName">
|
||||
<el-table-column label="#" width="48" type="index" align="center" />
|
||||
<el-table-column prop="coilNo" label="入场钢卷号" width="140" />
|
||||
<el-table-column prop="supplierCoilNo" label="厂家卷号" width="120" />
|
||||
<el-table-column prop="c" label="C(%)" width="70" align="center" />
|
||||
<el-table-column prop="si" label="Si(%)" width="70" align="center" />
|
||||
<el-table-column prop="mn" label="Mn(%)" width="70" align="center" />
|
||||
@@ -295,6 +307,31 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog title="选择对应入场卷号" :visible.sync="ambiguousVisible" width="600px" append-to-body :close-on-click-modal="false">
|
||||
<div style="font-size: 12px; color: #909399; margin-bottom: 12px;">
|
||||
厂家卷号匹配到多条入场卷号,请为每行选择对应记录
|
||||
</div>
|
||||
<el-table :data="ambiguousRows" border size="small" max-height="350">
|
||||
<el-table-column label="厂家卷号" prop="supplierCoilNo" width="140" />
|
||||
<el-table-column label="选择入场卷号" min-width="280">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.selected" placeholder="请选择入场卷号" size="small" style="width: 100%;">
|
||||
<el-option
|
||||
v-for="opt in scope.row.options"
|
||||
:key="opt"
|
||||
:label="opt"
|
||||
:value="opt"
|
||||
/>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="confirmAmbiguous">确 定</el-button>
|
||||
<el-button @click="ambiguousVisible = false">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -304,10 +341,11 @@ import { listChemicalItem, getChemicalItem, delChemicalItem, addChemicalItem, up
|
||||
import CoilSelector from "@/components/CoilSelector";
|
||||
import { listMaterialCoil } from "@/api/wms/coil";
|
||||
|
||||
const CHEMI_TEMPLATE_HEADERS = ['入场钢卷号', 'C(%)', 'Si(%)', 'Mn(%)', 'P(%)', 'S(%)', 'Als(%)', 'Al(%)', 'Ti(%)', 'Cr(%)', 'Ni(%)', 'Cu(%)', 'N(%)', 'Fe(%)', 'B(%)'];
|
||||
const CHEMI_TEMPLATE_HEADERS = ['入场钢卷号', '厂家卷号', 'C(%)', 'Si(%)', 'Mn(%)', 'P(%)', 'S(%)', 'Als(%)', 'Al(%)', 'Ti(%)', 'Cr(%)', 'Ni(%)', 'Cu(%)', 'N(%)', 'Fe(%)', 'B(%)'];
|
||||
|
||||
const CHEMI_HEADER_MAP = {
|
||||
'入场钢卷号': 'coilNo',
|
||||
'厂家卷号': 'supplierCoilNo',
|
||||
'C(%)': 'c',
|
||||
'Si(%)': 'si',
|
||||
'Mn(%)': 'mn',
|
||||
@@ -395,6 +433,10 @@ export default {
|
||||
importLoading: false,
|
||||
coilNoOptions: [],
|
||||
coilNoLoading: false,
|
||||
tempSupplierCoilNo: '',
|
||||
supplierCoilNoLoading: false,
|
||||
ambiguousVisible: false,
|
||||
ambiguousRows: [],
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@@ -490,6 +532,34 @@ export default {
|
||||
this.coilNoLoading = false;
|
||||
});
|
||||
},
|
||||
querySupplierCoilNo(queryString, cb) {
|
||||
if (!queryString || queryString.length < 2) {
|
||||
cb([]);
|
||||
return;
|
||||
}
|
||||
this.supplierCoilNoLoading = true;
|
||||
listMaterialCoil({
|
||||
supplierCoilNo: queryString,
|
||||
pageNum: 1,
|
||||
pageSize: 20
|
||||
}).then(response => {
|
||||
const options = (response.rows || []).map(item => ({
|
||||
value: item.supplierCoilNo,
|
||||
label: item.supplierCoilNo,
|
||||
enterCoilNo: item.enterCoilNo
|
||||
}));
|
||||
cb(options);
|
||||
}).finally(() => {
|
||||
this.supplierCoilNoLoading = false;
|
||||
});
|
||||
},
|
||||
handleSelectSupplierCoilNo(item) {
|
||||
if (item.enterCoilNo) {
|
||||
this.form.coilNo = item.enterCoilNo;
|
||||
this.$refs["form"].validateField('coilNo');
|
||||
}
|
||||
this.tempSupplierCoilNo = '';
|
||||
},
|
||||
handleBatchAdd(rows) {
|
||||
this.loading = true;
|
||||
this.buttonLoading = true;
|
||||
@@ -559,12 +629,90 @@ export default {
|
||||
if (!this.importFile || !this.importRawData.length) { this.$message.warning('暂无数据可校验'); return; }
|
||||
this.importValidateLoading = true;
|
||||
this.importErrorList = [];
|
||||
for (let i = 0; i < this.importRawData.length; i++) {
|
||||
this.ambiguousRows = [];
|
||||
const dataRows = this.importRawData;
|
||||
for (let i = 0; i < dataRows.length; i++) {
|
||||
const rowNum = i + 2;
|
||||
let coilNo = '';
|
||||
CHEMI_TEMPLATE_HEADERS.forEach((h, j) => { if (CHEMI_HEADER_MAP[h] === 'coilNo') coilNo = this.importRawData[i][j]; });
|
||||
if (!coilNo || !String(coilNo).trim()) this.importErrorList.push({ rowNum, errorMsg: '当前钢卷号不能为空' });
|
||||
let coilNo = '', supplierCoilNo = '';
|
||||
CHEMI_TEMPLATE_HEADERS.forEach((h, j) => {
|
||||
if (CHEMI_HEADER_MAP[h] === 'coilNo') coilNo = dataRows[i][j];
|
||||
if (CHEMI_HEADER_MAP[h] === 'supplierCoilNo') supplierCoilNo = dataRows[i][j];
|
||||
});
|
||||
coilNo = String(coilNo || '').trim();
|
||||
supplierCoilNo = String(supplierCoilNo || '').trim();
|
||||
if (!coilNo && !supplierCoilNo) {
|
||||
this.importErrorList.push({ rowNum, errorMsg: '入场钢卷号和厂家卷号不能同时为空' });
|
||||
}
|
||||
}
|
||||
// 处理仅填写厂家卷号的行
|
||||
if (this.importErrorList.length === 0) {
|
||||
this.importTableData.forEach((row, idx) => {
|
||||
const cn = (row.coilNo || '').trim();
|
||||
const sn = (row.supplierCoilNo || '').trim();
|
||||
row._sno = sn;
|
||||
row._idx = idx;
|
||||
row._fillCoilNo = cn;
|
||||
// 仅厂家卷号且无入场卷号的行需匹配
|
||||
if (sn && !cn) row._needMatch = true;
|
||||
});
|
||||
const needMatchRows = this.importTableData.filter(r => r._needMatch);
|
||||
if (needMatchRows.length > 0) {
|
||||
const uniqueSnos = [...new Set(needMatchRows.map(r => r._sno))];
|
||||
const multiMap = {}; // supplierCoilNo -> [enterCoilNo, ...]
|
||||
try {
|
||||
const results = await Promise.all(
|
||||
uniqueSnos.map(sno => listMaterialCoil({ supplierCoilNo: sno, pageNum: 1, pageSize: 50 }))
|
||||
);
|
||||
uniqueSnos.forEach((sno, idx) => {
|
||||
const rows = (results[idx] && results[idx].rows) || [];
|
||||
const enterNos = [...new Set(rows.map(r => r.enterCoilNo).filter(Boolean))];
|
||||
multiMap[sno] = enterNos;
|
||||
});
|
||||
} catch (err) {
|
||||
this.importValidateLoading = false;
|
||||
this.importHandleError('厂家卷号匹配失败:' + err.message);
|
||||
return;
|
||||
}
|
||||
const ambiguousList = [];
|
||||
needMatchRows.forEach(row => {
|
||||
const candidates = multiMap[row._sno] || [];
|
||||
if (candidates.length === 0) {
|
||||
this.importErrorList.push({ rowNum: (row.rowNum || (row._idx + 2)), errorMsg: `厂家卷号"${row._sno}"未匹配到入场卷号` });
|
||||
} else if (candidates.length === 1) {
|
||||
row.coilNo = candidates[0];
|
||||
} else {
|
||||
ambiguousList.push({
|
||||
_idx: row._idx,
|
||||
supplierCoilNo: row._sno,
|
||||
options: candidates,
|
||||
selected: null
|
||||
});
|
||||
}
|
||||
});
|
||||
if (ambiguousList.length > 0) {
|
||||
this.ambiguousRows = ambiguousList;
|
||||
this.importValidateLoading = false;
|
||||
this.ambiguousVisible = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.finishValidation();
|
||||
},
|
||||
confirmAmbiguous() {
|
||||
const unselected = this.ambiguousRows.filter(r => !r.selected);
|
||||
if (unselected.length > 0) {
|
||||
this.$message.warning('请为所有行选择入场卷号');
|
||||
return;
|
||||
}
|
||||
this.ambiguousRows.forEach(item => {
|
||||
this.importTableData[item._idx].coilNo = item.selected;
|
||||
});
|
||||
this.ambiguousVisible = false;
|
||||
this.importValidateLoading = true;
|
||||
this.finishValidation();
|
||||
},
|
||||
finishValidation() {
|
||||
if (this.importErrorList.length > 0) {
|
||||
this.$message.error(`数据校验失败,共发现${this.importErrorList.length}条错误`);
|
||||
} else {
|
||||
@@ -617,10 +765,10 @@ export default {
|
||||
this.$refs.importUpload?.clearFiles();
|
||||
},
|
||||
importDownloadTemplate() {
|
||||
const data = [CHEMI_TEMPLATE_HEADERS, ['示例卷号', '0.05', '0.02', '0.30', '0.015', '0.008', '0.040', '0.04', '0.05', '0.03', '0.02', '0.03', '0.005', '98', '0.001']];
|
||||
const data = [CHEMI_TEMPLATE_HEADERS, ['示例卷号', '示例厂家卷号', '0.05', '0.02', '0.30', '0.015', '0.008', '0.040', '0.04', '0.05', '0.03', '0.02', '0.03', '0.005', '98', '0.001']];
|
||||
const wb = XLSX.utils.book_new();
|
||||
const ws = XLSX.utils.aoa_to_sheet(data);
|
||||
ws['!cols'] = [{ wch: 16 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }];
|
||||
ws['!cols'] = [{ wch: 16 }, { wch: 16 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }, { wch: 8 }];
|
||||
XLSX.utils.book_append_sheet(wb, ws, '导入模板');
|
||||
XLSX.writeFile(wb, '化学成分导入模板.xlsx');
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user