2025-10-24 16:19:58 +03:00
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
import { Steps, Card, message } from 'antd';
|
2025-10-24 20:40:44 +03:00
|
|
|
|
import Step1Policy from '../components/form/Step1Policy';
|
2025-10-24 16:19:58 +03:00
|
|
|
|
import Step2Details from '../components/form/Step2Details';
|
|
|
|
|
|
import Step3Payment from '../components/form/Step3Payment';
|
|
|
|
|
|
import './ClaimForm.css';
|
|
|
|
|
|
|
|
|
|
|
|
const { Step } = Steps;
|
|
|
|
|
|
|
|
|
|
|
|
interface FormData {
|
|
|
|
|
|
// Шаг 1
|
2025-10-24 20:54:57 +03:00
|
|
|
|
voucher: string; // Полис вида E1000-302538524
|
|
|
|
|
|
email: string; // Email обязателен
|
2025-10-24 16:19:58 +03:00
|
|
|
|
|
|
|
|
|
|
// Шаг 2
|
|
|
|
|
|
incidentDate?: string;
|
|
|
|
|
|
incidentDescription?: string;
|
|
|
|
|
|
transportType?: string;
|
|
|
|
|
|
uploadedFiles?: string[];
|
|
|
|
|
|
|
|
|
|
|
|
// Шаг 3
|
2025-10-24 20:54:57 +03:00
|
|
|
|
phone: string;
|
2025-10-24 16:19:58 +03:00
|
|
|
|
paymentMethod: string;
|
|
|
|
|
|
bankName?: string;
|
|
|
|
|
|
cardNumber?: string;
|
|
|
|
|
|
accountNumber?: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function ClaimForm() {
|
|
|
|
|
|
const [currentStep, setCurrentStep] = useState(0);
|
|
|
|
|
|
const [formData, setFormData] = useState<FormData>({
|
2025-10-24 20:54:57 +03:00
|
|
|
|
voucher: '',
|
|
|
|
|
|
email: '',
|
2025-10-24 16:19:58 +03:00
|
|
|
|
phone: '',
|
|
|
|
|
|
paymentMethod: 'sbp',
|
|
|
|
|
|
});
|
|
|
|
|
|
const [isPhoneVerified, setIsPhoneVerified] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
const updateFormData = (data: Partial<FormData>) => {
|
|
|
|
|
|
setFormData({ ...formData, ...data });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const nextStep = () => {
|
|
|
|
|
|
setCurrentStep(currentStep + 1);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const prevStep = () => {
|
|
|
|
|
|
setCurrentStep(currentStep - 1);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await fetch('http://147.45.146.17:8100/api/v1/claims/create', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
2025-10-24 20:54:57 +03:00
|
|
|
|
voucher: formData.voucher,
|
2025-10-24 16:19:58 +03:00
|
|
|
|
email: formData.email,
|
2025-10-24 20:54:57 +03:00
|
|
|
|
phone: formData.phone,
|
2025-10-24 16:19:58 +03:00
|
|
|
|
incident_date: formData.incidentDate,
|
|
|
|
|
|
incident_description: formData.incidentDescription,
|
|
|
|
|
|
transport_type: formData.transportType,
|
|
|
|
|
|
payment_method: formData.paymentMethod,
|
|
|
|
|
|
bank_name: formData.bankName,
|
|
|
|
|
|
card_number: formData.cardNumber,
|
|
|
|
|
|
account_number: formData.accountNumber,
|
|
|
|
|
|
uploaded_files: formData.uploadedFiles || [],
|
|
|
|
|
|
}),
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
message.success(`Заявка ${result.claim_number} успешно создана!`);
|
|
|
|
|
|
// Сброс формы
|
|
|
|
|
|
setFormData({
|
2025-10-24 20:54:57 +03:00
|
|
|
|
voucher: '',
|
|
|
|
|
|
email: '',
|
2025-10-24 16:19:58 +03:00
|
|
|
|
phone: '',
|
|
|
|
|
|
paymentMethod: 'sbp',
|
|
|
|
|
|
});
|
|
|
|
|
|
setCurrentStep(0);
|
|
|
|
|
|
setIsPhoneVerified(false);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
message.error('Ошибка при создании заявки');
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
message.error('Ошибка соединения с сервером');
|
|
|
|
|
|
console.error(error);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const steps = [
|
|
|
|
|
|
{
|
2025-10-24 20:40:44 +03:00
|
|
|
|
title: 'Проверка полиса',
|
2025-10-24 16:19:58 +03:00
|
|
|
|
content: (
|
2025-10-24 20:40:44 +03:00
|
|
|
|
<Step1Policy
|
2025-10-24 16:19:58 +03:00
|
|
|
|
formData={formData}
|
|
|
|
|
|
updateFormData={updateFormData}
|
|
|
|
|
|
onNext={nextStep}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: 'Детали происшествия',
|
|
|
|
|
|
content: (
|
|
|
|
|
|
<Step2Details
|
|
|
|
|
|
formData={formData}
|
|
|
|
|
|
updateFormData={updateFormData}
|
|
|
|
|
|
onNext={nextStep}
|
|
|
|
|
|
onPrev={prevStep}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-10-24 20:40:44 +03:00
|
|
|
|
title: 'Телефон и выплата',
|
2025-10-24 16:19:58 +03:00
|
|
|
|
content: (
|
|
|
|
|
|
<Step3Payment
|
|
|
|
|
|
formData={formData}
|
|
|
|
|
|
updateFormData={updateFormData}
|
|
|
|
|
|
onPrev={prevStep}
|
|
|
|
|
|
onSubmit={handleSubmit}
|
2025-10-24 20:40:44 +03:00
|
|
|
|
isPhoneVerified={isPhoneVerified}
|
|
|
|
|
|
setIsPhoneVerified={setIsPhoneVerified}
|
2025-10-24 16:19:58 +03:00
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2025-10-24 21:34:50 +03:00
|
|
|
|
const handleReset = () => {
|
|
|
|
|
|
setFormData({
|
|
|
|
|
|
voucher: '',
|
|
|
|
|
|
email: '',
|
|
|
|
|
|
phone: '',
|
|
|
|
|
|
paymentMethod: 'sbp',
|
|
|
|
|
|
});
|
|
|
|
|
|
setCurrentStep(0);
|
|
|
|
|
|
setIsPhoneVerified(false);
|
|
|
|
|
|
message.info('Форма сброшена');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-24 16:19:58 +03:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="claim-form-container">
|
2025-10-24 21:34:50 +03:00
|
|
|
|
<Card
|
|
|
|
|
|
title="Подать заявку на выплату"
|
|
|
|
|
|
className="claim-form-card"
|
|
|
|
|
|
extra={
|
|
|
|
|
|
currentStep > 0 && (
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={handleReset}
|
|
|
|
|
|
style={{
|
|
|
|
|
|
padding: '4px 12px',
|
|
|
|
|
|
background: '#fff',
|
|
|
|
|
|
border: '1px solid #d9d9d9',
|
|
|
|
|
|
borderRadius: '4px',
|
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
|
fontSize: '14px'
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
🔄 Начать заново
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
2025-10-24 16:19:58 +03:00
|
|
|
|
<Steps current={currentStep} className="steps">
|
|
|
|
|
|
{steps.map((item) => (
|
|
|
|
|
|
<Step key={item.title} title={item.title} />
|
|
|
|
|
|
))}
|
|
|
|
|
|
</Steps>
|
|
|
|
|
|
<div className="steps-content">{steps[currentStep].content}</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|