From 89ebffaf865230c66f0e64abe8948311e9cd2d9b Mon Sep 17 00:00:00 2001 From: tzy1042411602 <1042411602@qq.com> Date: Mon, 16 Dec 2024 17:37:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E8=89=BA=E6=A8=A1=E5=9D=97=EF=BC=9A?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AE=8C=E5=85=A8=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/details.js | 5 +- src/views/system/details/index.vue | 46 +- src/views/system/orderPro/index.vue | 4 +- src/views/system/route/index.vue | 1218 ++++++++++++++++++--------- 4 files changed, 833 insertions(+), 440 deletions(-) diff --git a/src/api/system/details.js b/src/api/system/details.js index e799d99..8d98363 100644 --- a/src/api/system/details.js +++ b/src/api/system/details.js @@ -17,12 +17,11 @@ export function getDetails(id) { }) } -export function updateFBl(fnumber) { - console.log('111',fnumber) +export function updateFBl(data) { return request({ url: '/system/details/updateFBMaterial', method: 'post', - data: fnumber + data: data }) } // 获取项目令号列表 diff --git a/src/views/system/details/index.vue b/src/views/system/details/index.vue index 5ab8d7a..e145da5 100644 --- a/src/views/system/details/index.vue +++ b/src/views/system/details/index.vue @@ -18,7 +18,7 @@ @keyup.enter.native="handleQuery" /> --> - + { - this.form = response; - const fnumberCount = response.reduce((countMap, item) => { - countMap[item.fnumber] = (countMap[item.fnumber] || 0) + 1; - return countMap; - }, {}); - // 获取成功的 fnumber 数量 - const successCount = Object.keys(fnumberCount).length; - //彈窗 - this.resNotice(successCount); - }).finally(()=>{ - this.loading = false; - }); - }, + updateFBMaterial(row) { + this.loading = true; + this.reset(); + + // 获取选中行的数据 + const selectedData = this.ids.map(id => { + const item = this.detailsList.find(row => row.id === id); + return { + fnumber: item.fnumber, // 物料编码 + totalWeight: item.totalWeight // 生产令号 + }; + }); + + console.log('发送数据:', selectedData); + + // 调用接口 + updateFBl(selectedData).then(response => { + this.form = response; + const successCount = response.length; + this.resNotice(successCount); + }).finally(() => { + this.loading = false; + }); +}, /** 弹窗 **/ resNotice(successCount) { this.$alert(`成功上传的条数:${successCount}`, '成功信息', { diff --git a/src/views/system/orderPro/index.vue b/src/views/system/orderPro/index.vue index d32a838..45e9dfe 100644 --- a/src/views/system/orderPro/index.vue +++ b/src/views/system/orderPro/index.vue @@ -136,14 +136,14 @@ icon="el-icon-folder-opened" @click="handleDetail(scope.row.productionOrderNo)" v-hasPermi="['system:orderPro:view']" - >查看详情 + >查看工艺 查看bom + >查看BOM diff --git a/src/views/system/route/index.vue b/src/views/system/route/index.vue index 1016d4c..15368de 100644 --- a/src/views/system/route/index.vue +++ b/src/views/system/route/index.vue @@ -42,12 +42,19 @@ v-hasPermi="['system:route:export']">导出 - + + 刷新库存 + 导入工艺 + + 导入时间 + + 推送工艺 @@ -91,6 +98,14 @@ --> + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - -
- -
- - {{ currentMaterial.materialCode }} - {{ currentMaterial.materialName }} - {{ currentMaterial.productionOrderNo }} - -
- -
- - -
- - - 新增 - - - 刷新 - - - 导出 - - -
-
- - - - - - - - - - - - - - - - - - - - - -
- - -
- - - - - - - -
- {{ item.materialName }} - - 库存: {{ item.singleWeight || '0' }} - -
-
- 编码: {{ item.materialCode }} | 材质: {{ item.materialQuality }} | 单位: {{ item.unit }} -
-
-
-
- - - {{ bomForm.materialCode }} - - - - {{ bomForm.materialQuality }} - - - - {{ bomForm.unit }} - - - - {{ bomForm.singleWeight || '0' }} - - - - - -
- + + + +
将文件拖到此处,或点击上传
+
+ 仅允许导入xls、xlsx格式文件。 +
+
-
-
+ + +
+ +
+ + {{ currentMaterial.materialCode }} + {{ currentMaterial.materialName }} + {{ currentMaterial.productionOrderNo }} + +
+ + +
+ + +
+ + + 新增 + + + 刷新 + + + 导出 + + +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
@@ -480,13 +589,13 @@ import { addRoute, updateRoute, getDistinctProjectCodes, - updateProcessPlan, generatePDFs + updateProcessPlan, generatePDFs, updateBom, addBom } from "@/api/system/route"; import upload from "svg-sprite-loader/examples/custom-runtime-generator/build/main"; import { getToken } from "../../../utils/auth"; import Fromed from './fromed' import Bomfrom from './bomfrom' -import { getProcessInfoList, pushRouteBom, onSave,getBomInfo } from "../../../api/system/route"; +import { getProcessInfoList, pushRouteBom, onSave, getBomInfo } from "@/api/system/route"; import { listMaterial } from "@/api/system/material"; export default { @@ -509,6 +618,14 @@ export default { }, data() { return { + timeUpload: { + open: false, + title: "", + isUploading: false, + headers: { Authorization: "Bearer " + getToken() }, + url: process.env.VUE_APP_BASE_API + "/system/route/importDataTime" + }, + materialOptions: [], // 用于存储物料信息 showtable: true, expand: true, bomData: [], @@ -681,44 +798,65 @@ export default { processName: [ { required: true, message: "工序名称不能为空", trigger: "blur" } ], - processDescription: [ - { required: true, message: "工序说明不能为空", trigger: "blur" } + // 添加物料相关的验证规则 + materialCode: [ + { required: true, message: "物料编码不能为空", trigger: "blur" } ], - processControl: [ - { required: true, message: "工序控制不能为空", trigger: "blur" } + materialName: [ + { required: true, message: "物料名称不能为空", trigger: "blur" } + ], + material: [ + { required: true, message: "材质不能为空", trigger: "blur" } + ], + discWeight: [ + { required: true, message: "单重不能为空", trigger: "blur" } ], - activityDuration: [ - { required: true, message: "活动时长不能为空", trigger: "blur" } - ] }, bomDialogVisible: false, bomDialogTitle: '', bomForm: { id: undefined, + projectNumber: '', // 添加项目令号 materialCode: '', materialName: '', - materialQuality: '', + materialType: '', quantity: 0, unit: '', - singleWeight : 0 + stock: 0, + parentMaterialCode: '', // 添加父级物料编码 + parentMaterialName: '', // 添加父级物料名称 }, bomRules: { + materialName: [ + { required: true, message: '请输入物料名称', trigger: 'blur' } + ], materialCode: [ { required: true, message: '请输入物料编码', trigger: 'blur' } ], - materialName: [ - { required: true, message: '请输入物料名称', trigger: 'blur' } + materialType: [ + { required: true, message: '请选择材质', trigger: 'change' } + ], + unit: [ + { required: true, message: '请选择单位', trigger: 'change' } ], quantity: [ { required: true, message: '请输入用量', trigger: 'blur' } ], - unit: [ - { required: true, message: '请选择单位', trigger: 'change' } + projectNumber: [ + { required: true, message: '项目令号不能为空', trigger: 'blur' } + ], + parentMaterialCode: [ + { required: true, message: '父级物料编码不能为空', trigger: 'blur' } + ], + parentMaterialName: [ + { required: true, message: '父级物料名称不能为空', trigger: 'blur' } + ], + stock: [ + { required: true, message: '库存不能为空', trigger: 'blur' } ] }, selectedBomRows: [], materialSearchLoading: false, - materialOptions: [], materialQuery: '', // 当前搜索关键字 materialPagination: { pageNum: 1, @@ -759,19 +897,209 @@ export default { } }, methods: { - // BOM抽屉相关方法 - bomClose(done) { - this.$confirm('确认关闭?') - .then(_ => { - this.bomData = []; - this.currentMaterial = { - materialCode: '', - materialName: '', - productionOrderNo: '' + // 处理工作中心变化 + handleWorkCenterChange(scope) { + const { row, $index } = scope; + // 如果是委外中心,自动设置工序控制为"委外+质量" + if (row.workCenter === '委外中心') { + row.processControl = '委外+质量'; + } else { + // 非委外中心时,检查是否需要设置为"汇报+免检" + this.setProcessControl(row, $index); + } +}, + // 处理工序控制变化 + handleProcessControlChange(row, index) { + // 验证工序控制是否符合规则 + const validControl = this.validateProcessControl(row, index); + if (!validControl.valid) { + this.$message.warning(validControl.message); + // 设置正确的工序控制值 + row.processControl = validControl.correctValue; + } + }, + + // 判断工序控制是否应该禁用 + isProcessControlDisabled(row, index) { + return row.workCenter === '委外中心' || this.shouldBeAutoFreeInspection(row, index); + }, + + // 设置工序控制 + setProcessControl(row, index) { + if (row.workCenter === '委外中心') { + // 委外中心必须是委外+质量 + this.$set(row, 'processControl', '委外+质量'); + } else if (this.shouldBeAutoFreeInspection(row, index)) { + // 与上序工作中心相同时设置为汇报+免检 + this.$set(row, 'processControl', '汇报+免检'); + } + }, + // 验证工序控制 + validateProcessControl(row, index) { + // 首先检查是否是委外中心 + if (row.workCenter === '委外中心') { + if (row.processControl !== '委外+质量') { + return { + valid: false, + message: '委外中心的工序控制必须为"委外+质量"', + correctValue: '委外+质量' }; - done(); - }) - .catch(_ => {}); + } + return { valid: true }; + } + + // 如果不是委外中心,检查是否需要自动免检 + if (this.shouldBeAutoFreeInspection(row, index) && row.processControl !== '汇报+免检') { + return { + valid: false, + message: '与上序工作中心相同时,工序控制应为"汇报+免检"', + correctValue: '汇报+免检' + }; + } + + return { valid: true }; +}, + // 判断是否应该自动设置为免检 + shouldBeAutoFreeInspection(row, index) { + if (!row.parentId || index === 0 || row.workCenter === '委外中心') { + return false; + } + + // 获取上一道工序 + const parent = this.form.routeList.find(item => item.id === row.parentId); + if (!parent || !parent.children) { + return false; + } + + const currentIndex = parent.children.findIndex(item => item === row); + if (currentIndex <= 0) { + return false; + } + + const prevProcess = parent.children[currentIndex - 1]; + + + return prevProcess && prevProcess.workCenter === row.workCenter; + }, + + + + + /* // 查询单个物料库存 + async handleMaterialSelect(materialCode) { + if (!materialCode) return; + + // 设置加载状态 + const row = this.form.routeList.find(item => item.materialCode === materialCode); + if (row) { + this.$set(row, 'loadingStock', true); + } + + try { + const response = await listMaterial({ + materialCode: materialCode + }); + + if (response.rows && response.rows.length > 0) { + const material = response.rows[0]; + // 更新对应行的库存信息 + if (row) { + this.$set(row, 'stock', material.singleWeight || 0); + } + } + } catch (error) { + console.error('查询库存失败:', error); + this.$message.error('查询库存失败'); + } finally { + if (row) { + this.$set(row, 'loadingStock', false); + } + } + },*/ + // 刷新所有物料库存 + // 修改刷新所有物料库存的方法 + async refreshAllStock() { + this.loading = true; + try { + const promises = this.form.routeList + .filter(row => row.materialCode) // 只处理有物料编码的行 + .map(row => this.handleMaterialSelect(row.materialCode)); + + await Promise.all(promises); + this.$message.success('库存刷新完成'); + } catch (error) { + console.error('批量刷新库存失败:', error); + this.$message.error('部分库存刷新失败'); + } finally { + this.loading = false; + } + }, + /** 导入时间按钮操作 */ + handleImportTime() { + this.timeUpload.title = "导入时间"; + this.timeUpload.open = true; + }, + // 处理时间文件上传进度 + handleTimeFileUploadProgress(event, file, fileList) { + this.timeUpload.isUploading = true; + }, + // 处理时间文件上传成功 + handleTimeFileSuccess(response, file, fileList) { + this.timeUpload.open = false; + this.timeUpload.isUploading = false; + this.$refs.timeUpload.clearFiles(); + this.$alert("
" + + response.msg + "
", "导入结果", { dangerouslyUseHTMLString: true }); + this.getList(); + }, + // 提交时间文件上传 + submitTimeFileForm() { + this.$refs.timeUpload.submit(); + }, + rowDrop() { + const tbody = document.querySelector('.el-table__body-wrapper tbody'); + const _this = this; + Sortable.create(tbody, { + onEnd({ newIndex, oldIndex }) { + const currRow = _this.form.routeList[oldIndex]; + // 只处理子工序 + if (currRow.parentId) { + const parentIndex = _this.form.routeList.findIndex(item => item.id === currRow.parentId); + if (parentIndex > -1) { + const children = _this.form.routeList[parentIndex].children; + // 移动数组元素 + const targetRow = children.splice(oldIndex, 1)[0]; + children.splice(newIndex, 0, targetRow); + // 重新计算工序号 + children.forEach((item, index) => { + item.processNo = (index + 1) * 10; // 按10、20、30...排序 + }); + } + } + }, + filter: ".filtered" // 过滤掉父节点 + }); + }, + + reorderProcessNo() { + this.form.routeList.forEach(parent => { + if (parent.children && parent.children.length) { + parent.children.forEach((child, index) => { + child.processNo = index + 1; // 使用下标+1 + }); + } + }); + }, + // BOM抽屉相关方法 + bomClose(done) { + // 直接清空数据并关闭 + this.bomData = []; + this.currentMaterial = { + materialCode: '', + materialName: '', + productionOrderNo: '' + }; + done(); }, handleBomSearch() { @@ -859,61 +1187,28 @@ export default { return a.processNo - b.processNo })[routeList.length - 1]; var processNo = !route ? 0 : route.processNo + 10; - routeList.push({ id: --this.id, parentId: props.row.id, processNo: processNo, children: null }); + //routeList.push({ id: --this.id, parentId: props.row.id, processNo: processNo, children: null }); + //this.showParentSaveBtn = props.row.id; + const newRow = { + id: --this.id, + parentId: props.row.id, + processNo: processNo, + children: null + }; + routeList.push(newRow); this.showParentSaveBtn = props.row.id; - }, - // 保存子集 -/* onSave(props) { - this.$confirm('确认保存工艺路线数据?', '提示', { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' - }).then(() => { - this.loading = true; - var list = this.form.routeList.find(item => item.id === props.row.id); - var newChildrenList = list.children.filter(item => item.id < 0).map(v => ({ - id: v.parentId, - routeDescription: list.routeDescription, - materialCode: list.materialCode, - materialName: list.materialName, - unit: list.unit, - processNo: v.processNo, - bomMaterial: list.bomMaterial, - workCenter: v.workCenter, - processName: v.processName, - rawMaterialCode: list.rawMaterialCode, - rawMaterialName: list.rawMaterialName, - discWeight: list.discWeight, - discUsage: list.discUsage, - processDescription: v.processDescription, - processControl: v.processControl, - activityDuration: v.activityDuration, - activityUnit: v.activityUnit, - material: list.material, - bomUnit: list.bomUnit, - unitQuantity: list.unitQuantity, - batchQuantity: list.batchQuantity, - firstBatchQuantity: list.firstBatchQuantity, - planStartTime: v.planStartTime, - planEndTime: v.planEndTime, - xuStartTime: v.xuStartTime || null, - xuEndTime: v.xuEndTime || null - })); - - return onSave(newChildrenList); - }).then((response) => { - this.$modal.msgSuccess("工艺路线保存成功"); - this.showParentSaveBtn = null; - this.getList(); - }).catch((error) => { - if (error !== 'cancel') { - this.$modal.msgError(error.message || "工艺路线保存失败"); + // 添加新行后,监听工作中心变化 + this.$nextTick(() => { + if (newRow.workCenter) { + this.setProcessControl(newRow, routeList.length - 1); } - }).finally(() => { - this.loading = false; }); - },*/ + + + + }, + // 删除子集 onDelete(props) { // 获取父级的所在下标 @@ -928,9 +1223,10 @@ export default { this.form.routeList[index].children[i].processNo = (i + 1) * 10; } }, -// 修改现有的cellhand方法 + // 修改现有的cellhand方法 cellhand(row, column) { - if (/单重|材料BOM物料编码|材料BOM物料名称|用量/.test(column.label)) { + // 只在点击物料编码列时触发 + if (column.property === 'materialCode') { this.BOMpop = true; this.bomLoading = true; @@ -972,26 +1268,44 @@ export default { }, /** 查询工艺路线列表 */ - getList() { + // 修改原有的 getList 方法,获取列表后自动刷新库存 + async getList() { this.loading = true; - listRoute(this.queryParams).then(response => { + try { + const response = await listRoute(this.queryParams); this.form.routeList = response.rows; this.total = response.total; + // 自动刷新库存 + await this.refreshAllStock(); + } catch (error) { + console.error('获取数据失败:', error); + this.$message.error('数据加载失败'); + } finally { this.loading = false; - }); + } }, - // 表单重置 reset() { this.form = { - ...this.form, // 保留现有数据 - // 只重置工艺编辑相关的字段 id: undefined, + // 物料信息 + materialCode: undefined, + materialName: undefined, + material: undefined, + discWeight: undefined, + bomUnit: undefined, + unitQuantity: undefined, + batchQuantity: undefined, + firstBatchQuantity: undefined, + // 工艺信息 workCenter: undefined, processName: undefined, processDescription: undefined, processControl: undefined, - activityDuration: undefined + activityDuration: undefined, + activityUnit: undefined, + xuStartTime: undefined, + xuEndTime: undefined }; this.resetForm("form"); }, @@ -1097,91 +1411,91 @@ export default { /**推送工艺 */ async pushRouteBom() { - // 获取生产订单号 - const productionOrderNo = this.$route.query.productionOrderNo; + // 获取生产订单号 + const productionOrderNo = this.$route.query.productionOrderNo; - if (!productionOrderNo) { - this.$modal.msgError("未获取到生产订单号,请检查!"); - return; - } - - try { - // 显示确认对话框 - await this.$confirm( - '推送工艺可能需要较长时间,请耐心等待。是否继续?', - '提示', - { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' + if (!productionOrderNo) { + this.$modal.msgError("未获取到生产订单号,请检查!"); + return; } - ); - // 显示全屏 loading - const loading = this.$loading({ - lock: true, - text: '正在推送工艺,请稍候...', - spinner: 'el-icon-loading', - background: 'rgba(0, 0, 0, 0.7)' - }); + try { + // 显示确认对话框 + await this.$confirm( + '推送工艺可能需要较长时间,请耐心等待。是否继续?', + '提示', + { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + } + ); - // 重置表单状态 - this.reset(); + // 显示全屏 loading + const loading = this.$loading({ + lock: true, + text: '正在推送工艺,请稍候...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' + }); - // 设置超时检测 - const timeout = 600000; // 10分钟超时 - const timeoutPromise = new Promise((_, reject) => { - setTimeout(() => { - reject(new Error('推送操作超时,请检查后台处理状态')); - }, timeout); - }); + // 重置表单状态 + this.reset(); - // 调用推送 API 并设置超时 - const response = await Promise.race([ - pushRouteBom(productionOrderNo), - timeoutPromise - ]); + // 设置超时检测 + const timeout = 600000; // 10分钟超时 + const timeoutPromise = new Promise((_, reject) => { + setTimeout(() => { + reject(new Error('推送操作超时,请检查后台处理状态')); + }, timeout); + }); - // 更新表单数据 - if (response && response.data) { - this.form = response.data; - } + // 调用推送 API 并设置超时 + const response = await Promise.race([ + pushRouteBom(productionOrderNo), + timeoutPromise + ]); - // 刷新列表 - await this.getList(); + // 更新表单数据 + if (response && response.data) { + this.form = response.data; + } - // 关闭 loading - loading.close(); + // 刷新列表 + await this.getList(); - // 显示成功消息 - this.$notify({ - title: '推送成功', - message: `工艺路线[${productionOrderNo}]推送完成`, - type: 'success', - duration: 5000 - }); + // 关闭 loading + loading.close(); - } catch (error) { - // 错误处理 - console.error('[推送工艺失败]:', error); + // 显示成功消息 + this.$notify({ + title: '推送成功', + message: `工艺路线[${productionOrderNo}]推送完成`, + type: 'success', + duration: 5000 + }); - // 显示错误通知 - this.$notify({ - title: '推送失败', - message: error.message || '推送失败,请重试!', - type: 'error', - duration: 0, - showClose: true - }); + } catch (error) { + // 错误处理 + console.error('[推送工艺失败]:', error); - } finally { - // 确保 loading 被关闭 - if (this.$loading) { - this.$loading().close(); - } - this.loading = false; - } -}, + // 显示错误通知 + this.$notify({ + title: '推送失败', + message: error.message || '推送失败,请重试!', + type: 'error', + duration: 0, + showClose: true + }); + + } finally { + // 确保 loading 被关闭 + if (this.$loading) { + this.$loading().close(); + } + this.loading = false; + } + }, /** 更新计划时间*/ updateProcessPlan(row) { // 显示加载状态 @@ -1248,6 +1562,14 @@ export default { submitForm() { this.$refs["form"].validate(valid => { if (valid) { + // 添加工序控制验证 + const processControlValid = this.validateAllProcessControls(); + if (!processControlValid.valid) { + this.$message.error(processControlValid.message); + return; + } + + this.buttonLoading = true; if (this.form.id != null) { updateRoute(this.form).then(response => { @@ -1271,21 +1593,35 @@ export default { } }); }, - /** 删除按钮操作 */ - handleDelete(scope) { - const ids = [scope.row.id]; - this.$modal.confirm('是否确认删除工艺路线编号为"' + ids + '"的数据项?').then(() => { - return delRoute(ids); - }).then(() => { - this.getList(); - this.$modal.msgSuccess("删除成功"); - }).catch(error => { - if (error !== 'cancel') { - console.error('Delete error:', error); - this.$modal.msgError("删除失败:" + (error.message || "未知错误")); + // 验证所有工序控制 + validateAllProcessControls() { + for (const row of this.form.routeList) { + if (row.children) { + for (let i = 0; i < row.children.length; i++) { + const validResult = this.validateProcessControl(row.children[i], i); + if (!validResult.valid) { + return validResult; + } + } + } } - }); - }, + return { valid: true }; + }, + /** 删除按钮操作 */ + handleDelete(scope) { + const ids = [scope.row.id]; + this.$modal.confirm('是否确认删除工艺路线编号为"' + ids + '"的数据项?').then(() => { + return delRoute(ids); + }).then(() => { + this.getList(); + this.$modal.msgSuccess("删除成功"); + }).catch(error => { + if (error !== 'cancel') { + console.error('Delete error:', error); + this.$modal.msgError("删除失败:" + (error.message || "未知错误")); + } + }); + }, /** 导出按钮操作 */ handleExport() { this.download('system/route/export', { @@ -1302,12 +1638,15 @@ export default { this.bomDialogTitle = '新增BOM'; this.bomForm = { id: undefined, + projectNumber: this.currentMaterial.productionOrderNo, // 使用当前的项目令号 materialCode: '', materialName: '', - materialQuality: '', + materialType: '', quantity: 0, unit: '', - singleWeight : 0 + stock: 0, + parentMaterialCode: this.currentMaterial.materialCode, // 使用当前物料作为父级 + parentMaterialName: this.currentMaterial.materialName }; this.bomDialogVisible = true; }, @@ -1330,7 +1669,7 @@ export default { }).then(() => { this.$message.success('删除成功'); this.handleBomRefresh(); - }).catch(() => {}); + }).catch(() => { }); }, // 提交BOM表单 @@ -1358,47 +1697,43 @@ export default { ); }, // 处理物料搜 - handleMaterialSearch(query) { - if (query === '') { - this.materialOptions = []; + handleMaterialSearch(queryString, callback) { + if (queryString.length === 0) { + callback([]); return; } this.materialSearchLoading = true; - // 调用查询接口,支持物料名称和编码搜索 listMaterial({ pageNum: 1, pageSize: 10, - materialName: query + materialName: queryString }).then(response => { - this.materialOptions = response.rows; - }).catch(error => { - console.error('搜索物料失败:', error); - this.$message.error('搜索物料失败'); + const suggestions = response.rows.map(item => ({ + materialName: item.materialName, + materialCode: item.materialCode, + materialType: item.materialQuality, + classificationName: item.classificationName, + singleWeight: item.singleWeight || 0 + })); + callback(suggestions); + }).catch(() => { + callback([]); }).finally(() => { this.materialSearchLoading = false; }); }, - - // 处理物料选择 - handleMaterialSelect(materialName) { - if (!materialName) { - this.bomForm.materialCode = ''; - this.bomForm.materialQuality = ''; - this.bomForm.singleWeight = 0; - this.bomForm.unit = ''; - return; - } - - // 从选项中获取选中的物料信息 - const selectedMaterial = this.materialOptions.find(item => item.materialName === materialName); - if (selectedMaterial) { - this.bomForm.materialCode = selectedMaterial.materialCode; - this.bomForm.materialQuality = selectedMaterial.materialQuality; - this.bomForm.singleWeight = selectedMaterial.singleWeight || 0; - this.bomForm.unit = selectedMaterial.unit; - } - }, + // 处理物料选择 + handleMaterialSelect(item) { + if (item) { + // 如果是从建议中选择 + this.bomForm.materialName = item.materialName; + this.bomForm.materialCode = item.materialCode; + this.bomForm.materialType = item.materialType; + this.bomForm.stock = item.singleWeight; + this.bomForm.unit = item.classificationName; + } + }, @@ -1533,7 +1868,13 @@ export default { if (parentRow && parentRow.children) { const index = parentRow.children.findIndex(item => item === scope.row); if (index > -1) { + // 删除当前行 parentRow.children.splice(index, 1); + + // 重新排序剩余的工序号 + parentRow.children.forEach((child, idx) => { + child.processNo = (idx + 1) * 10; // 按10、20、30...重新排序 + }); } } } @@ -1556,6 +1897,7 @@ export default { border: none; background-color: #FAFAFA; } + .bom-header { margin-bottom: 15px; } @@ -1591,7 +1933,55 @@ export default { .material-select-dropdown { max-height: 300px !important; } + .material-select-dropdown .el-select-dropdown__wrap { max-height: 300px !important; } + + +.material-autocomplete-dropdown { + min-width: 500px !important; + /* 设置下拉框最小宽度 */ +} + +.material-suggestion-item { + padding: 8px 10px; + border-bottom: 1px solid #eee; +} + +.material-suggestion-item:last-child { + border-bottom: none; +} + +.material-name { + font-size: 14px; + color: #303133; + margin-bottom: 4px; +} + +.material-info { + font-size: 12px; + color: #909399; +} + +.material-info span { + margin-right: 15px; +} + +.material-info span:last-child { + margin-right: 0; +} + +/* 调整输入框宽度 */ +.el-form-item[label="物料名称"] .el-autocomplete { + width: 100%; +} + +/* 可以添加一些提示样式 */ +.el-select.is-disabled .el-input__inner { + background-color: #f5f7fa; + border-color: #e4e7ed; + color: #909399; + cursor: not-allowed; +}