|
|
|
|
@ -767,11 +767,27 @@ export default { |
|
|
|
|
); |
|
|
|
|
const deptName = selectedDept ? selectedDept.department : ""; |
|
|
|
|
|
|
|
|
|
this.sizeForm.inTableData = res.data.result.map((item) => ({ |
|
|
|
|
...item, |
|
|
|
|
IdDemandEndld: this.inBatchForm.batchType, |
|
|
|
|
department: deptName, |
|
|
|
|
})); |
|
|
|
|
// 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 |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
this.sizeForm.inTableData = processedData; |
|
|
|
|
|
|
|
|
|
// 关闭批量选择弹窗 |
|
|
|
|
this.inBatchDialogVisible = false; |
|
|
|
|
@ -865,6 +881,7 @@ export default { |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
async submit(index) { |
|
|
|
|
// 1. 基础校验 |
|
|
|
|
if (!this.sizeForm.reason) { |
|
|
|
|
this.$message.error("事由不能为空"); |
|
|
|
|
return; |
|
|
|
|
@ -873,73 +890,110 @@ export default { |
|
|
|
|
this.$message.error("请选择物资类型"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. 分支校验与数据处理 |
|
|
|
|
let finalDetailList = []; |
|
|
|
|
|
|
|
|
|
if (this.sizeForm.options === 1) { |
|
|
|
|
// === 批量选择模式 === |
|
|
|
|
if (!this.sizeForm.demandEndInfo) { |
|
|
|
|
this.$message.error("请选择需求单名称"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if ( |
|
|
|
|
!this.sizeForm.inTableData || |
|
|
|
|
this.sizeForm.inTableData.length === 0 |
|
|
|
|
) { |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取批量模式下选中的部门信息 |
|
|
|
|
// 注意:inBatchForm.department 存的是 ID |
|
|
|
|
const selectedDeptObj = this.departmentList.find( |
|
|
|
|
(item) => item.departmentId === this.inBatchForm.department |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (!selectedDeptObj) { |
|
|
|
|
this.$message.error("部门信息丢失,请重新选择需求单和部门"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理批量数据,补充必要的字段 |
|
|
|
|
finalDetailList = this.sizeForm.inTableData.map((row) => { |
|
|
|
|
// 批量模式下,所有行的部门应该是一致的,即 inBatchForm 中选中的部门 |
|
|
|
|
return { |
|
|
|
|
...row, |
|
|
|
|
department: selectedDeptObj.departmentId, // 提交部门ID |
|
|
|
|
departmentName: selectedDeptObj.department, // 提交部门名称 |
|
|
|
|
// 如果后端需要 oneFormId,需确保 row 中有对应的 id 或 materialId |
|
|
|
|
// 原代码逻辑: oneFormId: select.id (这里 select 可能未定义,需检查业务逻辑) |
|
|
|
|
// 假设 batchList 返回的数据中已经包含了一表单ID或者不需要此字段,暂时保留原意但做保护 |
|
|
|
|
oneFormId: row.oneFormId || row.id |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} 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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// status == 1 暂存 ,2提交 |
|
|
|
|
this.sizeForm.status = index; |
|
|
|
|
this.sizeForm.ldOneOutStorageDetailVOList = this.sizeForm.inTableData; |
|
|
|
|
let arr = this.departmentList.find( |
|
|
|
|
(item) => item.departmentId === this.inBatchForm.department || {} |
|
|
|
|
); |
|
|
|
|
this.sizeForm.ldOneOutStorageDetailVOList = this.sizeForm.inTableData.map( |
|
|
|
|
(row) => { |
|
|
|
|
|
|
|
|
|
// 处理单项数据,将部门ID转换为名称(如果需要) |
|
|
|
|
finalDetailList = this.sizeForm.inTableData.map((row) => { |
|
|
|
|
const deptId = row.department; |
|
|
|
|
const dept = this.list.find((item) => item.departmentId === deptId); |
|
|
|
|
const oneFormId = row.id; |
|
|
|
|
let select = this.materials.find( |
|
|
|
|
(item) => item.materialId === row.materialId |
|
|
|
|
); |
|
|
|
|
// 在 this.list (单条部门列表) 中查找名称 |
|
|
|
|
const deptObj = this.list.find((item) => item.departmentId === deptId); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
...row, |
|
|
|
|
department: |
|
|
|
|
this.sizeForm.options == "1" ? arr.departmentId : deptId, |
|
|
|
|
departmentName: |
|
|
|
|
this.sizeForm.options == "1" ? arr.department : dept.department, |
|
|
|
|
oneFormId: select.id, |
|
|
|
|
department: deptId, |
|
|
|
|
departmentName: deptObj ? deptObj.department : "", |
|
|
|
|
oneFormId: row.oneFormId || row.id |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
if (this.outDialogTiltle == "编辑") { |
|
|
|
|
this.sizeForm.id = this.id; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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.id = this.id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4. 发起请求 |
|
|
|
|
try { |
|
|
|
|
this.saveLoading = true; |
|
|
|
|
console.log('提交数据:', this.sizeForm); // 调试用,确认数据结构 |
|
|
|
|
|
|
|
|
|
const res = await submitData(this.sizeForm); |
|
|
|
|
|
|
|
|
|
if (res.data.success) { |
|
|
|
|
this.$message({ |
|
|
|
|
type: "success", |
|
|
|
|
message: "提交成功", |
|
|
|
|
message: index === 1 ? "暂存成功" : "提交成功", |
|
|
|
|
}); |
|
|
|
|
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 || "服务器错误"); |
|
|
|
|
} |
|
|
|
|
|