|
|
@ -4,10 +4,9 @@ import { Form, Input, Select, DatePicker, Space, ColProps, Button, Cascader, Def |
|
|
|
import type { FormProps, FormInstance } from 'antd'; |
|
|
|
import type { FormProps, FormInstance } from 'antd'; |
|
|
|
import ESBreadcrumbComponent from './ESBreadcrumbComponent'; // 引入面包屑组件
|
|
|
|
import ESBreadcrumbComponent from './ESBreadcrumbComponent'; // 引入面包屑组件
|
|
|
|
import { withRouter, RouteComponentProps } from 'react-router-dom'; // 引入 withRouter 和 RouteComponentProps
|
|
|
|
import { withRouter, RouteComponentProps } from 'react-router-dom'; // 引入 withRouter 和 RouteComponentProps
|
|
|
|
import { add, getIndustryList, getPaperListWithDetails } from "api/exam-online/index"; // 修改接口为获取带详情的试卷列表
|
|
|
|
import { save, getIndustryList, getPaperListWithDetails } from "api/exam-online/index"; // 修改接口为获取带详情的试卷列表
|
|
|
|
import { provice } from './city.js'; // 引入省市县数据
|
|
|
|
import { provice } from './city.js'; // 引入省市县数据
|
|
|
|
import moment, { Moment } from 'moment'; |
|
|
|
import moment, { Moment } from 'moment'; |
|
|
|
import TextArea from "antd/es/input/TextArea"; // 引入 moment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { Option } = Select; |
|
|
|
const { Option } = Select; |
|
|
|
|
|
|
|
|
|
|
@ -15,6 +14,7 @@ const { Option } = Select; |
|
|
|
export interface ExamBasicInfo { |
|
|
|
export interface ExamBasicInfo { |
|
|
|
examId: string; |
|
|
|
examId: string; |
|
|
|
examName: string; |
|
|
|
examName: string; |
|
|
|
|
|
|
|
industryId: string | number; |
|
|
|
regulatedIndustry: string | number; |
|
|
|
regulatedIndustry: string | number; |
|
|
|
paperId: string; |
|
|
|
paperId: string; |
|
|
|
examScore: string; |
|
|
|
examScore: string; |
|
|
@ -78,10 +78,16 @@ const convertArrToRegion = (regionArr: string[]) => { |
|
|
|
return regionArr.join('/'); |
|
|
|
return regionArr.join('/'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface industryObj { |
|
|
|
|
|
|
|
value: any; |
|
|
|
|
|
|
|
label: any; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ExamBasicInfoForm: React.FC<PropsWithRouter> = (props) => { |
|
|
|
const ExamBasicInfoForm: React.FC<PropsWithRouter> = (props) => { |
|
|
|
const { isEdit, initialFormData = {} as ExamBasicInfo, history } = props; |
|
|
|
const { isEdit, initialFormData = {} as ExamBasicInfo, history } = props; |
|
|
|
const formRef = useRef<FormInstance<ExamBasicInfo>>(null); |
|
|
|
const formRef = useRef<FormInstance<ExamBasicInfo>>(null); |
|
|
|
const [industryOptions, setIndustryOptions] = useState<{ value: string | number; label: string }[]>([]); |
|
|
|
// const [industryOptions, setIndustryOptions] = useState<{ value: string | number; label: string }[]>([]);
|
|
|
|
|
|
|
|
const [industryOptions, setIndustryOptions] = useState<industryObj[]>([]); |
|
|
|
const [allPaperOptions, setAllPaperOptions] = useState<{ value: string; label: string; examScore: string; examDuration: string; regulatedIndustry: string | number }[]>([]); |
|
|
|
const [allPaperOptions, setAllPaperOptions] = useState<{ value: string; label: string; examScore: string; examDuration: string; regulatedIndustry: string | number }[]>([]); |
|
|
|
const [paperOptions, setPaperOptions] = useState<{ value: string; label: string; examScore: string; examDuration: string }[]>([]); |
|
|
|
const [paperOptions, setPaperOptions] = useState<{ value: string; label: string; examScore: string; examDuration: string }[]>([]); |
|
|
|
const [isDataLoaded, setIsDataLoaded] = useState(false); |
|
|
|
const [isDataLoaded, setIsDataLoaded] = useState(false); |
|
|
@ -95,13 +101,14 @@ const ExamBasicInfoForm: React.FC<PropsWithRouter> = (props) => { |
|
|
|
const formattedValidTo = formatDate(validTo); |
|
|
|
const formattedValidTo = formatDate(validTo); |
|
|
|
const formattedValues = { |
|
|
|
const formattedValues = { |
|
|
|
...otherValues, |
|
|
|
...otherValues, |
|
|
|
|
|
|
|
id:values.examId, |
|
|
|
examRegion: formattedRegion, |
|
|
|
examRegion: formattedRegion, |
|
|
|
validFrom: formattedValidFrom, |
|
|
|
validFrom: formattedValidFrom, |
|
|
|
validTo: formattedValidTo |
|
|
|
validTo: formattedValidTo |
|
|
|
}; |
|
|
|
}; |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 调用 add 方法将数据发送到后台
|
|
|
|
// 调用 save 方法将数据发送到后台
|
|
|
|
const response = await add(formattedValues); |
|
|
|
const response = await save(formattedValues); |
|
|
|
console.log('数据登录成功:', response); |
|
|
|
console.log('数据登录成功:', response); |
|
|
|
// 登录成功后迁移到 /exam-schedule 页面
|
|
|
|
// 登录成功后迁移到 /exam-schedule 页面
|
|
|
|
history.push("/exam-schedule"); |
|
|
|
history.push("/exam-schedule"); |
|
|
@ -139,77 +146,82 @@ const ExamBasicInfoForm: React.FC<PropsWithRouter> = (props) => { |
|
|
|
const fetchData = async () => { |
|
|
|
const fetchData = async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 获取监管行业列表
|
|
|
|
// 获取监管行业列表
|
|
|
|
const industryResponse = await getIndustryList(); |
|
|
|
let industryResponse = await getIndustryList(); |
|
|
|
setIndustryOptions(industryResponse.map((item: any) => ({ value: item.industry_id, label: item.industry_name }))); |
|
|
|
let industryOptionsArray = industryResponse.map((item: any) => ({ value: item.industry_id, label: item.industry_name })); |
|
|
|
|
|
|
|
setIndustryOptions(industryOptionsArray); |
|
|
|
|
|
|
|
|
|
|
|
// 获取带详情的试卷列表
|
|
|
|
// 获取带详情的试卷列表
|
|
|
|
const paperResponse = await getPaperListWithDetails(); |
|
|
|
const paperResponse = await getPaperListWithDetails(); |
|
|
|
setAllPaperOptions(paperResponse.map((item: any) => ({ |
|
|
|
let allPaperOptionsArray = paperResponse.map((item: any) => ({ |
|
|
|
value: item.paper_id, |
|
|
|
value: item.paper_id, |
|
|
|
label: item.paper_name, |
|
|
|
label: item.paper_name, |
|
|
|
examScore: item.total_score, |
|
|
|
examScore: item.total_score, |
|
|
|
examDuration: item.exam_duration, |
|
|
|
examDuration: item.exam_duration, |
|
|
|
regulatedIndustry: item.regulatory_industry // 假设接口返回的试卷数据包含监管行业信息
|
|
|
|
regulatedIndustry: item.regulatory_industry |
|
|
|
}))); |
|
|
|
})) |
|
|
|
|
|
|
|
setAllPaperOptions(allPaperOptionsArray); |
|
|
|
|
|
|
|
|
|
|
|
setIsDataLoaded(true); |
|
|
|
setIsDataLoaded(true); |
|
|
|
|
|
|
|
const initialIndustry = initialFormData.industryId; |
|
|
|
|
|
|
|
if (String(initialIndustry) === '') { |
|
|
|
|
|
|
|
setPaperOptions(allPaperOptionsArray); |
|
|
|
|
|
|
|
} else if (initialIndustry) { |
|
|
|
|
|
|
|
const filteredPapers = allPaperOptionsArray.filter((paper: { regulatedIndustry: any; }) => String(paper.regulatedIndustry) === String(initialIndustry)); |
|
|
|
|
|
|
|
setPaperOptions(filteredPapers); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setPaperOptions(allPaperOptionsArray); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (formRef.current) { |
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ |
|
|
|
|
|
|
|
examId: initialFormData.examId || '', |
|
|
|
|
|
|
|
examName: initialFormData.examName || '', |
|
|
|
|
|
|
|
examRegion: typeof initialFormData.examRegion === "string" ? convertRegionToArr(initialFormData.examRegion) : initialFormData.examRegion, |
|
|
|
|
|
|
|
validFrom: initialFormData.validFrom || null, |
|
|
|
|
|
|
|
validTo: initialFormData.validTo || null, |
|
|
|
|
|
|
|
remark: initialFormData.remark || '', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
// 设置监管行业的值
|
|
|
|
|
|
|
|
const selectedIndustry = industryOptionsArray.find((option: { value: any; }) => String(option.value) === String(initialFormData.industryId)); |
|
|
|
|
|
|
|
if (selectedIndustry) { |
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ regulatedIndustry: selectedIndustry.value }); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ regulatedIndustry: '' }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置试卷名称
|
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ paperId: initialFormData.paperId || '' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 触发 handlePaperChange 函数更新考试分值和考试时长
|
|
|
|
|
|
|
|
const selectedPaper = allPaperOptionsArray.find((paper: { value: any; }) => String(paper.value) === String(initialFormData.paperId)); |
|
|
|
|
|
|
|
if (selectedPaper && formRef.current) { |
|
|
|
|
|
|
|
// 更新表单中的考试分值和考试时长
|
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ |
|
|
|
|
|
|
|
examScore: selectedPaper.examScore, |
|
|
|
|
|
|
|
examDuration: selectedPaper.examDuration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
console.error('数据加载失败:', error); |
|
|
|
console.error('数据加载失败:', error); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
fetchData() |
|
|
|
|
|
|
|
|
|
|
|
fetchData(); |
|
|
|
|
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (isDataLoaded) { |
|
|
|
|
|
|
|
const initialIndustry = initialFormData.regulatedIndustry; |
|
|
|
|
|
|
|
if (String(initialIndustry) === '') { |
|
|
|
|
|
|
|
setPaperOptions(allPaperOptions); |
|
|
|
|
|
|
|
} else if (initialIndustry) { |
|
|
|
|
|
|
|
const filteredPapers = allPaperOptions.filter(paper => String(paper.regulatedIndustry) === String(initialIndustry)); |
|
|
|
|
|
|
|
setPaperOptions(filteredPapers); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setPaperOptions(allPaperOptions); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (formRef.current) { |
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ |
|
|
|
|
|
|
|
examId: initialFormData.examId || '', |
|
|
|
|
|
|
|
examName: initialFormData.examName || '', |
|
|
|
|
|
|
|
examRegion: typeof initialFormData.examRegion === "string" ? convertRegionToArr(initialFormData.examRegion) : initialFormData.examRegion, |
|
|
|
|
|
|
|
validFrom: initialFormData.validFrom || null, |
|
|
|
|
|
|
|
validTo: initialFormData.validTo || null, |
|
|
|
|
|
|
|
remark: initialFormData.remark || '', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置监管行业的值
|
|
|
|
|
|
|
|
const selectedIndustry = industryOptions.find(option => String(option.value) === String(initialFormData.regulatedIndustry)); |
|
|
|
|
|
|
|
if (selectedIndustry) { |
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ regulatedIndustry: selectedIndustry.value }); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ regulatedIndustry: '' }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置试卷名称
|
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ paperId: initialFormData.paperId || '' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 触发 handlePaperChange 函数更新考试分值和考试时长
|
|
|
|
|
|
|
|
handlePaperChange(initialFormData.paperId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [isDataLoaded, allPaperOptions, initialFormData, industryOptions]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleIndustryChange = (value: string | number) => { |
|
|
|
const handleIndustryChange = (value: string | number) => { |
|
|
|
if (String(value) === '') { |
|
|
|
if (String(value) === '') { |
|
|
|
setPaperOptions(allPaperOptions); |
|
|
|
setPaperOptions(allPaperOptions); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const filteredPapers = allPaperOptions.filter(paper => String(paper.regulatedIndustry) === String(value)); |
|
|
|
const filteredPapers = allPaperOptions.filter(paper => String(paper.regulatedIndustry) === String(value)); |
|
|
|
setPaperOptions(filteredPapers); |
|
|
|
if (filteredPapers.length > 0) { |
|
|
|
} |
|
|
|
setPaperOptions(filteredPapers); |
|
|
|
if (formRef.current) { |
|
|
|
} |
|
|
|
formRef.current.setFieldsValue({ paperId: '' }); // 清空试卷选择
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
formRef.current.setFieldsValue({ paperId: '' }); // 清空试卷选择
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handlePaperChange = (value: string) => { |
|
|
|
const handlePaperChange = (value: string) => { |
|
|
|