|
|
|
|
@ -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 |
|
|
|
|
@ -772,19 +772,20 @@ export default { |
|
|
|
|
// 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; |
|
|
|
|
@ -881,8 +882,7 @@ export default { |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
async submit(index) { |
|
|
|
|
// 1. 基础校验 |
|
|
|
|
if (!this.sizeForm.reason) { |
|
|
|
|
if (!this.sizeForm.reason) { |
|
|
|
|
this.$message.error("事由不能为空"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
@ -890,112 +890,146 @@ export default { |
|
|
|
|
this.$message.error("请选择物资类型"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 校验表格数据 |
|
|
|
|
if (!this.sizeForm.inTableData || this.sizeForm.inTableData.length === 0) { |
|
|
|
|
this.$message.error("请添加出库物资数据"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. 分支校验与数据处理 |
|
|
|
|
let finalDetailList = []; |
|
|
|
|
// status == 1 暂存 ,2提交 |
|
|
|
|
this.sizeForm.status = index; |
|
|
|
|
|
|
|
|
|
// 准备提交的数据列表 |
|
|
|
|
let submitList = []; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
// 处理批量选择 (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.department 存的是 ID |
|
|
|
|
const selectedDeptObj = this.departmentList.find( |
|
|
|
|
(item) => item.departmentId === this.inBatchForm.department |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (!selectedDeptObj) { |
|
|
|
|
this.$message.error("部门信息丢失,请重新选择需求单和部门"); |
|
|
|
|
return; |
|
|
|
|
// 如果 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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理批量数据,补充必要的字段 |
|
|
|
|
finalDetailList = this.sizeForm.inTableData.map((row) => { |
|
|
|
|
// 批量模式下,所有行的部门应该是一致的,即 inBatchForm 中选中的部门 |
|
|
|
|
this.sizeForm.optionType = this.inBatchForm.optionType; |
|
|
|
|
|
|
|
|
|
submitList = this.sizeForm.inTableData.map((row) => { |
|
|
|
|
// 批量数据通常已经包含 materialId, code, name 等 |
|
|
|
|
// 关键是补充 department 和 oneFormId (如果需要) |
|
|
|
|
|
|
|
|
|
// 如果 row 中已经有 departmentId (建议修改 batchSubmit 让它存 ID),则直接用 |
|
|
|
|
// 否则使用上面推导的 deptId |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
...row, |
|
|
|
|
department: selectedDeptObj.departmentId, // 提交部门ID |
|
|
|
|
departmentName: selectedDeptObj.department, // 提交部门名称 |
|
|
|
|
// 如果后端需要 oneFormId,需确保 row 中有对应的 id 或 materialId |
|
|
|
|
// 原代码逻辑: oneFormId: select.id (这里 select 可能未定义,需检查业务逻辑) |
|
|
|
|
// 假设 batchList 返回的数据中已经包含了一表单ID或者不需要此字段,暂时保留原意但做保护 |
|
|
|
|
oneFormId: row.oneFormId || row.id |
|
|
|
|
// 确保提交正确的部门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 if (this.sizeForm.options === 2) { |
|
|
|
|
// === 单项选择模式 === |
|
|
|
|
if (!this.sizeForm.inTableData || this.sizeForm.inTableData.length === 0) { |
|
|
|
|
this.$message.error("请至少添加一条物资数据"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (const row of this.sizeForm.inTableData) { |
|
|
|
|
if (!row.department) { // 注意:单项选择时 v-model 绑定的是 scope.row.department (ID) |
|
|
|
|
this.$message.error("请选择部门"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理单项数据,将部门ID转换为名称(如果需要) |
|
|
|
|
finalDetailList = this.sizeForm.inTableData.map((row) => { |
|
|
|
|
} else { |
|
|
|
|
// 处理单项选择 (options == 2) |
|
|
|
|
// 原有逻辑基本保留,但要加强空值判断 |
|
|
|
|
submitList = this.sizeForm.inTableData.map((row) => { |
|
|
|
|
const deptId = row.department; |
|
|
|
|
// 在 this.list (单条部门列表) 中查找名称 |
|
|
|
|
const deptObj = this.list.find((item) => item.departmentId === deptId); |
|
|
|
|
const dept = this.list.find((item) => item.departmentId === deptId); |
|
|
|
|
|
|
|
|
|
// 单项选择时,需要从 materials 获取详细信息补全 |
|
|
|
|
let select = this.materials.find( |
|
|
|
|
(item) => item.materialId === row.materialId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 容错处理 |
|
|
|
|
if (!select) { |
|
|
|
|
console.warn('未找到对应的物资信息', row.materialId); |
|
|
|
|
select = {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
...row, |
|
|
|
|
department: deptId, |
|
|
|
|
departmentName: deptObj ? deptObj.department : "", |
|
|
|
|
oneFormId: row.oneFormId || row.id |
|
|
|
|
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 |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3. 组装最终提交对象 |
|
|
|
|
this.sizeForm.status = index; |
|
|
|
|
this.sizeForm.ldOneOutStorageDetailVOList = finalDetailList; |
|
|
|
|
|
|
|
|
|
// 如果是批量模式,确保 optionType 被正确设置 |
|
|
|
|
if (this.sizeForm.options === 1) { |
|
|
|
|
this.sizeForm.optionType = this.inBatchForm.optionType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 如果是编辑模式,带上 ID |
|
|
|
|
if (this.outDialogTiltle == "编辑" || this.outDialogType == "edit") { |
|
|
|
|
this.sizeForm.ldOneOutStorageDetailVOList = submitList; |
|
|
|
|
|
|
|
|
|
if (this.outDialogTiltle == "编辑") { |
|
|
|
|
this.sizeForm.id = this.id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4. 发起请求 |
|
|
|
|
try { |
|
|
|
|
this.saveLoading = true; |
|
|
|
|
console.log('提交数据:', this.sizeForm); // 调试用,确认数据结构 |
|
|
|
|
// 打印调试信息,方便查看提交数据结构 |
|
|
|
|
console.log('提交数据:', this.sizeForm); |
|
|
|
|
|
|
|
|
|
const res = await submitData(this.sizeForm); |
|
|
|
|
|
|
|
|
|
if (res.data.success) { |
|
|
|
|
this.$message({ |
|
|
|
|
type: "success", |
|
|
|
|
message: index === 1 ? "暂存成功" : "提交成功", |
|
|
|
|
message: "提交成功", |
|
|
|
|
}); |
|
|
|
|
this.$emit("submitSuccess"); |
|
|
|
|
this.saveLoading = false; |
|
|
|
|
this.handleCloseDetail(); |
|
|
|
|
} else { |
|
|
|
|
this.saveLoading = false; |
|
|
|
|
this.$message.error(res.data.message || "操作失败"); |
|
|
|
|
this.$message.error(res.data.message || "提交失败"); |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error(error); |
|
|
|
|
this.saveLoading = false; |
|
|
|
|
this.$message.error(error.message || "服务器错误"); |
|
|
|
|
} finally { |
|
|
|
|
this.saveLoading = false; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|