评价模板禁用逻辑
This commit is contained in:
@ -15,6 +15,7 @@ import {
|
||||
Typography,
|
||||
Spin,
|
||||
Modal,
|
||||
Checkbox,
|
||||
} from 'antd';
|
||||
import { history, useLocation, useIntl, connect } from 'umi';
|
||||
import type { Dispatch, ConnectProps } from 'umi';
|
||||
@ -28,7 +29,11 @@ import {
|
||||
TemplateStatus,
|
||||
TemplateStatusText,
|
||||
IndicatorAddOption,
|
||||
IndicatorAddOptionText,
|
||||
Types,
|
||||
} from '@/dicts/supplierTemplateDict';
|
||||
|
||||
import { useUser } from '@/hooks/useUser';
|
||||
import {
|
||||
getTemplateDetail,
|
||||
getAllTemplates,
|
||||
@ -36,6 +41,8 @@ import {
|
||||
addTemplate,
|
||||
} from '@/servers/api/supplierEvaluate';
|
||||
import styles from './supplierTemplateManage.less';
|
||||
import { getDictList } from '@/servers/api/dicts';
|
||||
import type { DictItem } from '@/servers/api/dicts';
|
||||
|
||||
const { Option } = Select;
|
||||
const { confirm } = Modal;
|
||||
@ -65,6 +72,7 @@ interface LocationState {
|
||||
const { Title } = Typography;
|
||||
|
||||
const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }) => {
|
||||
const { getUserRole, setUserInfo } = useUser();
|
||||
const intl = useIntl();
|
||||
const [form] = Form.useForm<FormValues>();
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
@ -74,10 +82,11 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
useState<SupplierTemplateManage.TemplateDetailResponse['data']>();
|
||||
const [templateList, setTemplateList] = useState<SupplierTemplateManage.TemplateItem[]>([]);
|
||||
|
||||
// 添加控制开关的状态
|
||||
// 添加控制开关的状态 一级指标是否可增加(0.可增加、1.不可增加)
|
||||
const [indicatorStMore, setIndicatorStMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||
//二级指标是否可增加(0.可增加、1.不可增加)
|
||||
const [indicatorNdMore, setIndicatorNdMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||
|
||||
const [indicatorTypes, setIndicatorTypes] = useState<{ label: string; value: string }[]>([]);
|
||||
// 获取路由传递的数据
|
||||
const location = useLocation<LocationState>();
|
||||
|
||||
@ -128,6 +137,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
copyTemplateId: res.data.copyTemplateId,
|
||||
indicatorStMore: res.data.indicatorStMore || IndicatorAddOption.CAN_ADD,
|
||||
indicatorNdMore: res.data.indicatorNdMore || IndicatorAddOption.CAN_ADD,
|
||||
indicatorTypeMore: res.data.indicatorTypeMore || '',
|
||||
});
|
||||
|
||||
// 直接设置指标数据,无需转换
|
||||
@ -147,6 +157,31 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取指标类型字典
|
||||
const fetchIndicatorTypes = async () => {
|
||||
try {
|
||||
const res = await getDictList('Indicator_type');
|
||||
if (res.success && res.data) {
|
||||
setIndicatorTypes(
|
||||
res.data.map((item: DictItem) => ({
|
||||
label: item.dicName,
|
||||
value: item.code,
|
||||
})),
|
||||
);
|
||||
} else {
|
||||
message.error(
|
||||
intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.message.getTypeFailed' }),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取指标类型失败:', error);
|
||||
message.error(
|
||||
intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.message.getTypeFailed' }),
|
||||
);
|
||||
} finally {
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
if (location.state?.editData?.id && dispatch) {
|
||||
dispatch({
|
||||
@ -164,6 +199,8 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
useEffect(() => {
|
||||
// 获取所有模板列表
|
||||
fetchTemplateList();
|
||||
// 获取指标类型
|
||||
fetchIndicatorTypes();
|
||||
// 如果是编辑模式,加载编辑数据
|
||||
if (location.state?.isEdit && location.state?.editData) {
|
||||
setIsEdit(true);
|
||||
@ -188,7 +225,6 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
...values,
|
||||
templateType: selectedTemplate?.templateType || '',
|
||||
indicatorStList: templateData,
|
||||
indicatorTypeMore: IndicatorAddOption.CAN_ADD,
|
||||
status: parseInt(values.status, 10),
|
||||
} as unknown as SupplierTemplateManage.TemplateUpdateRequest;
|
||||
|
||||
@ -196,7 +232,6 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
if (isEdit && templateDetail) {
|
||||
dataToSubmit.id = templateDetail.id;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
// 调用API接口
|
||||
@ -260,6 +295,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
|
||||
// 处理指标数据变更
|
||||
const handleTemplateDataChange = (data: SupplierTemplateManage.IndicatorSt[]) => {
|
||||
console.log('handleTemplateDataChange', data);
|
||||
setTemplateData(data);
|
||||
};
|
||||
|
||||
@ -371,7 +407,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Form<FormValues>
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={handleSubmit}
|
||||
initialValues={{
|
||||
@ -511,22 +547,39 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={24}>
|
||||
<Col span={8}>
|
||||
<Form.Item
|
||||
label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorStMore' })}
|
||||
name="indicatorStMore"
|
||||
valuePropName="checked"
|
||||
getValueProps={(value) => ({ checked: value === IndicatorAddOption.CAN_ADD })}
|
||||
{getUserRole() === 'admin' && (
|
||||
<Row gutter={24}>
|
||||
<Col span={8}>
|
||||
<Form.Item label="是否可追加一级指标" name="indicatorStMore">
|
||||
<Radio.Group>
|
||||
<Radio value={IndicatorAddOption.CAN_ADD}>
|
||||
{IndicatorAddOptionText[IndicatorAddOption.CAN_ADD]}
|
||||
</Radio>
|
||||
<Radio value={IndicatorAddOption.CANNOT_ADD}>
|
||||
{IndicatorAddOptionText[IndicatorAddOption.CANNOT_ADD]}
|
||||
</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Form.Item // 这里必须放在Row下
|
||||
shouldUpdate={(prev, curr) => prev.indicatorStMore !== curr.indicatorStMore}
|
||||
noStyle
|
||||
>
|
||||
<Switch
|
||||
checked={indicatorStMore === IndicatorAddOption.CAN_ADD}
|
||||
onChange={(checked) => handleSwitchChange('indicatorStMore', checked)}
|
||||
/>
|
||||
{({ getFieldValue }) =>
|
||||
getFieldValue('indicatorStMore') === IndicatorAddOption.CANNOT_ADD ? (
|
||||
<Col span={8}>
|
||||
<Form.Item label="禁用指标类型" name="indicatorTypeMore">
|
||||
<Select
|
||||
placeholder="请选择禁用指标类型"
|
||||
options={indicatorTypes}
|
||||
allowClear
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
) : null
|
||||
}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
{/* <Col span={8}>
|
||||
<Form.Item
|
||||
label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorNdMore' })}
|
||||
name="indicatorNdMore"
|
||||
@ -538,8 +591,9 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
onChange={(checked) => handleSwitchChange('indicatorNdMore', checked)}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</Col> */}
|
||||
</Row>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Divider />
|
||||
@ -549,7 +603,22 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
bordered={false}
|
||||
className={styles.innerCard}
|
||||
>
|
||||
<EvaluateTemplateTable onChange={handleTemplateDataChange} value={templateData} />
|
||||
<Form.Item
|
||||
shouldUpdate={(prev, curr) =>
|
||||
prev.indicatorStMore !== curr.indicatorStMore ||
|
||||
prev.indicatorTypeMore !== curr.indicatorTypeMore
|
||||
}
|
||||
noStyle
|
||||
>
|
||||
{({ getFieldValue }) => (
|
||||
<EvaluateTemplateTable
|
||||
disableType={getFieldValue('indicatorTypeMore')}
|
||||
firstIsAdd={getFieldValue('indicatorStMore') === IndicatorAddOption.CAN_ADD}
|
||||
onChange={handleTemplateDataChange}
|
||||
value={templateData}
|
||||
/>
|
||||
)}
|
||||
</Form.Item>
|
||||
</Card>
|
||||
</Spin>
|
||||
|
||||
|
Reference in New Issue
Block a user