diff --git a/src/pages/supplierAnnualManage/supplierAnnualTaskManage/components/BasicInfoStep.tsx b/src/pages/supplierAnnualManage/supplierAnnualTaskManage/components/BasicInfoStep.tsx index bf12296..3bddf08 100644 --- a/src/pages/supplierAnnualManage/supplierAnnualTaskManage/components/BasicInfoStep.tsx +++ b/src/pages/supplierAnnualManage/supplierAnnualTaskManage/components/BasicInfoStep.tsx @@ -1,8 +1,8 @@ import React, { useState, useEffect, useCallback, forwardRef, useImperativeHandle } from 'react'; -import { Form, Input, Select, DatePicker, Row, Col, Card, Radio } from 'antd'; +import { Form, Input, Select, DatePicker, Row, Col, Card, Radio, message } from 'antd'; import moment from 'moment'; import { useIntl, FormattedMessage } from 'umi'; -import { getAllAnnualTemplates } from '@/servers/api/supplierAnnual'; +import { getAllAnnualTemplates,getAnnualTemplateDetail } from '@/servers/api/supplierAnnual'; import CategorySelector from '@/components/CategorySelector'; import styles from '../supplierAnnualTaskManageAdd.less'; import { CategoryLimitationType } from '@/dicts/supplierTemplateDict'; @@ -83,17 +83,35 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { }); }; + // 监听表单里 categoryLimitation 的当前值 判断是否显示品类选择器 + const categoryLimitation = Form.useWatch('categoryLimitation', form); + const showCategorySelector = categoryLimitation === CategoryLimitationType.LIMITED; - // 判断是否显示品类选择器 - const shouldShowCategorySelector = useCallback(() => { - const categoryLimitation = taskFormData.categoryLimitation; - return categoryLimitation === CategoryLimitationType.LIMITED; - }, [taskFormData]); - + // 处理模板选择 将模板的是否限制品类,和品类id赋值 + const handleTemplateSelect = async (templateId: string) => { + const res = await getAnnualTemplateDetail(templateId); + if (res.success && res.data) { + // 更新表单数据 + const formValues = { + ...taskFormData, + categoryLimitation: res.data.categoryLimitation || CategoryLimitationType.UNIVERSAL, + categoryId: res.data.categoryId, + }; + form.setFieldsValue(formValues); + } else { + message.error( + intl.formatMessage({ id: 'supplierTemplateManage.message.getDetailFailed' }) || res.message, + ); + } + }; return (
- +
{ - + @@ -121,11 +144,13 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { value: value ? moment(value) : undefined, })} normalize={(value) => value && value.format('YYYY')} - rules={[{ required: true, message: "请选择年审年份" }]} + rules={[{ required: true, message: '请选择年审年份' }]} > - @@ -137,7 +162,7 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { ({ value: value ? moment(value) : undefined, })} @@ -146,7 +171,9 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { @@ -154,7 +181,7 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { ({ value: value ? moment(value) : undefined, })} @@ -163,7 +190,9 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { @@ -172,9 +201,18 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { @@ -186,12 +224,21 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { - {shouldShowCategorySelector() && ( + {showCategorySelector && ( @@ -202,15 +249,27 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { + @@ -125,11 +156,20 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { value: value ? moment(value) : undefined, })} normalize={(value) => value && value.format('YYYY')} - rules={[{ required: true, message: intl.formatMessage({ id: 'supplierTaskManage.placeholder.selectYear' }) }]} + rules={[ + { + required: true, + message: intl.formatMessage({ + id: 'supplierTaskManage.placeholder.selectYear', + }), + }, + ]} > @@ -141,26 +181,44 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { ({ value: value ? moment(value) : undefined, })} normalize={(value) => value && value.format('YYYY-MM-DD')} > - + ({ value: value ? moment(value) : undefined, })} normalize={(value) => value && value.format('YYYY-MM-DD')} > - + @@ -170,7 +228,14 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { @@ -182,12 +247,17 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { - {shouldShowCategorySelector() && ( + {showCategorySelector && ( @@ -200,9 +270,22 @@ const BasicInfoStepComponent = (props: BasicInfoStepProps) => { - {templates.map((template) => (