提交问题修改

master
zhangdi 2 weeks ago
parent 0e4bdc44ff
commit 1f68203d4f
  1. 180
      src/views/firstOrder/components/outDialog.vue

@ -580,7 +580,7 @@ export default {
item.materialCode === stat.materialCode && item.materialCode === stat.materialCode &&
item.materialName === stat.materialName item.materialName === stat.materialName
); );
console.log(898989,detailList) console.log(898989, detailList);
detail.theOutboundQuantity = detailList.reduce( detail.theOutboundQuantity = detailList.reduce(
(acc, cur) => acc + cur.num, (acc, cur) => acc + cur.num,
0 0
@ -772,19 +772,20 @@ export default {
// IdDemandEndld: this.inBatchForm.batchType, // IdDemandEndld: this.inBatchForm.batchType,
// department: deptName, // department: deptName,
// })); // }));
const processedData = res.data.result.map((item) => { const processedData = res.data.result.map((item) => {
// - // -
// 0 // 0
const appQty = Number(item.applicationQuantity || 0); const appQty = Number(item.applicationQuantity || 0);
const outQty = Number(item.outboundQuantity || 0); const outQty = Number(item.outboundQuantity || 0);
const defaultQty = appQty - outQty; const defaultQty = appQty - outQty;
return { return {
...item, ...item,
IdDemandEndld: this.inBatchForm.batchType, IdDemandEndld: this.inBatchForm.batchType,
department: deptName, // IDsubmit department: deptName, // IDsubmit
// 0 // 0
theOutboundQuantity: defaultQty > 0 ? defaultQty : 0 theOutboundQuantity: defaultQty > 0 ? defaultQty : 0,
}; };
}); });
this.sizeForm.inTableData = processedData; this.sizeForm.inTableData = processedData;
@ -881,8 +882,7 @@ export default {
}, },
// //
async submit(index) { async submit(index) {
// 1. if (!this.sizeForm.reason) {
if (!this.sizeForm.reason) {
this.$message.error("事由不能为空"); this.$message.error("事由不能为空");
return; return;
} }
@ -890,112 +890,146 @@ export default {
this.$message.error("请选择物资类型"); this.$message.error("请选择物资类型");
return; return;
} }
//
if (!this.sizeForm.inTableData || this.sizeForm.inTableData.length === 0) {
this.$message.error("请添加出库物资数据");
return;
}
// 2. // status == 1 2
let finalDetailList = []; this.sizeForm.status = index;
//
let submitList = [];
if (this.sizeForm.options === 1) { // (options == 1)
// === === if (this.sizeForm.options == 1) {
if (!this.sizeForm.demandEndInfo) { // 1.
this.$message.error("请选择需求单名称"); // inBatchForm.department
return; // batchSubmit sizeForm
}
if (!this.sizeForm.inTableData || this.sizeForm.inTableData.length === 0) { let deptId = null;
this.$message.error("请添加批量选择数据"); let deptName = "";
return;
// 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) { // inBatchForm batchSubmit department
this.$message.error("部门信息丢失,请重新选择需求单和部门"); if (!deptId && this.sizeForm.inTableData.length > 0) {
return; // 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
// BugID
// 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;
finalDetailList = this.sizeForm.inTableData.map((row) => {
// inBatchForm submitList = this.sizeForm.inTableData.map((row) => {
// materialId, code, name
// department oneFormId ()
// row departmentId ( batchSubmit ID)
// 使 deptId
return { return {
...row, ...row,
department: selectedDeptObj.departmentId, // ID // ID
departmentName: selectedDeptObj.department, // department: deptId || row.departmentId || row.department,
// oneFormId row id materialId departmentName: deptName || row.departmentName || row.department,
// : oneFormId: select.id ( select ) // oneFormId materials id
// batchList ID // : oneFormId: select.id select
oneFormId: row.oneFormId || row.id // item id ( detailId)
oneFormId: row.id || row.materialId,
theOutboundQuantity: row.theOutboundQuantity || row.num //
}; };
}); });
} else if (this.sizeForm.options === 2) { } else {
// === === // (options == 2)
if (!this.sizeForm.inTableData || this.sizeForm.inTableData.length === 0) { //
this.$message.error("请至少添加一条物资数据"); submitList = this.sizeForm.inTableData.map((row) => {
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) => {
const deptId = row.department; const deptId = row.department;
// this.list () const dept = this.list.find((item) => item.departmentId === deptId);
const deptObj = 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 { return {
...row, ...row,
department: deptId, department: deptId,
departmentName: deptObj ? deptObj.department : "", departmentName: dept ? dept.department : row.departmentName,
oneFormId: row.oneFormId || row.id 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.ldOneOutStorageDetailVOList = submitList;
this.sizeForm.status = index;
this.sizeForm.ldOneOutStorageDetailVOList = finalDetailList; if (this.outDialogTiltle == "编辑") {
// optionType
if (this.sizeForm.options === 1) {
this.sizeForm.optionType = this.inBatchForm.optionType;
}
// ID
if (this.outDialogTiltle == "编辑" || this.outDialogType == "edit") {
this.sizeForm.id = this.id; this.sizeForm.id = this.id;
} }
// 4.
try { try {
this.saveLoading = true; this.saveLoading = true;
console.log('提交数据:', this.sizeForm); // // 便
console.log('提交数据:', this.sizeForm);
const res = await submitData(this.sizeForm); const res = await submitData(this.sizeForm);
if (res.data.success) { if (res.data.success) {
this.$message({ this.$message({
type: "success", type: "success",
message: index === 1 ? "暂存成功" : "提交成功", message: "提交成功",
}); });
this.$emit("submitSuccess"); this.$emit("submitSuccess");
this.saveLoading = false;
this.handleCloseDetail(); this.handleCloseDetail();
} else { } else {
this.saveLoading = false; this.$message.error(res.data.message || "提交失败");
this.$message.error(res.data.message || "操作失败");
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
this.saveLoading = false;
this.$message.error(error.message || "服务器错误"); this.$message.error(error.message || "服务器错误");
} finally {
this.saveLoading = false;
} }
}, },

Loading…
Cancel
Save