import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Button, Form, Input, message, Space } from 'antd';
import {
CheckCircleFilled,
FileSearchOutlined,
LoadingOutlined,
SafetyCertificateFilled
} from '@ant-design/icons';
import './index.css';
import { materialFields, materialInitialValues, mockSubmitMaterial } from './mockData';
const steps = [
{ key: 1, title: '填写信息' },
{ key: 2, title: '认证审核中' },
{ key: 3, title: '认证通过' }
];
function PageHeader() {
return (
);
}
function StepHeader({ current }) {
return (
{steps.map((step, index) => {
const active = current >= step.key;
const currentStep = current === step.key;
return (
{step.key}
{step.title}
{index < steps.length - 1 && }
);
})}
);
}
function FieldItem({ field }) {
const labelLines = field.label.split('\n');
return (
{labelLines.map((line) => {line}
)}
)}
rules={field.span === 24 ? [{ required: true, message: `请输入${labelLines[0]}` }] : undefined}
>
);
}
function FillStep({ onSubmitted }) {
const [form] = Form.useForm();
const [submitting, setSubmitting] = useState(false);
const groupedRows = useMemo(() => {
const rows = [];
let current = [];
let used = 0;
materialFields.forEach((field) => {
if (field.span === 24) {
if (current.length) rows.push(current);
rows.push([field]);
current = [];
used = 0;
return;
}
if (used + field.span > 24) {
rows.push(current);
current = [];
used = 0;
}
current.push(field);
used += field.span;
});
if (current.length) rows.push(current);
return rows;
}, []);
const handleSubmit = async () => {
try {
const values = await form.validateFields();
setSubmitting(true);
const res = await mockSubmitMaterial(values);
if (res?.success) {
message.success('提交成功,正在进入认证审核');
onSubmitted(res.data);
}
}
catch (err) {
if (!err?.errorFields) {
message.error('提交失败,请稍后重试');
}
}
finally {
setSubmitting(false);
}
};
return (
);
}
function ReviewLoadingStep() {
return (
);
}
function ReviewSuccessStep() {
return (
);
}
export default function MaterialReportPage() {
const [current, setCurrent] = useState(1);
const timerRef = useRef(null);
useEffect(() => () => clearTimeout(timerRef.current), []);
const handleSubmitted = () => {
setCurrent(2);
clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => {
setCurrent(3);
}, 2300);
};
return (
{current === 1 &&
}
{current === 2 &&
}
{current === 3 &&
}
);
}