Files
fe_supplier_frontend/src/pages/register/supplier.tsx
2025-07-17 09:16:22 +08:00

283 lines
9.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 供应商注册
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';
import Person from './supplier/Person';
import { addAgent, coscoSupplierBaseAdd, fetchSurveyQuestions } from '@/servers/api/register';
import './register.less';
interface supplierWithInputProps {
supplierWithInput?: Boolean;
exitId?: string;
onOk?: () => void;
}
const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
const { supplierWithInput = false, exitId = '', onOk } = props;
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(() => {
//供应商带录入
if (supplierWithInput) {
}
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('请先输入正确的手机号');
});
};
const onFinishFailed = (errorInfo: any) => {
console.log('Failed:', errorInfo);
};
const onFinish = async (values: any) => {
setLoading(true);
try {
// 确保供应商类型添加到表单值中
values.coscoSupplierBase = values.coscoSupplierBase || {};
values.coscoSupplierBase.supplierType = supplierType;
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,
}]
}
console.log('供应商注册信息:', values);
// 直接调用API supplierWithInput === true 供应商注册代录 否则 注册 accessory
const response = await (supplierWithInput ? addAgent(values) : coscoSupplierBaseAdd(values));
if (response.success) {
if (!supplierWithInput) {
message.success('注册成功,请登录');
history.push('/login');
} else {
message.success(`${exitId ? '修改成功' : '注册成功'}`);
onOk?.();
}
} 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 (
<div className={`register-page ${supplierWithInput ? ' on' : ''}`}>
<div className="register-container large-width">
{!supplierWithInput && (
<>
<div className="back-home">
<a onClick={() => history.push('/login')}>
<HomeOutlined />
</a>
</div>
<div className="register-title">
{intl.formatMessage({ id: 'register.supplier.title' })}
</div>
</>
)}
<Spin spinning={fetchingQuestions}>
<Form
form={form}
name="supplier_register"
className="register-form"
onFinish={onFinish}
onFinishFailed={onFinishFailed}
layout="horizontal"
labelAlign="right"
size="large"
labelCol={{ span: 7 }}
wrapperCol={{ span: 17 }}
>
<Form.Item label="境内/境外" labelCol={{ span: 2 }} wrapperCol={{ span: 19 }}>
<Radio.Group onChange={handleSupplierTypeChange} buttonStyle="solid" value={supplierType}>
<Radio.Button value="dvs">/</Radio.Button>
<Radio.Button value="ovs"></Radio.Button>
{supplierWithInput && (
<Radio.Button value="pe"></Radio.Button>
)}
</Radio.Group>
</Form.Item>
{supplierType === 'dvs' ? (
<DomesticForm
form={form}
countdown={countdown}
surveyQuestions={surveyQuestions}
handleGetCaptcha={handleGetCaptcha}
/>
) : supplierType === 'ovs' ? (
<ForeignForm
form={form}
countdown={countdown}
handleGetCaptcha={handleGetCaptcha}
surveyQuestions={surveyQuestions}
/>
) : (
<Person
form={form}
countdown={countdown}
handleGetCaptcha={handleGetCaptcha}
surveyQuestions={surveyQuestions}
/>
)}
{supplierType !== 'pe' && (
<Form.Item
name="agreement"
valuePropName="checked"
wrapperCol={{ span: 24 }}
rules={[
{
validator: (_, value) =>
value
? Promise.resolve()
: Promise.reject(new Error('请阅读并同意注册信息承诺书')),
},
]}
>
<div style={{ textAlign: 'center' }}>
<Checkbox>
<Button
type="link"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setModalVisible(true);
}}
>
</Button>
</Checkbox>
</div>
</Form.Item>
)}
<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
// maskClosable={false}
>
<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;