Initial commit

This commit is contained in:
linxd
2025-06-17 14:20:06 +08:00
commit 08424ecdb8
112 changed files with 26341 additions and 0 deletions

View File

@ -0,0 +1,226 @@
// 供应商注册
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 { coscoSupplierBaseAdd, fetchSurveyQuestions } from '@/servers/api/register';
import './register.less';
const SupplierRegister: React.FC = () => {
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(() => {
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 onFinish = async (values: any) => {
setLoading(true);
try {
// 确保供应商类型添加到表单值中
values.coscoSupplierBase = values.coscoSupplierBase || {};
values.coscoSupplierBase.supplierType = supplierType;
console.log('供应商注册信息:', values);
// 直接调用API
const response = await coscoSupplierBaseAdd(values);
if (response.success) {
message.success('注册成功,请登录');
history.push('/login');
} 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 ">
<div className="register-container large-width">
<div className="back-home">
<a onClick={() => history.push('/index')}>
<HomeOutlined /> {intl.formatMessage({ id: 'login.back.home' })}
</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}
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>
</Radio.Group>
</Form.Item>
{supplierType === 'dvs' ? (
<DomesticForm
form={form}
countdown={countdown}
surveyQuestions={surveyQuestions}
handleGetCaptcha={handleGetCaptcha}
/>
) : (
<ForeignForm
form={form}
countdown={countdown}
handleGetCaptcha={handleGetCaptcha}
surveyQuestions={surveyQuestions}
/>
)}
<Form.Item
name="agreement"
valuePropName="checked"
labelCol={{ span: 2 }}
wrapperCol={{ span: 19 }}
rules={[
{
validator: (_, value) =>
value
? Promise.resolve()
: Promise.reject(new Error('请阅读并同意注册信息承诺书')),
},
]}
>
<Checkbox>
<Button
type="link"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setModalVisible(true);
}}
>
</Button>
</Checkbox>
</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;