import React, {useState} from 'react'; import { Form, Input, Select, Button, Spin, message } from 'antd'; const { Option } = Select; import { useLocation } from 'umi'; import {createContract, updateContract} from "./ContractService"; import {history} from "@@/core/history"; // 模拟行业选项 const industryOptions = [ { label: '制造业', value:'0' }, { label: '服务业', value:'service' }, { label: '零售业', value:'retail' }, ]; const StepOne: React.FC = () => { const [form] = Form.useForm(); let readOnly = false; const location = useLocation(); const contractType = location.state?.contractType; const contractInfo = location.state?.contractInfo; const opt = location.state?.opt; const [loading, setLoading] = useState(false); if(opt){ form.setFieldsValue({ ...contractInfo }); if(opt === 'detail'){ readOnly = true; }else if (opt ==='edit'){ readOnly = false; } } // 表单提交处理函数 const onFinish = (values: any) => { values.contractType = contractType; if(opt === 'detail'){ history.push({ pathname: '/stepTwo', state: { contractInfo: contractInfo, opt: opt } }); }else{ try { if (values.id) { setLoading(true) updateContract(values).then((res: any) => { if(res.code === 200){ // message.success("当前数据更新成功").then(() => { history.push({ pathname: '/stepTwo', state: { contractInfo: res.data, opt: opt } }); // }).then( () => { setLoading(false) // }) }else { message.error('更新失败'); } }) } else { createContract(values).then( (res: any) => { if(res.code === 200){ history.push({ pathname: '/stepTwo', state: { contractInfo: res.data } }); }else { message.error('更新失败'); } }); } } catch (error) { message.error(error.message || '操作失败'); } } }; // @ts-ignore const validateCreditCode = (value: string) => { // 基本格式校验 if (!value || value.length !== 18) { return '统一社会信用代码必须为18位'; } // 正则校验(允许数字和大写字母,不包括I、O、Z、S、V) const pattern = /^[0-9A-HJ-NPQRTUWXY]{18}$/; if (!pattern.test(value)) { return '统一社会信用代码格式不正确'; } // 校验码计算 const weightFactor = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28]; const codePoint = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'J': 18, 'K': 19, 'L': 20, 'M': 21, 'N': 22, 'P': 23, 'Q': 24, 'R': 25, 'T': 26, 'U': 27, 'W': 28, 'X': 29, 'Y': 30 }; const checkCodeDict = { 0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F', 16: 'G', 17: 'H', 18: 'J', 19: 'K', 20: 'L', 21: 'M', 22: 'N', 23: 'P', 24: 'Q', 25: 'R', 26: 'T', 27: 'U', 28: 'W', 29: 'X', 30: 'Y' }; let sum = 0; for (let i = 0; i < 17; i++) { sum += codePoint[value[i]] * weightFactor[i]; } const mod = sum % 31; const checkCode = checkCodeDict[mod]; if (checkCode !== value[17]) { return '统一社会信用代码校验位不正确'; } return null; // 校验通过 }; // 表单提交失败处理函数 const onFinishFailed = (errorInfo: any) => { // console.log('Form submission failed:', errorInfo); message.error('表单提交失败,请检查输入'); }; return (
{/* 添加全局遮罩 */} {loading && ( )}
{/* 项目基本信息部分 */}
基本信息
{/* 我方签约主体信息部分 */}
我方签约主体信息
({ // validator(rule, value) { // const errorMessage = validateCreditCode(value); // if (errorMessage) { // return Promise.reject(errorMessage); // } // return Promise.resolve(); // }, // }) ]} style={{ width: '50%', marginRight: 16 }} >
{/* 对方签约主体信息部分 */}
对方签约主体信息
({ // validator(rule, value) { // const errorMessage = validateCreditCode(value); // if (errorMessage) { // return Promise.reject(errorMessage); // } // return Promise.resolve(); // }, // }) ]} style={{ width: '45%' }} >
{/**/} {/* */} {/**/}
{/* 居中显示的下一步按钮 */}
); }; export default StepOne;