打分时增加校验:一级指标分值必须大于等于下级所有二级指标分值总和

This commit is contained in:
linxd
2025-07-15 11:30:18 +08:00
parent a8a4bbdb8f
commit 2b1715db6f

View File

@ -276,6 +276,19 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
message.error(intl.formatMessage({ id: 'supplierTemplateManage.message.addIndicator' })); message.error(intl.formatMessage({ id: 'supplierTemplateManage.message.addIndicator' }));
return; 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('一级指标分值不能小于二级指标分值之和');
return;
}
// 显示确认对话框 // 显示确认对话框
confirm({ confirm({
@ -341,7 +354,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
form.setFieldsValue({ form.setFieldsValue({
indicatorStMore: res.data.indicatorStMore, indicatorStMore: res.data.indicatorStMore,
indicatorTypeMore: res.data.indicatorTypeMore, indicatorTypeMore: res.data.indicatorTypeMore,
}) });
} }
} else { } else {
message.error( message.error(
@ -509,7 +522,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
loading={templateList.length === 0} loading={templateList.length === 0}
showSearch={true} showSearch={true}
filterOption={(input, option) => { filterOption={(input, option) => {
return (option?.children ?? '').toLowerCase().includes(input.toLowerCase()) return (option?.children ?? '').toLowerCase().includes(input.toLowerCase());
}} }}
onSelect={handleTemplateSelect} onSelect={handleTemplateSelect}
> >
@ -543,44 +556,54 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
</Form.Item> </Form.Item>
</Col> </Col>
</Row> </Row>
<Row gutter={24}> <Row gutter={24}>
<Col span={8}> <Col span={8}>
<Form.Item label="是否可追加一级指标" name="indicatorStMore" hidden={getUserRole() !== 'admin'}> <Form.Item
<Radio.Group onChange={(e) => { label="是否可追加一级指标"
name="indicatorStMore"
hidden={getUserRole() !== 'admin'}
>
<Radio.Group
onChange={(e) => {
if (e.target.value === IndicatorAddOption.CAN_ADD) { if (e.target.value === IndicatorAddOption.CAN_ADD) {
form.setFieldsValue({ form.setFieldsValue({
indicatorTypeMore: '', indicatorTypeMore: '',
}); });
} }
}}> }}
<Radio value={IndicatorAddOption.CAN_ADD}> >
{IndicatorAddOptionText[IndicatorAddOption.CAN_ADD]} <Radio value={IndicatorAddOption.CAN_ADD}>
</Radio> {IndicatorAddOptionText[IndicatorAddOption.CAN_ADD]}
<Radio value={IndicatorAddOption.CANNOT_ADD}> </Radio>
{IndicatorAddOptionText[IndicatorAddOption.CANNOT_ADD]} <Radio value={IndicatorAddOption.CANNOT_ADD}>
</Radio> {IndicatorAddOptionText[IndicatorAddOption.CANNOT_ADD]}
</Radio.Group> </Radio>
</Form.Item> </Radio.Group>
</Col>
<Form.Item // 这里必须放在Row下
shouldUpdate={(prev, curr) => prev.indicatorStMore !== curr.indicatorStMore}
noStyle
>
{({ getFieldValue }) =>
getFieldValue('indicatorStMore') === IndicatorAddOption.CANNOT_ADD ? (
<Col span={8}>
<Form.Item label="禁用指标类型" name="indicatorTypeMore" hidden={getUserRole() !== 'admin'}>
<Select
placeholder="请选择禁用指标类型"
options={indicatorTypes}
allowClear
/>
</Form.Item>
</Col>
) : null
}
</Form.Item> </Form.Item>
{/* <Col span={8}> </Col>
<Form.Item // 这里必须放在Row下
shouldUpdate={(prev, curr) => prev.indicatorStMore !== curr.indicatorStMore}
noStyle
>
{({ getFieldValue }) =>
getFieldValue('indicatorStMore') === IndicatorAddOption.CANNOT_ADD ? (
<Col span={8}>
<Form.Item
label="禁用指标类型"
name="indicatorTypeMore"
hidden={getUserRole() !== 'admin'}
>
<Select
placeholder="请选择禁用指标类型"
options={indicatorTypes}
allowClear
/>
</Form.Item>
</Col>
) : null
}
</Form.Item>
{/* <Col span={8}>
<Form.Item <Form.Item
label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorNdMore' })} label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorNdMore' })}
name="indicatorNdMore" name="indicatorNdMore"
@ -593,7 +616,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
/> />
</Form.Item> </Form.Item>
</Col> */} </Col> */}
</Row> </Row>
</Card> </Card>
<Divider /> <Divider />