Files
fe_supplier_frontend/src/pages/register/supplier.tsx

283 lines
9.7 KiB
TypeScript
Raw Normal View History

2025-06-17 14:20:06 +08:00
// 供应商注册
import React, { useState, useEffect } from 'react';
import { useIntl, history } from 'umi';
import { Form, Button, message, Radio, Checkbox, Modal, Spin } from 'antd';
import { HomeOutlined } from '@ant-design/icons';
import DomesticForm from './supplier/DomesticForm';
import ForeignForm from './supplier/ForeignForm';
2025-07-09 14:01:45 +08:00
import Person from './supplier/Person';
2025-07-04 10:15:56 +08:00
import { addAgent, coscoSupplierBaseAdd, fetchSurveyQuestions } from '@/servers/api/register';
2025-06-17 14:20:06 +08:00
import './register.less';
2025-07-04 10:15:56 +08:00
interface supplierWithInputProps {
supplierWithInput?: Boolean;
exitId?: string;
onOk?: () => void;
}
const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
const { supplierWithInput = false, exitId = '', onOk } = props;
2025-06-17 14:20:06 +08:00
const [form] = Form.useForm();
const intl = useIntl();
const [supplierType, setSupplierType] = useState<string>('dvs');
const [loading, setLoading] = useState(false);
const [countdown, setCountdown] = useState(0);
const [modalVisible, setModalVisible] = useState(false);
const [surveyQuestions, setSurveyQuestions] = useState<API.SurveyQuestionResponse>([]);
const [fetchingQuestions, setFetchingQuestions] = useState(false);
// 获取问卷列表
useEffect(() => {
2025-07-04 10:15:56 +08:00
//供应商带录入
if (supplierWithInput) {
}
2025-06-17 14:20:06 +08:00
const fetchQuestions = async () => {
setFetchingQuestions(true);
try {
const response = await fetchSurveyQuestions();
if (response.success) {
setSurveyQuestions(response.data || []);
} else {
message.error(response.message || '获取问卷列表失败');
}
} catch (error) {
console.error('获取问卷列表出错:', error);
message.error('获取问卷列表出错');
} finally {
setFetchingQuestions(false);
}
};
fetchQuestions();
}, []);
// 获取短信验证码
const handleGetCaptcha = () => {
form
.validateFields(['contactPhone'])
.then((values) => {
message.success(`验证码已发送至 ${values.contactPhone}`);
let count = 60;
setCountdown(count);
const timer = setInterval(() => {
count--;
setCountdown(count);
if (count === 0) {
clearInterval(timer);
}
}, 1000);
})
.catch((errorInfo) => {
message.error('请先输入正确的手机号');
});
};
2025-07-15 10:02:33 +08:00
const onFinishFailed = (errorInfo: any) => {
console.log('Failed:', errorInfo);
};
2025-06-17 14:20:06 +08:00
const onFinish = async (values: any) => {
setLoading(true);
try {
// 确保供应商类型添加到表单值中
values.coscoSupplierBase = values.coscoSupplierBase || {};
values.coscoSupplierBase.supplierType = supplierType;
2025-07-09 14:01:45 +08:00
if(supplierType === 'pe') {
values.coscoSupplierBase.personName = values.coscoSupplierBase.name;
values.coscoSupplierBase.personPhone = values.coscoSupplierBase.contactPhone;
values.coscoSupplierSurveyAttachments = [{
attachmentsType: "accessory",
fileName: values.attachments.file.response.fileName,
fileType: values.attachments.file.response.fileType,
fileSize: values.attachments.file.response.fileSize,
filePath: values.attachments.file.response.filePath,
fileUrl: values.attachments.file.response.filePath,
}]
}
2025-06-17 14:20:06 +08:00
console.log('供应商注册信息:', values);
2025-07-09 14:01:45 +08:00
// 直接调用API supplierWithInput === true 供应商注册代录 否则 注册 accessory
2025-06-17 14:20:06 +08:00
2025-07-09 14:01:45 +08:00
const response = await (supplierWithInput ? addAgent(values) : coscoSupplierBaseAdd(values));
2025-06-17 14:20:06 +08:00
if (response.success) {
2025-07-09 14:01:45 +08:00
if (!supplierWithInput) {
2025-07-04 10:15:56 +08:00
message.success('注册成功,请登录');
history.push('/login');
} else {
2025-07-09 14:01:45 +08:00
message.success(`${exitId ? '修改成功' : '注册成功'}`);
onOk?.();
2025-07-04 10:15:56 +08:00
}
2025-06-17 14:20:06 +08:00
} else {
message.error(response.message || '注册失败,请重试');
}
} catch (error) {
console.error('注册出错:', error);
message.error('注册失败,请稍后重试');
} finally {
setLoading(false);
}
};
const handleSupplierTypeChange = (e: any) => {
form.resetFields();
setSupplierType(e.target.value);
};
return (
2025-07-04 10:15:56 +08:00
<div className={`register-page ${supplierWithInput ? ' on' : ''}`}>
2025-06-17 14:20:06 +08:00
<div className="register-container large-width">
2025-07-04 10:15:56 +08:00
{!supplierWithInput && (
<>
<div className="back-home">
2025-07-11 08:33:29 +08:00
<a onClick={() => history.push('/login')}>
<HomeOutlined />
2025-07-04 10:15:56 +08:00
</a>
</div>
<div className="register-title">
{intl.formatMessage({ id: 'register.supplier.title' })}
</div>
</>
)}
2025-06-17 14:20:06 +08:00
<Spin spinning={fetchingQuestions}>
<Form
form={form}
name="supplier_register"
className="register-form"
onFinish={onFinish}
2025-07-15 10:02:33 +08:00
onFinishFailed={onFinishFailed}
2025-06-17 14:20:06 +08:00
layout="horizontal"
labelAlign="right"
size="large"
labelCol={{ span: 7 }}
wrapperCol={{ span: 17 }}
>
2025-07-17 09:16:22 +08:00
<Form.Item label="境内/境外" labelCol={{ span: 2 }} wrapperCol={{ span: 19 }}>
2025-06-17 14:20:06 +08:00
<Radio.Group onChange={handleSupplierTypeChange} buttonStyle="solid" value={supplierType}>
<Radio.Button value="dvs">/</Radio.Button>
<Radio.Button value="ovs"></Radio.Button>
2025-07-09 14:01:45 +08:00
{supplierWithInput && (
<Radio.Button value="pe"></Radio.Button>
)}
2025-06-17 14:20:06 +08:00
</Radio.Group>
</Form.Item>
2025-07-09 14:01:45 +08:00
2025-06-17 14:20:06 +08:00
{supplierType === 'dvs' ? (
<DomesticForm
form={form}
countdown={countdown}
surveyQuestions={surveyQuestions}
handleGetCaptcha={handleGetCaptcha}
/>
2025-07-09 14:01:45 +08:00
) : supplierType === 'ovs' ? (
2025-06-17 14:20:06 +08:00
<ForeignForm
form={form}
countdown={countdown}
handleGetCaptcha={handleGetCaptcha}
surveyQuestions={surveyQuestions}
/>
2025-07-09 14:01:45 +08:00
) : (
<Person
form={form}
countdown={countdown}
handleGetCaptcha={handleGetCaptcha}
surveyQuestions={surveyQuestions}
/>
2025-06-17 14:20:06 +08:00
)}
2025-07-09 14:01:45 +08:00
{supplierType !== 'pe' && (
<Form.Item
name="agreement"
valuePropName="checked"
2025-07-16 14:10:34 +08:00
wrapperCol={{ span: 24 }}
2025-07-09 14:01:45 +08:00
rules={[
{
validator: (_, value) =>
value
? Promise.resolve()
: Promise.reject(new Error('请阅读并同意注册信息承诺书')),
},
]}
>
2025-07-16 14:10:34 +08:00
<div style={{ textAlign: 'center' }}>
2025-07-09 14:01:45 +08:00
<Checkbox>
<Button
type="link"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setModalVisible(true);
}}
>
</Button>
</Checkbox>
2025-07-16 14:10:34 +08:00
</div>
2025-07-09 14:01:45 +08:00
</Form.Item>
)}
2025-06-17 14:20:06 +08:00
<Form.Item wrapperCol={{ span: 24 }}>
<div style={{ textAlign: 'center' }}>
<Button type="primary" htmlType="submit" loading={loading}>
{intl.formatMessage({ id: 'register.submit' })}
</Button>
</div>
</Form.Item>
</Form>
</Spin>
</div>
{/* 注册信息承诺书弹窗 */}
<Modal
title="注册信息承诺书"
visible={modalVisible}
onOk={() => {
console.log('点击了确定按钮');
setModalVisible(false);
}}
onCancel={() => {
console.log('点击了取消按钮');
setModalVisible(false);
}}
width={700}
okText="我知道了"
cancelButtonProps={{ style: { display: 'none' } }}
destroyOnClose
2025-07-04 10:15:56 +08:00
// maskClosable={false}
2025-06-17 14:20:06 +08:00
>
<div style={{ maxHeight: '60vh', overflow: 'auto' }}>
<p></p>
<p>使</p>
<ol>
<li>
/
</li>
<li>/</li>
<li>
/
</li>
<li>/</li>
<li>/使</li>
<li>
/
</li>
<li>/</li>
<li>/</li>
</ol>
<p></p>
</div>
</Modal>
</div>
);
};
export default SupplierRegister;