二级库出库逻辑调整

master
zhangdi 1 month ago
parent b7797adcff
commit e96de37b21
  1. 190
      src/views/secondOrder/components/outDialog.vue

@ -140,6 +140,7 @@
style="width: 100%" style="width: 100%"
border border
ref="groupTable" ref="groupTable"
@expand-change="handleExpandChange"
> >
<!-- 展开行详情 --> <!-- 展开行详情 -->
<el-table-column type="expand"> <el-table-column type="expand">
@ -153,12 +154,26 @@
(val) => handleSelectionChange(val, props.row) (val) => handleSelectionChange(val, props.row)
" "
border border
:row-key="getRowKeyId"
ref="nestedTable"
> >
<el-table-column <!-- <el-table-column
type="selection" type="selection"
width="55" width="55"
:selectable="isRowSelectable" :selectable="isRowSelectable"
/> /> -->
<el-table-column label="选择" width="55">
<template slot-scope="scope">
<el-checkbox
v-model="scope.row._selected"
:disabled="!isRowSelectable(scope.row)"
@change="
(checked) =>
handleRowSelect(checked, scope.row, props.row)
"
/>
</template>
</el-table-column>
<el-table-column type="index" label="#" width="55" /> <el-table-column type="index" label="#" width="55" />
<el-table-column label="物料名称" prop="materialName" /> <el-table-column label="物料名称" prop="materialName" />
<el-table-column label="物料编码" prop="materialCode" /> <el-table-column label="物料编码" prop="materialCode" />
@ -513,6 +528,56 @@ export default {
this.getOutGroupName(); this.getOutGroupName();
}, },
methods: { methods: {
handleExpandChange(row, expandedRows) {
//
if (expandedRows.includes(row)) {
this.$nextTick(() => {
// ref
// ref UI selection selectedGroupMap checkbox
// el-table selection UI checked
});
}
},
handleRowSelect(checked, childRow, parentRow) {
const key =
parentRow.materialId || parentRow.materialCode || parentRow.id;
let currentSelection = this.selectedGroupMap[key] || [];
if (checked) {
//
if (
!currentSelection.some(
(item) => item.materialId === childRow.materialId
)
) {
currentSelection = [...currentSelection, { ...childRow }];
}
} else {
//
currentSelection = currentSelection.filter(
(item) => item.materialId !== childRow.materialId
);
}
this.$set(this.selectedGroupMap, key, currentSelection);
//
let allDetails = [];
Object.values(this.selectedGroupMap).forEach((selectedList) => {
allDetails = allDetails.concat(
selectedList.map((item) => ({
...item,
num: item.num || (item.type === "NY" ? 1 : 0),
}))
);
});
this.sizeForm.ldTwoOutStorageDetailList = allDetails;
this.getStatistics();
},
// el-table row-key key
getRowKeyId(row) {
return row.materialId || row.id || row.materialCode;
},
isRowSelectable(row) { isRowSelectable(row) {
// materialName materialId // materialName materialId
return ( return (
@ -560,16 +625,25 @@ export default {
getGroupMaterial(this.sizeForm.ldTwoOutStorage).then((res) => { getGroupMaterial(this.sizeForm.ldTwoOutStorage).then((res) => {
this.groupTableData = res.data.result; this.groupTableData = res.data.result;
this.groupTableData.forEach((group) => { this.groupTableData.forEach((group) => {
// if (
if (group.twoInventoryVOList.length > 0) { group.twoInventoryVOList &&
group.twoInventoryVOList.forEach((element) => { group.twoInventoryVOList.length > 0
element.applyNum = group.applyNum; ) {
element.goodsCode = group.applyNum; group.twoInventoryVOList.forEach((item) => {
if (element.type === "NY") { item.applyNum = group.applyNum;
element.num = 1; item.goodsCode = group.applyNum;
if (item.type === "NY") {
item.num = 1;
} else { } else {
element.num = group.applyNum; item.num = group.applyNum;
} }
//
const key = group.materialId || group.materialCode || group.id;
const previouslySelected = this.selectedGroupMap[key] || [];
const isSelected = previouslySelected.some(
(sel) => sel.materialId === item.materialId
);
this.$set(item, "_selected", isSelected);
}); });
} }
}); });
@ -779,56 +853,60 @@ export default {
this.$refs.dynamicValidateForm.validate((valid) => { this.$refs.dynamicValidateForm.validate((valid) => {
if (valid) { if (valid) {
// ===== ===== // ===== =====
if (this.sizeForm.ldTwoOutStorage.groupName !== "自由出库") { if (this.sizeForm.ldTwoOutStorage.groupName !== "自由出库") {
let hasError = false; let hasError = false;
for (const group of this.groupTableData) { for (const group of this.groupTableData) {
const key = group.materialId || group.materialCode || group.id; const key = group.materialId || group.materialCode || group.id;
if (!key) continue; if (!key) continue;
// //
const selectedItems = this.selectedGroupMap[key] || []; const selectedItems = this.selectedGroupMap[key] || [];
//
if (selectedItems.length === 0) {
this.$message.error(
`分组【${
group.materialName || group.materialCode
}未选择任何物资`
);
hasError = true;
break;
}
// num
const totalSelectedNum = selectedItems.reduce((sum, item) => {
return sum + (Number(item.num) || 0);
}, 0);
const applyNum = Number(group.applyNum) || 0;
if (totalSelectedNum !== applyNum) {
this.$message.error(
`分组【${
group.materialName || group.materialCode
}已选物资出库数量总和${totalSelectedNum}与申请数量${applyNum}不一致`
);
hasError = true;
break;
}
}
// if (hasError) {
if (selectedItems.length === 0) { return; //
this.$message.error(`分组【${group.materialName || group.materialCode}】未选择任何物资`); }
hasError = true;
break;
} }
// num // ===== =====
const totalSelectedNum = selectedItems.reduce((sum, item) => { if (this.sizeForm.ldTwoOutStorage.groupName === "自由出库") {
return sum + (Number(item.num) || 0); if (
}, 0); !this.sizeForm.ldTwoOutStorageDetailList ||
this.sizeForm.ldTwoOutStorageDetailList.length === 0
const applyNum = Number(group.applyNum) || 0; ) {
this.$message.error("请至少选择一项物资");
if (totalSelectedNum !== applyNum) { return;
this.$message.error( }
`分组【${group.materialName || group.materialCode}】:已选物资出库数量总和(${totalSelectedNum})与申请数量(${applyNum})不一致`
);
hasError = true;
break;
} }
}
if (hasError) {
return; //
}
}
// ===== =====
if (this.sizeForm.ldTwoOutStorage.groupName === "自由出库") {
if (
!this.sizeForm.ldTwoOutStorageDetailList ||
this.sizeForm.ldTwoOutStorageDetailList.length === 0
) {
this.$message.error("请至少选择一项物资");
return;
}
}
submit(this.sizeForm).then((res) => { submit(this.sizeForm).then((res) => {
this.$message({ this.$message({

Loading…
Cancel
Save