From bad3f985996c34de58c5005c8742f655318517c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Thu, 30 Oct 2025 15:32:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=92=A2=E5=8D=B7=E7=89=A9=E6=96=99):=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=80=89=E4=B8=AD=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加findItemWithBom工具函数用于统一获取物品名称 修改OuterTagPreview组件使用itemName替代productName 重构导出功能支持选中数据导出,并优化Excel生成逻辑 --- klp-ui/src/store/modules/category.js | 30 ++++++++ .../panels/LabelRender/OuterTagPreview.vue | 2 +- klp-ui/src/views/wms/coil/panels/base.vue | 72 ++++++++++++++++--- 3 files changed, 94 insertions(+), 10 deletions(-) diff --git a/klp-ui/src/store/modules/category.js b/klp-ui/src/store/modules/category.js index 0b03a749..83625204 100644 --- a/klp-ui/src/store/modules/category.js +++ b/klp-ui/src/store/modules/category.js @@ -94,6 +94,36 @@ const actions = { } }; +export function findItemWithBom(itemType, itemId) { + if (!itemType || !itemId) { + return null; + } + console.log('itemType', itemType, 'itemId', itemId) + let map = {} + if (itemType === 'product') { + map = state.productMap; + } else if (itemType === 'raw_material') { + map = state.rawMaterialMap; + } else { + return null; + } + console.log('map', map) + const item = map[itemId]; + const bomId = item.bomId + if (!item) { + return null; + } + console.log('bomId', bomId, item) + const bomItems = state.bomMap[bomId]; + + return { + ...item, + boms: bomItems || [], + itemName: itemType === 'product' ? item.productName : item.rawMaterialName, + itemType, + }; +} + export default { namespaced: true, state, diff --git a/klp-ui/src/views/wms/coil/panels/LabelRender/OuterTagPreview.vue b/klp-ui/src/views/wms/coil/panels/LabelRender/OuterTagPreview.vue index 4f04a20d..e5988e6e 100644 --- a/klp-ui/src/views/wms/coil/panels/LabelRender/OuterTagPreview.vue +++ b/klp-ui/src/views/wms/coil/panels/LabelRender/OuterTagPreview.vue @@ -24,7 +24,7 @@
产品名称
- +
执行标准
diff --git a/klp-ui/src/views/wms/coil/panels/base.vue b/klp-ui/src/views/wms/coil/panels/base.vue index da536bc3..e45492cd 100644 --- a/klp-ui/src/views/wms/coil/panels/base.vue +++ b/klp-ui/src/views/wms/coil/panels/base.vue @@ -129,8 +129,10 @@ - - + + @@ -164,6 +166,7 @@ import { listMaterialCoil, getMaterialCoil, delMaterialCoil, addMaterialCoil, updateMaterialCoilSimple, getMaterialCoilTrace } from "@/api/wms/coil"; import WarehouseSelect from "@/components/WarehouseSelect"; import QRCode from "../../print/components/QRCode.vue"; +import * as XLSX from 'xlsx' import { saveAsImage } from '@/utils/klp'; import ProductSelect from "@/components/KLPService/ProductSelect"; import RawMaterialSelect from "@/components/KLPService/RawMaterialSelect"; @@ -174,6 +177,7 @@ import RawMaterialInfo from "@/components/KLPService/Renderer/RawMaterialInfo"; // 引入封装的追溯结果组件 import CoilTraceResult from "./CoilTraceResult.vue"; // 路径根据实际存放位置调整 import LabelRender from './LabelRender/index.vue' +import { findItemWithBom } from "@/store/modules/category"; export default { name: "MaterialCoil", @@ -196,7 +200,7 @@ export default { }, querys: { type: Object, - default: () => {}, + default: () => { }, }, labelType: { type: String, @@ -301,7 +305,10 @@ export default { /** 预览标签 */ handlePreviewLabel(row) { this.labelRender.visible = true; - this.labelRender.data = row; + this.labelRender.data = { + ...row, + itemName: findItemWithBom(row.itemType, row.itemId)?.itemName || '', + }; }, /** 下载二维码 */ handleDownloadQRCode(row) { @@ -400,7 +407,7 @@ export default { this.title = "修改钢卷物料"; }); }, - transferCoil() {}, + transferCoil() { }, /** 提交按钮 */ submitForm() { this.$refs["form"].validate(valid => { @@ -441,11 +448,58 @@ export default { this.loading = false; }); }, - /** 导出按钮操作 */ + /** 导出选中数据操作 */ handleExport() { - this.download('wms/materialCoil/export', { - ...this.queryParams - }, `materialCoil_${new Date().getTime()}.xlsx`) + // 1. 判断是否有选中数据 + if (this.ids.length === 0) { + this.$message.warning('请先选中要导出的数据'); + return; + } + + // 2. 筛选选中的数据(通过ids匹配表格数据) + const selectedData = this.materialCoilList.filter(item => + this.ids.includes(item.coilId) // 用选中的coilId匹配表格数据 + ); + + // 3. 处理导出数据格式(和之前一致,转换枚举值) + const exportData = selectedData.map(item => { + return { + '入场钢卷号': item.enterCoilNo || '', + '当前钢卷号': item.currentCoilNo || '', + '厂家原料卷号': item.supplierCoilNo || '', + '库区': item.itemType === 'product' ? '成品' : '原料', + '仓库': item.warehouseName || '', + '物品': findItemWithBom(item.itemType, item.itemId)?.itemName || '', + '数据类型': item.dataType === 0 ? '历史数据' : '当前数据', + '班组': item.team || '', + '毛重': item.grossWeight || '', + '净重': item.netWeight || '', + '备注': item.remark || '' + }; + }); + + // 4. 生成Excel并下载(复用之前的逻辑) + const worksheet = XLSX.utils.json_to_sheet(exportData); + const workbook = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(workbook, worksheet, '选中钢卷物料'); + + const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); + this.saveExcelFile(excelBuffer, '选中钢卷物料数据'); + }, + + /** 保存Excel文件到本地 */ + saveExcelFile(buffer, fileName) { + const blob = new Blob([buffer], { + type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' + }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `${fileName}_${new Date().getTime()}.xlsx`; // 文件名带时间戳 + document.body.appendChild(a); + a.click(); // 触发下载 + document.body.removeChild(a); // 清理DOM + URL.revokeObjectURL(url); // 释放URL对象 } } };