From 87ba7cdad51f95b3400867a2d7b21851d3474f4c Mon Sep 17 00:00:00 2001 From: zhangdi <1104545947@qq.com> Date: Wed, 6 May 2026 09:49:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=BA=93=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/firstOrder/components/outDialog.vue | 165 ++++++------------ 1 file changed, 49 insertions(+), 116 deletions(-) diff --git a/src/views/firstOrder/components/outDialog.vue b/src/views/firstOrder/components/outDialog.vue index 81980eb..9d33675 100644 --- a/src/views/firstOrder/components/outDialog.vue +++ b/src/views/firstOrder/components/outDialog.vue @@ -580,7 +580,7 @@ export default { item.materialCode === stat.materialCode && item.materialName === stat.materialName ); - console.log(898989, detailList); + console.log(898989,detailList) detail.theOutboundQuantity = detailList.reduce( (acc, cur) => acc + cur.num, 0 @@ -767,25 +767,24 @@ export default { ); const deptName = selectedDept ? selectedDept.department : ""; - // this.sizeForm.inTableData = res.data.result.map((item) => ({ + // this.sizeForm.inTableData = res.data.result.map((item) => ({ // ...item, // IdDemandEndld: this.inBatchForm.batchType, // department: deptName, // })); - const processedData = res.data.result.map((item) => { // 计算剩余可出库数量:申请数量 - 已出库数量 // 如果字段不存在,默认为 0 const appQty = Number(item.applicationQuantity || 0); const outQty = Number(item.outboundQuantity || 0); const defaultQty = appQty - outQty; - + return { ...item, IdDemandEndld: this.inBatchForm.batchType, department: deptName, // 注意:这里存的是名称还是ID需根据后续submit逻辑确认,原代码存的是名称 // 设置本次出库数量默认值,且不能小于0 - theOutboundQuantity: defaultQty > 0 ? defaultQty : 0, + theOutboundQuantity: defaultQty > 0 ? defaultQty : 0 }; }); this.sizeForm.inTableData = processedData; @@ -882,7 +881,7 @@ export default { }, // 提交 async submit(index) { - if (!this.sizeForm.reason) { + if (!this.sizeForm.reason) { this.$message.error("事由不能为空"); return; } @@ -890,130 +889,62 @@ export default { this.$message.error("请选择物资类型"); return; } - - // 校验表格数据 - if (!this.sizeForm.inTableData || this.sizeForm.inTableData.length === 0) { - this.$message.error("请添加出库物资数据"); - return; + if (this.sizeForm.options === 1) { + if (!this.sizeForm.demandEndInfo) { + this.$message.error("请选择需求单名称"); + return; + } + if ( + !this.sizeForm.inTableData || + this.sizeForm.inTableData.length === 0 + ) { + this.$message.error("请添加批量选择数据"); + return; + } + if (this.sizeForm.options === 2) { + for (const row of this.sizeForm.inTableData) { + if (!row.departmentName) { + this.$message.error("请选择部门"); + return; + } + } + } } - // status == 1 暂存 ,2提交 this.sizeForm.status = index; + this.sizeForm.ldOneOutStorageDetailVOList = this.sizeForm.inTableData; + let arr = this.list.find( + (item) => item.departmentId === this.inBatchForm.department || {} + ); - // 准备提交的数据列表 - let submitList = []; - - // 处理批量选择 (options == 1) - if (this.sizeForm.options == 1) { - // 1. 获取批量选择时的部门信息 - // 注意:这里需要确保 inBatchForm.department 仍然有效,或者从第一行数据中获取部门信息 - // 建议在 batchSubmit 成功后,将部门信息固化到 sizeForm 或者每一行数据中 - - let deptId = null; - let deptName = ""; - - // 尝试从 inBatchForm 获取(如果弹窗刚关闭,数据还在) - if (this.inBatchForm.department) { - const selectedDept = this.list.find(item => item.departmentId === this.inBatchForm.department); - if (selectedDept) { - deptId = selectedDept.departmentId; - deptName = selectedDept.department; - } - } - - // 如果 inBatchForm 失效,尝试从表格第一行获取(如果在 batchSubmit 中已经写入了 department 字段) - if (!deptId && this.sizeForm.inTableData.length > 0) { - // 假设 batchSubmit 中已经将 departmentId 写入到了行的 department 字段 - // 检查原代码 batchSubmit: department: deptName (存的是名称还是ID需确认) - // 原代码: department: deptName (看起来存的是名称,这有问题,后端通常需要ID) - // 修正:我们需要确保提交给后端的是正确的 ID 和 Name - - // 由于原代码 batchSubmit 中: - // department: deptName (这是名称) - // 我们需要重新匹配一下或者依赖 list - const firstRow = this.sizeForm.inTableData[0]; - // 如果行里有 departmentId 最好,如果没有,可能需要根据名称反查,或者依赖之前的逻辑 - // 这里为了稳健,我们假设 batchSubmit 应该存 ID,但原代码存了 Name。 - // 让我们看原代码 batchSubmit: - // const deptName = selectedDept ? selectedDept.department : ""; - // department: deptName - // 这是一个潜在的Bug:表单里存的是名称,但提交时需要ID。 - - // 临时修复:根据名称在 list 中反查 ID - if(firstRow.department) { - const deptObj = this.list.find(d => d.department === firstRow.department); - if(deptObj) { - deptId = deptObj.departmentId; - deptName = deptObj.department; - } - } - } - - this.sizeForm.optionType = this.inBatchForm.optionType; - - submitList = this.sizeForm.inTableData.map((row) => { - // 批量数据通常已经包含 materialId, code, name 等 - // 关键是补充 department 和 oneFormId (如果需要) - - // 如果 row 中已经有 departmentId (建议修改 batchSubmit 让它存 ID),则直接用 - // 否则使用上面推导的 deptId - - return { - ...row, - // 确保提交正确的部门ID和名称 - department: deptId || row.departmentId || row.department, - departmentName: deptName || row.departmentName || row.department, - // 批量模式下,oneFormId 可能不需要从 materials 找,而是行数据里的 id 或其他标识 - // 原代码: oneFormId: select.id。如果 select 找不到,这里会错。 - // 通常批量接口返回的 item 本身就有 id (即 detailId) - oneFormId: row.id || row.materialId, - theOutboundQuantity: row.theOutboundQuantity || row.num // 确保数量字段正确 - }; - }); - - } else { - // 处理单项选择 (options == 2) - // 原有逻辑基本保留,但要加强空值判断 - submitList = this.sizeForm.inTableData.map((row) => { + + this.sizeForm.ldOneOutStorageDetailVOList = this.sizeForm.inTableData.map( + (row) => { const deptId = row.department; const dept = this.list.find((item) => item.departmentId === deptId); - - // 单项选择时,需要从 materials 获取详细信息补全 + const oneFormId = row.id; let select = this.materials.find( (item) => item.materialId === row.materialId ); - - // 容错处理 - if (!select) { - console.warn('未找到对应的物资信息', row.materialId); - select = {}; - } return { ...row, - department: deptId, - departmentName: dept ? dept.department : row.departmentName, - oneFormId: select.id || row.oneFormId, // 优先用查找到的,其次用原有的 - materialCode: select.materialCode || row.materialCode, - materialName: select.materialName || row.materialName, - model: select.model || row.model, - type: select.type || row.type, - unit: select.unit || row.unit + department: + this.sizeForm.options == "1" ? arr.departmentId : deptId, + departmentName: + this.sizeForm.options == "1" ? arr.department : dept.department, + oneFormId: row.oneFormId, }; - }); - } - - this.sizeForm.ldOneOutStorageDetailVOList = submitList; - + } + ); if (this.outDialogTiltle == "编辑") { this.sizeForm.id = this.id; } - + if (this.sizeForm.options === 1) { + this.sizeForm.optionType = this.inBatchForm.optionType; + } try { this.saveLoading = true; - // 打印调试信息,方便查看提交数据结构 - console.log('提交数据:', this.sizeForm); - const res = await submitData(this.sizeForm); if (res.data.success) { this.$message({ @@ -1021,15 +952,15 @@ export default { message: "提交成功", }); this.$emit("submitSuccess"); + this.saveLoading = false; this.handleCloseDetail(); } else { + this.saveLoading = false; this.$message.error(res.data.message || "提交失败"); } } catch (error) { - console.error(error); - this.$message.error(error.message || "服务器错误"); - } finally { this.saveLoading = false; + this.$message.error(error.message || "服务器错误"); } }, @@ -1069,10 +1000,12 @@ export default { this.batchSelectionVisible = false; this.sizeForm.optionType = ""; this.batchTableData = []; + this.inBatchForm.batchType = "" + this.inBatchForm.department = "" if (this.sizeForm.options === 1) { this.getQuarterList(); this.inBatchDialogVisible = true; - (this.inBatchForm.batchType = ""), (this.inBatchForm.department = ""); + this.inBatchForm.optionType = ""; } },