diff --git a/src/views/materials/batchPlan/index.vue b/src/views/materials/batchPlan/index.vue index a21a726..263d0f8 100644 --- a/src/views/materials/batchPlan/index.vue +++ b/src/views/materials/batchPlan/index.vue @@ -133,7 +133,7 @@ - + @@ -152,24 +158,21 @@ - + @@ -239,7 +242,7 @@ import { } from '@/api/materials/batchPlan'; import { CailiaoshebeiVO, CailiaoshebeiQuery, CailiaoshebeiForm } from '@/api/materials/batchPlan/types'; import { useUserStoreHook } from '@/store/modules/user'; -import { getCurrentInstance, ComponentInternalInstance, watch, onMounted, onUnmounted } from 'vue'; +import { getCurrentInstance, ComponentInternalInstance, watch, onMounted, onUnmounted, computed } from 'vue'; import type { ElFormInstance } from 'element-plus'; // 类型定义补充 @@ -302,7 +305,7 @@ const dialog = reactive({ title: '' }); -// 初始化表单数据(补充版本号、重复错误提示字段) +// 初始化表单数据 const initFormData: FormData = { mrpBaseBo: { id: undefined, @@ -323,10 +326,10 @@ const initFormData: FormData = { qs: undefined, arrivalTime: undefined, remark: undefined, - Remaining: 0, // 初始化剩余量 - quantityError: '', // 初始化数量错误提示 - batchNumber: undefined, // 初始化版本号 - duplicateError: '', // 初始化重复错误提示 + Remaining: 0, + quantityError: '', + batchNumber: undefined, + duplicateError: '', mrpBaseId: undefined } ] @@ -390,7 +393,7 @@ const validateDemandQuantity = (row: PlanListItem, index: number) => { // 1. 清除之前的错误信息 row.quantityError = ''; - // 2. 处理空值(若需必填可补充:row.quantityError = '数量不能为空') + // 2. 处理空值 if (row.demandQuantity === null || row.demandQuantity === undefined || row.demandQuantity === '') { return; } @@ -426,42 +429,20 @@ const getMrpBaseRemaining = async (suppliespriceId: number, row: PlanListItem) = } }; -/** 校验重复数据:版本号+物资名称不能重复 */ -const checkDuplicate = () => { - const planList = form.value.planList; - let hasDuplicate = false; +/** 获取可用物资列表(过滤已选选项) */ +const getAvailableNameList = (currentIndex: number) => { + // 收集除当前行外已选中的物资ID + const selectedIds = form.value.planList + .filter((_, index) => index !== currentIndex) + .map(item => item.suppliespriceId) + .filter(id => id !== undefined && id !== null); - // 1. 清除所有重复错误提示 - planList.forEach((item) => { - item.duplicateError = ''; - }); - - // 2. 遍历校验重复(只校验版本号和物资名称都存在的行) - for (let i = 0; i < planList.length; i++) { - const current = planList[i]; - // 跳过版本号或物资名称为空的行 - if (!current.batchNumber || !current.suppliespriceId) continue; - - for (let j = i + 1; j < planList.length; j++) { - const compare = planList[j]; - if (!compare.batchNumber || !compare.suppliespriceId) continue; - - // 版本号和物资ID都相同则判定为重复 - if (current.batchNumber === compare.batchNumber && current.suppliespriceId === compare.suppliespriceId) { - current.duplicateError = `与第${j + 1}行重复(同版本+同物资)`; - compare.duplicateError = `与第${i + 1}行重复(同版本+同物资)`; - hasDuplicate = true; - } - } - } - - return hasDuplicate; + // 过滤掉已选中的物资 + return nameList.value.filter(item => !selectedIds.includes(item.id)); }; -/** 选择物资名称触发(新增索引参数,用于触发重复校验) */ +/** 选择物资名称触发 */ const selectName = (val: number, row: PlanListItem, index: number) => { - console.log(row); - // 1. 获取剩余量并更新基础信息 getMrpBaseRemaining(val, row).then(() => { const selected = nameList.value.find((item: any) => item.id === val); @@ -473,9 +454,6 @@ const selectName = (val: number, row: PlanListItem, index: number) => { row.remark = selected.remark || ''; row.arrivalTime = selected.arrivalTime || ''; } - - // 2. 触发重复校验 - checkDuplicate(); }); }; @@ -514,8 +492,6 @@ const delRow = (index: number) => { return proxy?.$modal.msgWarning('请至少保留一项物资数据'); } form.value.planList.splice(index, 1); - // 删除后重新校验重复(避免删除重复行后错误提示残留) - checkDuplicate(); }; /** 新增表格行 */ @@ -577,15 +553,15 @@ const handleUpdata = () => { if (!queryParams.value.mainData.mrpBaseId) { return proxy?.$modal.msgError('请先选择批次'); } - // 1. 获取对应版本的物资列表 + // 获取对应版本的物资列表 reset(); loading.value = true; getCailiaoshebei(queryParams.value.mainData.mrpBaseId) .then((res: any) => { - // 1. 更新基础信息 + // 更新基础信息 form.value.mrpBaseBo = res.data.mrpBaseBo || initFormData.mrpBaseBo; - // 2. 更新表格数据(补充缺失字段) + // 更新表格数据(补充缺失字段) form.value.planList = (res.data.planList || []).map((item: any) => ({ id: item.id, name: item.name, @@ -597,13 +573,12 @@ const handleUpdata = () => { arrivalTime: item.arrivalTime, remark: item.remark, Remaining: Number(item.remaining) || 0, - // remaining: quantityError: '', batchNumber: item.batchNumber, duplicateError: '', mrpBaseId: item.mrpBaseId })); - // 3. 打开对话框 + // 打开对话框 dialog.visible = true; dialog.title = '修改物资-需求'; }) @@ -617,38 +592,32 @@ const handleUpdata = () => { /** 提交数据(整合所有校验) */ const submitTransferForm = async () => { - // 1. 先校验重复数据 - const hasDuplicate = checkDuplicate(); - if (hasDuplicate) { - return proxy?.$modal.msgError('存在重复的版本号+物资组合,请修正后提交'); - } - - // 2. 校验数量合法性(检查是否有数量错误) + // 1. 校验数量合法性(检查是否有数量错误) const hasQuantityError = form.value.planList.some((row) => row.quantityError); if (hasQuantityError) { return proxy?.$modal.msgError('存在非法数量,请修正后提交'); } - // 3. 执行表单基础验证 + // 2. 执行表单基础验证 const result = validateAndClean(form.value.planList); if (!result.valid) { return proxy?.$modal.msgError(result.message); } - // 4. 表单组件验证 + // 3. 表单组件验证 cailiaoshebeiFormRef.value?.validate(async (valid: boolean) => { if (!valid) return; buttonLoading.value = true; try { - // 5. 提交数据 + // 4. 提交数据 await updateCailiaoshebei({ ...form.value, planList: result.data // 使用清洗后的数据 }); proxy?.$modal.msgSuccess('操作成功'); dialog.visible = false; - // 6. 刷新列表 + // 5. 刷新列表 await getList(); } catch (error) { proxy?.$modal.msgError('操作失败,请重试'); @@ -773,7 +742,7 @@ const getVersion = () => { }); }; -/** 选择版本号触发(新增索引参数,用于触发重复校验) */ +/** 选择版本号触发 */ const selectNameVersion = (val: string, row: PlanListItem, index: number) => { row.batchNumber = val; row.suppliespriceId = undefined; // 切换版本号时清空物资选择 @@ -788,11 +757,8 @@ const selectNameVersion = (val: string, row: PlanListItem, index: number) => { row.duplicateError = ''; row.mrpBaseId = ''; - // 1. 获取对应版本的物资列表 + // 获取对应版本的物资列表 getNameList(val); - - // 2. 触发重复校验(清空物资后可能消除重复) - checkDuplicate(); }; /** 页面挂载时初始化 */ diff --git a/src/views/materials/overallPlanMaterialSupply/index.vue b/src/views/materials/overallPlanMaterialSupply/index.vue index 686a1f8..6e73a63 100644 --- a/src/views/materials/overallPlanMaterialSupply/index.vue +++ b/src/views/materials/overallPlanMaterialSupply/index.vue @@ -9,7 +9,7 @@ 审批 - 查看流程 + 查看流程 diff --git a/src/views/materials/overallPlanMaterialSupply/indexEdit.vue b/src/views/materials/overallPlanMaterialSupply/indexEdit.vue index a35f892..56c849b 100644 --- a/src/views/materials/overallPlanMaterialSupply/indexEdit.vue +++ b/src/views/materials/overallPlanMaterialSupply/indexEdit.vue @@ -16,7 +16,7 @@
-

设计原则

+

物质供应总计划

搜索