在供应商评价模板保存时需要进行分值判断,二级指标分值相加必须等于一级指标分值,全部一级指标分值相加必须等于100分
This commit is contained in:
@ -96,7 +96,7 @@ const ViewModal: React.FC<{
|
||||
]
|
||||
return (
|
||||
<Modal
|
||||
title="记录"
|
||||
title="审批记录"
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
footer={[
|
||||
|
@ -218,6 +218,35 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ 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<PageProps> = ({ 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user