feat(mes/qc/certificate): 新增化学成分和物理性能数据批量导入功能
1. 为化学成分和物理性能页面添加导入按钮与完整的导入弹窗流程 2. 实现Excel模板下载、文件上传、数据校验、钢卷匹配、批量导入全流程 3. 支持多匹配钢卷选择、导入进度展示与结果反馈 4. 适配两种业务表单的导入逻辑,包含错误处理和状态管理
This commit is contained in:
@@ -39,6 +39,15 @@
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini">批量新增</el-button>
|
||||
</coil-selector>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="el-icon-upload2"
|
||||
size="mini"
|
||||
@click="openImportDialog"
|
||||
>导入</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
@@ -148,18 +157,198 @@
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 导入对话框 -->
|
||||
<el-dialog title="导入化学成分" :visible.sync="importDialogVisible" width="1100px" top="5vh" append-to-body>
|
||||
<div class="import-container">
|
||||
|
||||
<!-- 步骤条 -->
|
||||
<div class="import-steps">
|
||||
<div class="step" :class="{ active: true, done: importStatus !== 'idle' && importStatus !== 'validated' }">
|
||||
<div class="step-badge">1</div>
|
||||
<div class="step-label">下载模板</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus !== 'idle' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'validated' || importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished', done: importStatus !== 'idle' && importStatus !== 'validated' }">
|
||||
<div class="step-badge">2</div>
|
||||
<div class="step-label">上传文件</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished', done: importStatus === 'processing' || importStatus === 'finished' }">
|
||||
<div class="step-badge">3</div>
|
||||
<div class="step-label">校验数据</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus === 'processing' || importStatus === 'finished' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished', done: importStatus === 'finished' }">
|
||||
<div class="step-badge step-badge-warn">4</div>
|
||||
<div class="step-label">匹配钢卷</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus === 'finished' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'processing' || importStatus === 'finished', done: importStatus === 'finished' }">
|
||||
<div class="step-badge step-badge-success">5</div>
|
||||
<div class="step-label">批量导入</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="import-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<el-upload ref="importUpload" action="" :auto-upload="false" :show-file-list="false"
|
||||
:on-change="importHandleFileChange" accept=".xlsx,.xls"
|
||||
:disabled="importStatus !== 'idle' && importStatus !== 'validated'">
|
||||
<el-button :type="importFile ? 'default' : 'primary'" :icon="importFile ? 'el-icon-document' : 'el-icon-upload2'">
|
||||
{{ importFile ? importFile.name : '选择Excel文件' }}
|
||||
</el-button>
|
||||
</el-upload>
|
||||
<el-button type="success" plain icon="el-icon-check" @click="importHandleValidate"
|
||||
:disabled="!importFile || importValidateLoading || importStatus !== 'idle'" :loading="importValidateLoading">校验数据</el-button>
|
||||
<el-button type="warning" plain icon="el-icon-coordinate" @click="importMatchCoils"
|
||||
v-if="importStatus === 'validated'" :loading="importMatchingLoading"
|
||||
:disabled="importMatchingLoading || importErrorList.length > 0">匹配钢卷</el-button>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<el-button v-if="importStatus === 'matched'" type="primary" icon="el-icon-upload-success" @click="importStartImport" :loading="importLoading">开始导入</el-button>
|
||||
<el-button plain icon="el-icon-download" @click="importDownloadTemplate">下载模板</el-button>
|
||||
<el-button plain icon="el-icon-refresh" @click="importReset">重置</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 匹配结果摘要 -->
|
||||
<div v-if="importStatus === 'matched'" class="match-summary">
|
||||
<div class="summary-item summary-matched">
|
||||
<span class="summary-num">{{ matchedCount }}</span>
|
||||
<span class="summary-label">已匹配</span>
|
||||
</div>
|
||||
<div class="summary-item summary-ambiguous">
|
||||
<span class="summary-num">{{ ambiguousCount }}</span>
|
||||
<span class="summary-label">待选择</span>
|
||||
</div>
|
||||
<div class="summary-item summary-notfound">
|
||||
<span class="summary-num">{{ notFoundCount }}</span>
|
||||
<span class="summary-label">未找到</span>
|
||||
</div>
|
||||
<div class="summary-item summary-total">
|
||||
<span class="summary-num">{{ importTableData.length }}</span>
|
||||
<span class="summary-label">总计</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据预览表格 -->
|
||||
<div v-if="importTableData.length > 0" class="data-preview">
|
||||
<el-table ref="importTable" :data="importTableData" border size="small" max-height="340" stripe
|
||||
:row-class-name="importTableRowClassName">
|
||||
<el-table-column label="#" width="48" type="index" align="center" />
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" width="140" />
|
||||
<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" />
|
||||
<el-table-column prop="p" label="P(%)" width="70" align="center" />
|
||||
<el-table-column prop="s" label="S(%)" width="70" align="center" />
|
||||
<el-table-column prop="als" label="Als(%)" width="70" align="center" />
|
||||
<el-table-column label="匹配结果" width="130" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row._status === 'matched'" type="success" size="mini" effect="plain">已匹配</el-tag>
|
||||
<el-tag v-else-if="scope.row._status === 'ambiguous'" type="warning" size="mini" effect="plain" class="tag-clickable" @click="importOpenCandidateDialog(scope.$index)">
|
||||
<i class="el-icon-question" /> 需选择
|
||||
</el-tag>
|
||||
<el-tag v-else-if="scope.row._status === 'not_found'" type="danger" size="mini" effect="plain">未找到</el-tag>
|
||||
<el-tag v-else type="info" size="mini" effect="plain">待处理</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="90" align="center" fixed="right" v-if="importStatus === 'matched'">
|
||||
<template slot-scope="scope">
|
||||
<el-button v-if="scope.row._status === 'ambiguous'" type="warning" size="mini" plain @click="importOpenCandidateDialog(scope.$index)">选择钢卷</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<!-- 导入进度 -->
|
||||
<div v-if="importStatus === 'processing'" class="import-progress">
|
||||
<div class="progress-header">
|
||||
<i class="el-icon-loading" />
|
||||
<span>正在批量导入数据,请稍候...</span>
|
||||
</div>
|
||||
<el-progress :percentage="importProgress" :stroke-width="8" />
|
||||
</div>
|
||||
|
||||
<!-- 完成提示 -->
|
||||
<div v-if="importStatus === 'finished'" class="result-panel result-success">
|
||||
<div class="result-icon"><i class="el-icon-circle-check" /></div>
|
||||
<div class="result-body">
|
||||
<div class="result-title">导入完成</div>
|
||||
<div class="result-desc">共成功导入 <b>{{ importImportedCount }}</b> 条化学成分数据</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<div v-if="importStatus === 'error'" class="result-panel result-error">
|
||||
<div class="result-icon"><i class="el-icon-circle-close" /></div>
|
||||
<div class="result-body">
|
||||
<div class="result-title">导入失败</div>
|
||||
<div class="result-desc">{{ importErrorMsg }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 未找到的提示 -->
|
||||
<div v-if="importErrorList.length > 0 && importStatus !== 'error'" class="result-panel result-error">
|
||||
<div class="result-icon"><i class="el-icon-warning-outline" /></div>
|
||||
<div class="result-body">
|
||||
<div class="result-title">{{ importErrorList.length }} 条记录未找到对应钢卷</div>
|
||||
<div class="result-desc">这些记录将在导入时被跳过,请检查钢卷号是否正确</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 钢卷选择对话框(多匹配时) -->
|
||||
<el-dialog title="选择钢卷" :visible.sync="candidateDialogVisible" width="700px" top="20vh" append-to-body>
|
||||
<div class="candidate-hint">
|
||||
<i class="el-icon-info" />
|
||||
当前钢卷号 <b>{{ candidateCoilNo }}</b> 匹配到多条记录,请选择一条:
|
||||
</div>
|
||||
<el-table ref="candidateTable" :data="candidateList" border height="300" highlight-current-row @row-click="importSelectCandidate">
|
||||
<el-table-column type="index" label="#" width="48" align="center" />
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" width="140" />
|
||||
<el-table-column prop="material" label="材质" width="100" />
|
||||
<el-table-column prop="specification" label="规格" width="120" />
|
||||
<el-table-column prop="netWeight" label="重量(t)" width="100" align="center" />
|
||||
<el-table-column prop="warehouseName" label="库区" />
|
||||
</el-table>
|
||||
<div class="candidate-footer">点击行即可选中</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as XLSX from 'xlsx';
|
||||
import { listChemicalItem, getChemicalItem, delChemicalItem, addChemicalItem, updateChemicalItem, batchAddChemicalItem } from "@/api/mes/qc/chemicalItem";
|
||||
import { listMaterialCoil } from "@/api/wms/coil";
|
||||
import CoilSelector from "@/components/CoilSelector";
|
||||
|
||||
const CHEMI_TEMPLATE_HEADERS = ['当前钢卷号', 'C(%)', 'Si(%)', 'Mn(%)', 'P(%)', 'S(%)', 'Als(%)'];
|
||||
|
||||
const CHEMI_HEADER_MAP = {
|
||||
'当前钢卷号': 'currentCoilNo',
|
||||
'C(%)': 'c',
|
||||
'Si(%)': 'si',
|
||||
'Mn(%)': 'mn',
|
||||
'P(%)': 'p',
|
||||
'S(%)': 's',
|
||||
'Als(%)': 'als'
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "ChemicalItem",
|
||||
components: {
|
||||
CoilSelector
|
||||
},
|
||||
computed: {
|
||||
matchedCount() { return this.importTableData.filter(r => r._status === 'matched').length; },
|
||||
ambiguousCount() { return this.importTableData.filter(r => r._status === 'ambiguous').length; },
|
||||
notFoundCount() { return this.importTableData.filter(r => r._status === 'not_found').length; }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 按钮loading
|
||||
@@ -202,7 +391,24 @@ export default {
|
||||
coilNo: [
|
||||
{ required: true, message: "钢卷号不能为空", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
},
|
||||
importDialogVisible: false,
|
||||
importFile: null,
|
||||
importRawData: [],
|
||||
importTableData: [],
|
||||
importErrorList: [],
|
||||
importProgress: 0,
|
||||
importImportedCount: 0,
|
||||
importTotalCount: 0,
|
||||
importStatus: 'idle', // idle | validated | matched | processing | finished | error
|
||||
importErrorMsg: '',
|
||||
importValidateLoading: false,
|
||||
importMatchingLoading: false,
|
||||
importLoading: false,
|
||||
candidateDialogVisible: false,
|
||||
candidateRowIndex: -1,
|
||||
candidateCoilNo: '',
|
||||
candidateList: []
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@@ -287,6 +493,203 @@ export default {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
openImportDialog() {
|
||||
this.importDialogVisible = true;
|
||||
},
|
||||
importHandleFileChange(file) {
|
||||
if (this.importValidateLoading || this.importMatchingLoading || this.importLoading) return;
|
||||
this.importFile = file.raw;
|
||||
this.importErrorList = [];
|
||||
this.importStatus = 'idle';
|
||||
this.importReadExcel();
|
||||
},
|
||||
async importReadExcel() {
|
||||
if (!this.importFile) return;
|
||||
try {
|
||||
const reader = new FileReader();
|
||||
reader.readAsArrayBuffer(this.importFile);
|
||||
reader.onload = async (e) => {
|
||||
try {
|
||||
const data = new Uint8Array(e.target.result);
|
||||
const wb = XLSX.read(data, { type: 'array' });
|
||||
const ws = wb.Sheets[wb.SheetNames[0]];
|
||||
const json = XLSX.utils.sheet_to_json(ws, { header: 1 });
|
||||
this.importValidateHeaders(json[0]);
|
||||
this.importRawData = json.slice(1).filter(r => r.some(c => c != null && c !== ''));
|
||||
this.importFormatExcel();
|
||||
this.$message.success(`成功解析Excel,共读取到 ${this.importRawData.length} 条数据`);
|
||||
} catch (err) { this.importHandleError('解析Excel失败:' + err.message); }
|
||||
};
|
||||
} catch (err) { this.importHandleError('读取文件失败:' + err.message); }
|
||||
},
|
||||
importValidateHeaders(headers) {
|
||||
this.importErrorList = [];
|
||||
if (!headers || headers.length < CHEMI_TEMPLATE_HEADERS.length) {
|
||||
this.importErrorList.push({ rowNum: 1, errorMsg: `表头数量不匹配,要求至少${CHEMI_TEMPLATE_HEADERS.length}列` });
|
||||
return;
|
||||
}
|
||||
CHEMI_TEMPLATE_HEADERS.forEach((h, i) => {
|
||||
if (headers[i] !== h) this.importErrorList.push({ rowNum: 1, errorMsg: `第${i+1}列表头错误,要求:"${h}",实际:"${headers[i]||''}"` });
|
||||
});
|
||||
if (this.importErrorList.length > 0) this.$message.error('Excel表头格式不符合要求,请检查!');
|
||||
},
|
||||
importFormatExcel() {
|
||||
this.importTableData = [];
|
||||
if (!this.importRawData.length) return;
|
||||
this.importRawData.forEach((row, i) => {
|
||||
const obj = {};
|
||||
CHEMI_TEMPLATE_HEADERS.forEach((h, j) => { obj[CHEMI_HEADER_MAP[h]] = row[j] != null ? String(row[j]).trim() : ''; });
|
||||
obj.rowNum = i + 2;
|
||||
obj._status = 'pending';
|
||||
obj._coilId = null;
|
||||
obj._coilNo = null;
|
||||
obj._candidates = [];
|
||||
obj._errorMsg = '';
|
||||
this.importTableData.push(obj);
|
||||
});
|
||||
},
|
||||
async importHandleValidate() {
|
||||
if (!this.importFile || !this.importRawData.length) { this.$message.warning('暂无数据可校验'); return; }
|
||||
this.importValidateLoading = true;
|
||||
this.importErrorList = [];
|
||||
for (let i = 0; i < this.importRawData.length; i++) {
|
||||
const rowNum = i + 2;
|
||||
let coilNo = '';
|
||||
CHEMI_TEMPLATE_HEADERS.forEach((h, j) => { if (CHEMI_HEADER_MAP[h] === 'currentCoilNo') coilNo = this.importRawData[i][j]; });
|
||||
if (!coilNo || !String(coilNo).trim()) this.importErrorList.push({ rowNum, errorMsg: '当前钢卷号不能为空' });
|
||||
}
|
||||
if (this.importErrorList.length > 0) {
|
||||
this.$message.error(`数据校验失败,共发现${this.importErrorList.length}条错误`);
|
||||
} else {
|
||||
this.$message.success('数据校验通过');
|
||||
this.importStatus = 'validated';
|
||||
}
|
||||
this.importValidateLoading = false;
|
||||
},
|
||||
async importMatchCoils() {
|
||||
this.importMatchingLoading = true;
|
||||
this.importErrorList = [];
|
||||
for (let i = 0; i < this.importTableData.length; i++) {
|
||||
const row = this.importTableData[i];
|
||||
const coilNo = row.currentCoilNo;
|
||||
if (!coilNo) { row._status = 'not_found'; row._errorMsg = '钢卷号为空'; continue; }
|
||||
try {
|
||||
const res = await listMaterialCoil({ currentCoilNo: coilNo, dataType: 1, pageSize: 999 });
|
||||
const coils = res.rows || [];
|
||||
if (coils.length === 0) {
|
||||
row._status = 'not_found';
|
||||
row._errorMsg = `未找到钢卷号"${coilNo}"`;
|
||||
} else if (coils.length === 1) {
|
||||
row._status = 'matched';
|
||||
row._coilId = coils[0].coilId;
|
||||
row._coilNo = coils[0].currentCoilNo;
|
||||
} else {
|
||||
row._status = 'ambiguous';
|
||||
row._candidates = coils;
|
||||
}
|
||||
} catch (err) {
|
||||
row._status = 'not_found';
|
||||
row._errorMsg = err.message;
|
||||
}
|
||||
}
|
||||
const notFound = this.importTableData.filter(r => r._status === 'not_found');
|
||||
if (notFound.length > 0) {
|
||||
this.importErrorList = notFound.map(r => ({ rowNum: r.rowNum, errorMsg: r._errorMsg }));
|
||||
this.$message.warning(`${notFound.length} 条记录未找到对应钢卷,已被剔除`);
|
||||
}
|
||||
this.importMatchingLoading = false;
|
||||
this.importStatus = 'matched';
|
||||
},
|
||||
importOpenCandidateDialog(index) {
|
||||
const row = this.importTableData[index];
|
||||
if (!row || row._status !== 'ambiguous') return;
|
||||
this.candidateRowIndex = index;
|
||||
this.candidateCoilNo = row.currentCoilNo;
|
||||
this.candidateList = row._candidates;
|
||||
this.candidateDialogVisible = true;
|
||||
},
|
||||
importSelectCandidate(coil) {
|
||||
if (this.candidateRowIndex < 0) return;
|
||||
const row = this.importTableData[this.candidateRowIndex];
|
||||
row._status = 'matched';
|
||||
row._coilId = coil.coilId;
|
||||
row._coilNo = coil.currentCoilNo;
|
||||
row._candidates = [];
|
||||
this.candidateDialogVisible = false;
|
||||
this.candidateRowIndex = -1;
|
||||
this.candidateList = [];
|
||||
this.$message.success(`已为第 ${row.rowNum} 行选择钢卷:${coil.currentCoilNo}`);
|
||||
},
|
||||
async importStartImport() {
|
||||
const rows = this.importTableData.filter(r => r._status === 'matched');
|
||||
if (!rows.length) { this.$message.warning('没有可导入的数据'); return; }
|
||||
const skipped = this.importTableData.length - rows.length;
|
||||
const ok = await this.$confirm(`确认导入 ${rows.length} 条数据?${skipped ? `(${skipped} 条未匹配的记录将被跳过)` : ''}`, '导入确认', { confirmButtonText: '确认导入', cancelButtonText: '取消', type: 'warning' }).catch(() => false);
|
||||
if (!ok) return;
|
||||
this.importLoading = true;
|
||||
this.importStatus = 'processing';
|
||||
this.importProgress = 0;
|
||||
this.importTotalCount = rows.length;
|
||||
this.importErrorMsg = '';
|
||||
try {
|
||||
const payload = rows.map(row => {
|
||||
const item = { coilId: row._coilId, coilNo: row._coilNo };
|
||||
['c','si','mn','p','s','als'].forEach(f => { if (row[f]) item[f] = row[f]; });
|
||||
return item;
|
||||
});
|
||||
const addRes = await batchAddChemicalItem(payload);
|
||||
if (addRes.code !== 200) throw new Error(addRes.msg || '批量导入失败');
|
||||
this.importStatus = 'finished';
|
||||
this.importImportedCount = payload.length;
|
||||
this.importProgress = 100;
|
||||
this.$message.success(`导入完成!共成功导入${payload.length}条数据`);
|
||||
this.getList();
|
||||
} catch (err) {
|
||||
this.importHandleError(err.message);
|
||||
} finally {
|
||||
this.importLoading = false;
|
||||
}
|
||||
},
|
||||
importReset() {
|
||||
if (this.importValidateLoading || this.importMatchingLoading || this.importLoading || this.importStatus === 'processing') { this.$message.warning('当前有操作正在进行中'); return; }
|
||||
this.importFile = null;
|
||||
this.importRawData = [];
|
||||
this.importTableData = [];
|
||||
this.importErrorList = [];
|
||||
this.importProgress = 0;
|
||||
this.importImportedCount = 0;
|
||||
this.importTotalCount = 0;
|
||||
this.importStatus = 'idle';
|
||||
this.importErrorMsg = '';
|
||||
this.candidateDialogVisible = false;
|
||||
this.candidateRowIndex = -1;
|
||||
this.candidateCoilNo = '';
|
||||
this.candidateList = [];
|
||||
this.$refs.importUpload?.clearFiles();
|
||||
},
|
||||
importDownloadTemplate() {
|
||||
const data = [CHEMI_TEMPLATE_HEADERS, ['示例卷号', '0.05', '0.02', '0.30', '0.015', '0.008', '0.040']];
|
||||
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 }];
|
||||
XLSX.utils.book_append_sheet(wb, ws, '导入模板');
|
||||
XLSX.writeFile(wb, '化学成分导入模板.xlsx');
|
||||
},
|
||||
importHandleError(msg) {
|
||||
this.$message.error(msg);
|
||||
this.importStatus = 'error';
|
||||
this.importErrorMsg = msg;
|
||||
this.importValidateLoading = false;
|
||||
this.importMatchingLoading = false;
|
||||
this.importLoading = false;
|
||||
},
|
||||
importTableRowClassName({ row }) {
|
||||
if (row._status === 'ambiguous') return 'row-ambiguous';
|
||||
if (row._status === 'not_found') return 'row-notfound';
|
||||
if (row._status === 'matched') return 'row-matched';
|
||||
return '';
|
||||
},
|
||||
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.loading = true;
|
||||
@@ -348,3 +751,227 @@ export default {
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.import-container {
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.import-steps {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 24px;
|
||||
padding: 20px 0 16px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.step {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
opacity: 0.45;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.step.active { opacity: 1; }
|
||||
.step.done { opacity: 0.65; }
|
||||
|
||||
.step-badge {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
background: #dcdfe6;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.step.active .step-badge {
|
||||
background: #409eff;
|
||||
box-shadow: 0 2px 8px rgba(64,158,255,0.35);
|
||||
}
|
||||
|
||||
.step.done .step-badge {
|
||||
background: #67c23a;
|
||||
}
|
||||
|
||||
.step-badge-warn { background: #e6a23c !important; }
|
||||
.step.active .step-badge-warn { background: #e6a23c !important; box-shadow: 0 2px 8px rgba(230,162,60,0.35) !important; }
|
||||
.step-badge-success { background: #67c23a !important; }
|
||||
.step.active .step-badge-success { background: #67c23a !important; box-shadow: 0 2px 8px rgba(103,194,58,0.35) !important; }
|
||||
|
||||
.step-label {
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.step.active .step-label { color: #303133; font-weight: 600; }
|
||||
|
||||
.step-connector {
|
||||
width: 48px;
|
||||
height: 2px;
|
||||
background: #dcdfe6;
|
||||
margin: 0 4px;
|
||||
margin-bottom: 24px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.step-connector.done { background: #67c23a; }
|
||||
|
||||
.import-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px 16px;
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
|
||||
.toolbar-left, .toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.match-summary {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.summary-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 14px 8px;
|
||||
border-radius: 8px;
|
||||
background: #fafafa;
|
||||
border: 1px solid #eee;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.summary-matched { border-color: #b7eb8f; background: #f6ffed; }
|
||||
.summary-ambiguous { border-color: #ffe58f; background: #fffbe6; }
|
||||
.summary-notfound { border-color: #ffa39e; background: #fff2f0; }
|
||||
.summary-total { border-color: #d9d9d9; background: #fafafa; }
|
||||
|
||||
.summary-num {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.summary-matched .summary-num { color: #52c41a; }
|
||||
.summary-ambiguous .summary-num { color: #faad14; }
|
||||
.summary-notfound .summary-num { color: #ff4d4f; }
|
||||
.summary-total .summary-num { color: #409eff; }
|
||||
|
||||
.summary-label {
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.data-preview {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
::v-deep .tag-clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
::v-deep .tag-clickable:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.import-progress {
|
||||
padding: 24px;
|
||||
background: #f6ffed;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #b7eb8f;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.progress-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
color: #52c41a;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.result-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 20px 24px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.result-success {
|
||||
background: #f6ffed;
|
||||
border: 1px solid #b7eb8f;
|
||||
}
|
||||
|
||||
.result-error {
|
||||
background: #fff2f0;
|
||||
border: 1px solid #ffa39e;
|
||||
}
|
||||
|
||||
.result-icon {
|
||||
font-size: 36px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.result-success .result-icon { color: #52c41a; }
|
||||
.result-error .result-icon { color: #ff4d4f; }
|
||||
|
||||
.result-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.result-success .result-title { color: #389e0d; }
|
||||
.result-error .result-title { color: #cf1322; }
|
||||
|
||||
.result-desc {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.candidate-hint {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 14px;
|
||||
background: #fffbe6;
|
||||
border: 1px solid #ffe58f;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: #ad6800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.candidate-footer {
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -87,6 +87,15 @@
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini">批量新增</el-button>
|
||||
</coil-selector>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="el-icon-upload2"
|
||||
size="mini"
|
||||
@click="openImportDialog"
|
||||
>导入</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
@@ -198,18 +207,205 @@
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 导入对话框 -->
|
||||
<el-dialog title="导入物理性能" :visible.sync="importDialogVisible" width="1100px" top="5vh" append-to-body>
|
||||
<div class="import-container">
|
||||
|
||||
<!-- 步骤条 -->
|
||||
<div class="import-steps">
|
||||
<div class="step" :class="{ active: true, done: importStatus !== 'idle' && importStatus !== 'validated' }">
|
||||
<div class="step-badge">1</div>
|
||||
<div class="step-label">下载模板</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus !== 'idle' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'validated' || importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished', done: importStatus !== 'idle' && importStatus !== 'validated' }">
|
||||
<div class="step-badge">2</div>
|
||||
<div class="step-label">上传文件</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished', done: importStatus === 'processing' || importStatus === 'finished' }">
|
||||
<div class="step-badge">3</div>
|
||||
<div class="step-label">校验数据</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus === 'processing' || importStatus === 'finished' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'matched' || importStatus === 'processing' || importStatus === 'finished', done: importStatus === 'finished' }">
|
||||
<div class="step-badge step-badge-warn">4</div>
|
||||
<div class="step-label">匹配钢卷</div>
|
||||
</div>
|
||||
<div class="step-connector" :class="{ done: importStatus === 'finished' }" />
|
||||
<div class="step" :class="{ active: importStatus === 'processing' || importStatus === 'finished', done: importStatus === 'finished' }">
|
||||
<div class="step-badge step-badge-success">5</div>
|
||||
<div class="step-label">批量导入</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="import-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<el-upload ref="importUpload" action="" :auto-upload="false" :show-file-list="false"
|
||||
:on-change="importHandleFileChange" accept=".xlsx,.xls"
|
||||
:disabled="importStatus !== 'idle' && importStatus !== 'validated'">
|
||||
<el-button :type="importFile ? 'default' : 'primary'" :icon="importFile ? 'el-icon-document' : 'el-icon-upload2'">
|
||||
{{ importFile ? importFile.name : '选择Excel文件' }}
|
||||
</el-button>
|
||||
</el-upload>
|
||||
<el-button type="success" plain icon="el-icon-check" @click="importHandleValidate"
|
||||
:disabled="!importFile || importValidateLoading || importStatus !== 'idle'" :loading="importValidateLoading">校验数据</el-button>
|
||||
<el-button type="warning" plain icon="el-icon-coordinate" @click="importMatchCoils"
|
||||
v-if="importStatus === 'validated'" :loading="importMatchingLoading"
|
||||
:disabled="importMatchingLoading || importErrorList.length > 0">匹配钢卷</el-button>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<el-button v-if="importStatus === 'matched'" type="primary" icon="el-icon-upload-success" @click="importStartImport" :loading="importLoading">开始导入</el-button>
|
||||
<el-button plain icon="el-icon-download" @click="importDownloadTemplate">下载模板</el-button>
|
||||
<el-button plain icon="el-icon-refresh" @click="importReset">重置</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 匹配结果摘要 -->
|
||||
<div v-if="importStatus === 'matched'" class="match-summary">
|
||||
<div class="summary-item summary-matched">
|
||||
<span class="summary-num">{{ matchedCount }}</span>
|
||||
<span class="summary-label">已匹配</span>
|
||||
</div>
|
||||
<div class="summary-item summary-ambiguous">
|
||||
<span class="summary-num">{{ ambiguousCount }}</span>
|
||||
<span class="summary-label">待选择</span>
|
||||
</div>
|
||||
<div class="summary-item summary-notfound">
|
||||
<span class="summary-num">{{ notFoundCount }}</span>
|
||||
<span class="summary-label">未找到</span>
|
||||
</div>
|
||||
<div class="summary-item summary-total">
|
||||
<span class="summary-num">{{ importTableData.length }}</span>
|
||||
<span class="summary-label">总计</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据预览表格 -->
|
||||
<div v-if="importTableData.length > 0" class="data-preview">
|
||||
<el-table ref="importTable" :data="importTableData" border size="small" max-height="340" stripe
|
||||
:row-class-name="importTableRowClassName">
|
||||
<el-table-column label="#" width="48" type="index" align="center" />
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" width="140" />
|
||||
<el-table-column prop="yieldStrength" label="屈服强度(MPa)" width="110" align="center" />
|
||||
<el-table-column prop="tensileStrength" label="抗拉强度(MPa)" width="110" align="center" />
|
||||
<el-table-column prop="elongation" label="伸长率(%)" width="80" align="center" />
|
||||
<el-table-column prop="hardness" label="硬度(HRB)" width="80" align="center" />
|
||||
<el-table-column prop="bendingTest" label="弯曲试验" width="80" align="center" />
|
||||
<el-table-column prop="surfaceQuality" label="表面质量" width="80" align="center" />
|
||||
<el-table-column prop="surfaceStructure" label="表面结构" width="80" align="center" />
|
||||
<el-table-column prop="edgeStatus" label="边缘状态" width="80" align="center" />
|
||||
<el-table-column label="匹配结果" width="130" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row._status === 'matched'" type="success" size="mini" effect="plain">已匹配</el-tag>
|
||||
<el-tag v-else-if="scope.row._status === 'ambiguous'" type="warning" size="mini" effect="plain" class="tag-clickable" @click="importOpenCandidateDialog(scope.$index)">
|
||||
<i class="el-icon-question" /> 需选择
|
||||
</el-tag>
|
||||
<el-tag v-else-if="scope.row._status === 'not_found'" type="danger" size="mini" effect="plain">未找到</el-tag>
|
||||
<el-tag v-else type="info" size="mini" effect="plain">待处理</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="90" align="center" fixed="right" v-if="importStatus === 'matched'">
|
||||
<template slot-scope="scope">
|
||||
<el-button v-if="scope.row._status === 'ambiguous'" type="warning" size="mini" plain @click="importOpenCandidateDialog(scope.$index)">选择钢卷</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<!-- 导入进度 -->
|
||||
<div v-if="importStatus === 'processing'" class="import-progress">
|
||||
<div class="progress-header">
|
||||
<i class="el-icon-loading" />
|
||||
<span>正在批量导入数据,请稍候...</span>
|
||||
</div>
|
||||
<el-progress :percentage="importProgress" :stroke-width="8" />
|
||||
</div>
|
||||
|
||||
<!-- 完成提示 -->
|
||||
<div v-if="importStatus === 'finished'" class="result-panel result-success">
|
||||
<div class="result-icon"><i class="el-icon-circle-check" /></div>
|
||||
<div class="result-body">
|
||||
<div class="result-title">导入完成</div>
|
||||
<div class="result-desc">共成功导入 <b>{{ importImportedCount }}</b> 条物理性能数据</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<div v-if="importStatus === 'error'" class="result-panel result-error">
|
||||
<div class="result-icon"><i class="el-icon-circle-close" /></div>
|
||||
<div class="result-body">
|
||||
<div class="result-title">导入失败</div>
|
||||
<div class="result-desc">{{ importErrorMsg }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 未找到的提示 -->
|
||||
<div v-if="importErrorList.length > 0 && importStatus !== 'error'" class="result-panel result-error">
|
||||
<div class="result-icon"><i class="el-icon-warning-outline" /></div>
|
||||
<div class="result-body">
|
||||
<div class="result-title">{{ importErrorList.length }} 条记录未找到对应钢卷</div>
|
||||
<div class="result-desc">这些记录将在导入时被跳过,请检查钢卷号是否正确</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 钢卷选择对话框(多匹配时) -->
|
||||
<el-dialog title="选择钢卷" :visible.sync="candidateDialogVisible" width="700px" top="20vh" append-to-body>
|
||||
<div class="candidate-hint">
|
||||
<i class="el-icon-info" />
|
||||
当前钢卷号 <b>{{ candidateCoilNo }}</b> 匹配到多条记录,请选择一条:
|
||||
</div>
|
||||
<el-table ref="candidateTable" :data="candidateList" border height="300" highlight-current-row @row-click="importSelectCandidate">
|
||||
<el-table-column type="index" label="#" width="48" align="center" />
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" width="140" />
|
||||
<el-table-column prop="material" label="材质" width="100" />
|
||||
<el-table-column prop="specification" label="规格" width="120" />
|
||||
<el-table-column prop="netWeight" label="重量(t)" width="100" align="center" />
|
||||
<el-table-column prop="warehouseName" label="库区" />
|
||||
</el-table>
|
||||
<div class="candidate-footer">点击行即可选中</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as XLSX from 'xlsx';
|
||||
import { listPhysicalItem, getPhysicalItem, delPhysicalItem, addPhysicalItem, updatePhysicalItem, batchAddPhysicalItem } from "@/api/mes/qc/physicalItem";
|
||||
import { listMaterialCoil } from "@/api/wms/coil";
|
||||
import CoilSelector from "@/components/CoilSelector";
|
||||
|
||||
const PHYS_TEMPLATE_HEADERS = [
|
||||
'当前钢卷号', '屈服强度(MPa)', '抗拉强度(MPa)', '伸长率(%)', '硬度(HRB)', '弯曲试验',
|
||||
'表面质量', '表面结构', '边缘状态'
|
||||
];
|
||||
|
||||
const PHYS_HEADER_MAP = {
|
||||
'当前钢卷号': 'currentCoilNo',
|
||||
'屈服强度(MPa)': 'yieldStrength',
|
||||
'抗拉强度(MPa)': 'tensileStrength',
|
||||
'伸长率(%)': 'elongation',
|
||||
'硬度(HRB)': 'hardness',
|
||||
'弯曲试验': 'bendingTest',
|
||||
'表面质量': 'surfaceQuality',
|
||||
'表面结构': 'surfaceStructure',
|
||||
'边缘状态': 'edgeStatus'
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "PhysicalItem",
|
||||
components: {
|
||||
CoilSelector
|
||||
},
|
||||
computed: {
|
||||
matchedCount() { return this.importTableData.filter(r => r._status === 'matched').length; },
|
||||
ambiguousCount() { return this.importTableData.filter(r => r._status === 'ambiguous').length; },
|
||||
notFoundCount() { return this.importTableData.filter(r => r._status === 'not_found').length; }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 按钮loading
|
||||
@@ -253,7 +449,24 @@ export default {
|
||||
coilNo: [
|
||||
{ required: true, message: "钢卷号不能为空", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
},
|
||||
importDialogVisible: false,
|
||||
importFile: null,
|
||||
importRawData: [],
|
||||
importTableData: [],
|
||||
importErrorList: [],
|
||||
importProgress: 0,
|
||||
importImportedCount: 0,
|
||||
importTotalCount: 0,
|
||||
importStatus: 'idle', // idle | validated | matched | processing | finished | error
|
||||
importErrorMsg: '',
|
||||
importValidateLoading: false,
|
||||
importMatchingLoading: false,
|
||||
importLoading: false,
|
||||
candidateDialogVisible: false,
|
||||
candidateRowIndex: -1,
|
||||
candidateCoilNo: '',
|
||||
candidateList: []
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@@ -339,6 +552,202 @@ export default {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
openImportDialog() {
|
||||
this.importDialogVisible = true;
|
||||
},
|
||||
importHandleFileChange(file) {
|
||||
if (this.importValidateLoading || this.importMatchingLoading || this.importLoading) return;
|
||||
this.importFile = file.raw;
|
||||
this.importErrorList = [];
|
||||
this.importStatus = 'idle';
|
||||
this.importReadExcel();
|
||||
},
|
||||
async importReadExcel() {
|
||||
if (!this.importFile) return;
|
||||
try {
|
||||
const reader = new FileReader();
|
||||
reader.readAsArrayBuffer(this.importFile);
|
||||
reader.onload = async (e) => {
|
||||
try {
|
||||
const data = new Uint8Array(e.target.result);
|
||||
const wb = XLSX.read(data, { type: 'array' });
|
||||
const ws = wb.Sheets[wb.SheetNames[0]];
|
||||
const json = XLSX.utils.sheet_to_json(ws, { header: 1 });
|
||||
this.importValidateHeaders(json[0]);
|
||||
this.importRawData = json.slice(1).filter(r => r.some(c => c != null && c !== ''));
|
||||
this.importFormatExcel();
|
||||
this.$message.success(`成功解析Excel,共读取到 ${this.importRawData.length} 条数据`);
|
||||
} catch (err) { this.importHandleError('解析Excel失败:' + err.message); }
|
||||
};
|
||||
} catch (err) { this.importHandleError('读取文件失败:' + err.message); }
|
||||
},
|
||||
importValidateHeaders(headers) {
|
||||
this.importErrorList = [];
|
||||
if (!headers || headers.length < PHYS_TEMPLATE_HEADERS.length) {
|
||||
this.importErrorList.push({ rowNum: 1, errorMsg: `表头数量不匹配,要求至少${PHYS_TEMPLATE_HEADERS.length}列` });
|
||||
return;
|
||||
}
|
||||
PHYS_TEMPLATE_HEADERS.forEach((h, i) => {
|
||||
if (headers[i] !== h) this.importErrorList.push({ rowNum: 1, errorMsg: `第${i+1}列表头错误,要求:"${h}",实际:"${headers[i]||''}"` });
|
||||
});
|
||||
if (this.importErrorList.length > 0) this.$message.error('Excel表头格式不符合要求,请检查!');
|
||||
},
|
||||
importFormatExcel() {
|
||||
this.importTableData = [];
|
||||
if (!this.importRawData.length) return;
|
||||
this.importRawData.forEach((row, i) => {
|
||||
const obj = {};
|
||||
PHYS_TEMPLATE_HEADERS.forEach((h, j) => { obj[PHYS_HEADER_MAP[h]] = row[j] != null ? String(row[j]).trim() : ''; });
|
||||
obj.rowNum = i + 2;
|
||||
obj._status = 'pending';
|
||||
obj._coilId = null;
|
||||
obj._coilNo = null;
|
||||
obj._candidates = [];
|
||||
obj._errorMsg = '';
|
||||
this.importTableData.push(obj);
|
||||
});
|
||||
},
|
||||
async importHandleValidate() {
|
||||
if (!this.importFile || !this.importRawData.length) { this.$message.warning('暂无数据可校验'); return; }
|
||||
this.importValidateLoading = true;
|
||||
this.importErrorList = [];
|
||||
for (let i = 0; i < this.importRawData.length; i++) {
|
||||
const rowNum = i + 2;
|
||||
let coilNo = '';
|
||||
PHYS_TEMPLATE_HEADERS.forEach((h, j) => { if (PHYS_HEADER_MAP[h] === 'currentCoilNo') coilNo = this.importRawData[i][j]; });
|
||||
if (!coilNo || !String(coilNo).trim()) this.importErrorList.push({ rowNum, errorMsg: '当前钢卷号不能为空' });
|
||||
}
|
||||
if (this.importErrorList.length > 0) {
|
||||
this.$message.error(`数据校验失败,共发现${this.importErrorList.length}条错误`);
|
||||
} else {
|
||||
this.$message.success('数据校验通过');
|
||||
this.importStatus = 'validated';
|
||||
}
|
||||
this.importValidateLoading = false;
|
||||
},
|
||||
async importMatchCoils() {
|
||||
this.importMatchingLoading = true;
|
||||
this.importErrorList = [];
|
||||
for (let i = 0; i < this.importTableData.length; i++) {
|
||||
const row = this.importTableData[i];
|
||||
const coilNo = row.currentCoilNo;
|
||||
if (!coilNo) { row._status = 'not_found'; row._errorMsg = '钢卷号为空'; continue; }
|
||||
try {
|
||||
const res = await listMaterialCoil({ currentCoilNo: coilNo, dataType: 1, pageSize: 999 });
|
||||
const coils = res.rows || [];
|
||||
if (coils.length === 0) {
|
||||
row._status = 'not_found';
|
||||
row._errorMsg = `未找到钢卷号"${coilNo}"`;
|
||||
} else if (coils.length === 1) {
|
||||
row._status = 'matched';
|
||||
row._coilId = coils[0].coilId;
|
||||
row._coilNo = coils[0].currentCoilNo;
|
||||
} else {
|
||||
row._status = 'ambiguous';
|
||||
row._candidates = coils;
|
||||
}
|
||||
} catch (err) {
|
||||
row._status = 'not_found';
|
||||
row._errorMsg = err.message;
|
||||
}
|
||||
}
|
||||
const notFound = this.importTableData.filter(r => r._status === 'not_found');
|
||||
if (notFound.length > 0) {
|
||||
this.importErrorList = notFound.map(r => ({ rowNum: r.rowNum, errorMsg: r._errorMsg }));
|
||||
this.$message.warning(`${notFound.length} 条记录未找到对应钢卷,已被剔除`);
|
||||
}
|
||||
this.importMatchingLoading = false;
|
||||
this.importStatus = 'matched';
|
||||
},
|
||||
importOpenCandidateDialog(index) {
|
||||
const row = this.importTableData[index];
|
||||
if (!row || row._status !== 'ambiguous') return;
|
||||
this.candidateRowIndex = index;
|
||||
this.candidateCoilNo = row.currentCoilNo;
|
||||
this.candidateList = row._candidates;
|
||||
this.candidateDialogVisible = true;
|
||||
},
|
||||
importSelectCandidate(coil) {
|
||||
if (this.candidateRowIndex < 0) return;
|
||||
const row = this.importTableData[this.candidateRowIndex];
|
||||
row._status = 'matched';
|
||||
row._coilId = coil.coilId;
|
||||
row._coilNo = coil.currentCoilNo;
|
||||
row._candidates = [];
|
||||
this.candidateDialogVisible = false;
|
||||
this.candidateRowIndex = -1;
|
||||
this.candidateList = [];
|
||||
this.$message.success(`已为第 ${row.rowNum} 行选择钢卷:${coil.currentCoilNo}`);
|
||||
},
|
||||
async importStartImport() {
|
||||
const rows = this.importTableData.filter(r => r._status === 'matched');
|
||||
if (!rows.length) { this.$message.warning('没有可导入的数据'); return; }
|
||||
const skipped = this.importTableData.length - rows.length;
|
||||
const ok = await this.$confirm(`确认导入 ${rows.length} 条数据?${skipped ? `(${skipped} 条未匹配的记录将被跳过)` : ''}`, '导入确认', { confirmButtonText: '确认导入', cancelButtonText: '取消', type: 'warning' }).catch(() => false);
|
||||
if (!ok) return;
|
||||
this.importLoading = true;
|
||||
this.importStatus = 'processing';
|
||||
this.importProgress = 0;
|
||||
this.importTotalCount = rows.length;
|
||||
this.importErrorMsg = '';
|
||||
try {
|
||||
const payload = rows.map(row => {
|
||||
const item = { coilId: row._coilId, coilNo: row._coilNo };
|
||||
['yieldStrength','tensileStrength','elongation','hardness','bendingTest','surfaceQuality','surfaceStructure','edgeStatus'].forEach(f => { if (row[f]) item[f] = row[f]; });
|
||||
return item;
|
||||
});
|
||||
const addRes = await batchAddPhysicalItem(payload);
|
||||
if (addRes.code !== 200) throw new Error(addRes.msg || '批量导入失败');
|
||||
this.importStatus = 'finished';
|
||||
this.importImportedCount = payload.length;
|
||||
this.importProgress = 100;
|
||||
this.$message.success(`导入完成!共成功导入${payload.length}条数据`);
|
||||
this.getList();
|
||||
} catch (err) {
|
||||
this.importHandleError(err.message);
|
||||
} finally {
|
||||
this.importLoading = false;
|
||||
}
|
||||
},
|
||||
importReset() {
|
||||
if (this.importValidateLoading || this.importMatchingLoading || this.importLoading || this.importStatus === 'processing') { this.$message.warning('当前有操作正在进行中'); return; }
|
||||
this.importFile = null;
|
||||
this.importRawData = [];
|
||||
this.importTableData = [];
|
||||
this.importErrorList = [];
|
||||
this.importProgress = 0;
|
||||
this.importImportedCount = 0;
|
||||
this.importTotalCount = 0;
|
||||
this.importStatus = 'idle';
|
||||
this.importErrorMsg = '';
|
||||
this.candidateDialogVisible = false;
|
||||
this.candidateRowIndex = -1;
|
||||
this.candidateCoilNo = '';
|
||||
this.candidateList = [];
|
||||
this.$refs.importUpload?.clearFiles();
|
||||
},
|
||||
importDownloadTemplate() {
|
||||
const data = [PHYS_TEMPLATE_HEADERS, ['示例卷号', '300', '420', '35', '85', '合格', '良好', '光面', '良好']];
|
||||
const wb = XLSX.utils.book_new();
|
||||
const ws = XLSX.utils.aoa_to_sheet(data);
|
||||
ws['!cols'] = [{ wch: 16 }, { wch: 16 }, { wch: 16 }, { wch: 10 }, { wch: 10 }, { wch: 10 }, { wch: 10 }, { wch: 10 }, { wch: 10 }];
|
||||
XLSX.utils.book_append_sheet(wb, ws, '导入模板');
|
||||
XLSX.writeFile(wb, '物理性能导入模板.xlsx');
|
||||
},
|
||||
importHandleError(msg) {
|
||||
this.$message.error(msg);
|
||||
this.importStatus = 'error';
|
||||
this.importErrorMsg = msg;
|
||||
this.importValidateLoading = false;
|
||||
this.importMatchingLoading = false;
|
||||
this.importLoading = false;
|
||||
},
|
||||
importTableRowClassName({ row }) {
|
||||
if (row._status === 'ambiguous') return 'row-ambiguous';
|
||||
if (row._status === 'not_found') return 'row-notfound';
|
||||
if (row._status === 'matched') return 'row-matched';
|
||||
return '';
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.loading = true;
|
||||
@@ -400,3 +809,227 @@ export default {
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.import-container {
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.import-steps {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 24px;
|
||||
padding: 20px 0 16px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.step {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
opacity: 0.45;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.step.active { opacity: 1; }
|
||||
.step.done { opacity: 0.65; }
|
||||
|
||||
.step-badge {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
background: #dcdfe6;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.step.active .step-badge {
|
||||
background: #409eff;
|
||||
box-shadow: 0 2px 8px rgba(64,158,255,0.35);
|
||||
}
|
||||
|
||||
.step.done .step-badge {
|
||||
background: #67c23a;
|
||||
}
|
||||
|
||||
.step-badge-warn { background: #e6a23c !important; }
|
||||
.step.active .step-badge-warn { background: #e6a23c !important; box-shadow: 0 2px 8px rgba(230,162,60,0.35) !important; }
|
||||
.step-badge-success { background: #67c23a !important; }
|
||||
.step.active .step-badge-success { background: #67c23a !important; box-shadow: 0 2px 8px rgba(103,194,58,0.35) !important; }
|
||||
|
||||
.step-label {
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.step.active .step-label { color: #303133; font-weight: 600; }
|
||||
|
||||
.step-connector {
|
||||
width: 48px;
|
||||
height: 2px;
|
||||
background: #dcdfe6;
|
||||
margin: 0 4px;
|
||||
margin-bottom: 24px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.step-connector.done { background: #67c23a; }
|
||||
|
||||
.import-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px 16px;
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
|
||||
.toolbar-left, .toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.match-summary {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.summary-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 14px 8px;
|
||||
border-radius: 8px;
|
||||
background: #fafafa;
|
||||
border: 1px solid #eee;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.summary-matched { border-color: #b7eb8f; background: #f6ffed; }
|
||||
.summary-ambiguous { border-color: #ffe58f; background: #fffbe6; }
|
||||
.summary-notfound { border-color: #ffa39e; background: #fff2f0; }
|
||||
.summary-total { border-color: #d9d9d9; background: #fafafa; }
|
||||
|
||||
.summary-num {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.summary-matched .summary-num { color: #52c41a; }
|
||||
.summary-ambiguous .summary-num { color: #faad14; }
|
||||
.summary-notfound .summary-num { color: #ff4d4f; }
|
||||
.summary-total .summary-num { color: #409eff; }
|
||||
|
||||
.summary-label {
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.data-preview {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
::v-deep .tag-clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
::v-deep .tag-clickable:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.import-progress {
|
||||
padding: 24px;
|
||||
background: #f6ffed;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #b7eb8f;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.progress-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
color: #52c41a;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.result-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 20px 24px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.result-success {
|
||||
background: #f6ffed;
|
||||
border: 1px solid #b7eb8f;
|
||||
}
|
||||
|
||||
.result-error {
|
||||
background: #fff2f0;
|
||||
border: 1px solid #ffa39e;
|
||||
}
|
||||
|
||||
.result-icon {
|
||||
font-size: 36px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.result-success .result-icon { color: #52c41a; }
|
||||
.result-error .result-icon { color: #ff4d4f; }
|
||||
|
||||
.result-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.result-success .result-title { color: #389e0d; }
|
||||
.result-error .result-title { color: #cf1322; }
|
||||
|
||||
.result-desc {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.candidate-hint {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 14px;
|
||||
background: #fffbe6;
|
||||
border: 1px solid #ffe58f;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: #ad6800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.candidate-footer {
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user