diff --git a/src/pages/supplier/category/SupplierEntryReview/components/ViewModal.tsx b/src/pages/supplier/category/SupplierEntryReview/components/ViewModal.tsx index 59e091b..e1e47af 100644 --- a/src/pages/supplier/category/SupplierEntryReview/components/ViewModal.tsx +++ b/src/pages/supplier/category/SupplierEntryReview/components/ViewModal.tsx @@ -96,7 +96,7 @@ const ViewModal: React.FC<{ ] return ( = ({ breadcrumb, dispatch } const handleBack = () => { history.goBack(); }; + // 提交时校验 全部一级指标分值相加必须等于100分 并且 二级指标分值相加必须等于一级指标分值 + const validateScore = () => { + // 校验一级指标总分必须等于100 + const totalScore = templateData.reduce( + (acc, stItem) => acc + parseFloat(stItem.score || '0'), + 0, + ); + + if (totalScore !== 100) { + message.error('一级指标分值相加必须等于100分'); + return false; + } + + // 校验每个一级指标下的二级指标之和是否等于该一级指标分值 + for (const stItem of templateData) { + const firstLevelScore = parseFloat(stItem.score || '0'); + const secondLevelTotal = stItem.indicatorNdList?.reduce( + (acc, ndItem) => acc + parseFloat(ndItem.score || '0'), + 0, + ) || 0; + + if (secondLevelTotal !== firstLevelScore) { + message.error(`二级指标分值之和必须等于其一级指标的分值`); + return false; + } + } + + return true; + }; // 提交数据的函数 const handleDataSubmit = async (values: FormValues) => { @@ -276,17 +305,8 @@ const SupplierTemplateManageAdd: React.FC = ({ breadcrumb, dispatch } message.error(intl.formatMessage({ id: 'supplierTemplateManage.message.addIndicator' })); return; } - // 校验每一个一级指标所属的所有二级指标分值是否超过一级指标的分值 - const hasInvalidScore = templateData.some((stItem) => { - const totalScore = stItem.indicatorNdList.reduce( - (acc, ndItem) => acc + parseFloat(ndItem.score || '0'), - 0, - ); - return totalScore > parseFloat(stItem.score || '0'); - }); - - if (hasInvalidScore) { - message.error('一级指标分值不能小于二级指标分值之和'); + // 校验分数 + if (!validateScore()) { return; }