343 lines
12 KiB
JavaScript
343 lines
12 KiB
JavaScript
import React from "react";
|
||
import Head from 'next/head';
|
||
import Image from 'next/image';
|
||
import Link from "next/link";
|
||
import cookie from 'cookie';
|
||
import numeral from "numeral";
|
||
import pluralize from 'pluralize-ru';
|
||
import { SpinnerCircular } from 'spinners-react';
|
||
import { connect } from "react-redux";
|
||
import { withRouter } from 'next/router';
|
||
import InputMask from 'react-input-mask';
|
||
import CurrencyInput from 'react-currency-input';
|
||
|
||
import QuestionnaireForm from "../QuestionnaireForm";
|
||
import { reduxWrapper } from '../../../../store';
|
||
import { saveQuestionnaire } from "../../../../actions";
|
||
|
||
class Form_1_Main extends QuestionnaireForm
|
||
{
|
||
constructor(props)
|
||
{
|
||
super(props);
|
||
this.state = {
|
||
main: {
|
||
title: null,
|
||
inn: null,
|
||
kpp: null,
|
||
email: null,
|
||
telephone: null,
|
||
websiteurl: null,
|
||
financial_loan: null,
|
||
is_individual_executive: false,
|
||
individual_executive_inn: "",
|
||
individual_executive_kpp: "",
|
||
individual_executive_oop: "",
|
||
individual_executive_docnum: "",
|
||
individual_executive_docdate: "",
|
||
high_level: "",
|
||
board_of_directors: "",
|
||
collective_executive: "",
|
||
individual_executive: "",
|
||
other_control: "",
|
||
nko: false,
|
||
accept: false,
|
||
},
|
||
non_profit_template: {
|
||
fin_source_business: false,
|
||
fin_source_donate: false,
|
||
fin_source_fees: false,
|
||
fin_source_another: false,
|
||
fin_source_another_description: "",
|
||
foreign_payers: false,
|
||
fin_goals_cars: "",
|
||
fin_goals_trucks: "",
|
||
fin_goals_special: "",
|
||
},
|
||
step: 1,
|
||
status: "empty",
|
||
loading: false,
|
||
errors: [],
|
||
};
|
||
|
||
this.ref_form = React.createRef();
|
||
this.ref_submit = React.createRef();
|
||
}
|
||
|
||
static getDerivedStateFromProps(nextProps, prevState)
|
||
{
|
||
return {
|
||
main: nextProps.questionnaire.main,
|
||
step: nextProps.questionnaire.step,
|
||
status: nextProps.questionnaire.status,
|
||
};
|
||
}
|
||
|
||
componentDidMount()
|
||
{
|
||
}
|
||
|
||
_handle_onNextPage = (event) =>
|
||
{
|
||
event.preventDefault();
|
||
|
||
const errors = [];
|
||
|
||
const { main } = this.state;
|
||
const { company } = this.props;
|
||
const check = ["title", "inn", "kpp", "email", "telephone", "financial_loan"];
|
||
if(company.inn.length > 10)
|
||
{
|
||
check.splice(check.indexOf("kpp"), 1);
|
||
}
|
||
|
||
for(let i in check)
|
||
{
|
||
if(main[check[i]] === "")
|
||
{
|
||
errors.push(`main.${ check[i] }`);
|
||
}
|
||
}
|
||
|
||
this.setState({ errors }, () =>
|
||
{
|
||
window.scroll(0, 0);
|
||
this.ref_submit.current.click();
|
||
});
|
||
}
|
||
|
||
_handle_onNonProfitChange = () =>
|
||
{
|
||
const { main, non_profit_template, step } = this.state;
|
||
|
||
this._handle_onFieldChange("non_profit", JSON.parse(JSON.stringify(non_profit_template)));
|
||
this._handle_onCheckboxFieldChange("main.nko", !main.nko ? true : false);
|
||
|
||
if(step > 6)
|
||
{
|
||
this._handle_onFieldChange("step", 6);
|
||
}
|
||
}
|
||
|
||
_handle_onFormSubmit = (event) =>
|
||
{
|
||
event.preventDefault();
|
||
|
||
this._handle_onJoinChange({ status: "draft", step: 2 });
|
||
setTimeout(() =>
|
||
{
|
||
saveQuestionnaire();
|
||
this.props.onNextStep("contacts");
|
||
}, 10);
|
||
}
|
||
|
||
_check_fields_disabled = (values) =>
|
||
{
|
||
for(let i in values)
|
||
{
|
||
if(values[i] === "")
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
render()
|
||
{
|
||
const { company, checking } = this.props;
|
||
const { loading, main, status, errors, } = this.state;
|
||
const firstLetter = /(?!.*[DFIOQU])[A-VXY]/i;
|
||
const letter = /(?!.*[DFIOQU])[A-Z]/i;
|
||
const digit = /[0-9]/;
|
||
const fin_mask = [firstLetter, digit, letter, " ", digit, letter, digit];
|
||
|
||
return (
|
||
<React.Fragment>
|
||
<form ref={ this.ref_form } onSubmit={ this._handle_onFormSubmit } onKeyDown={(e) => {if (e.key === 'Enter') e.preventDefault() }} className={`questionnaire questionnaire_1 ${ checking && "disabled" }`}>
|
||
<p className="title">1. Информация о лизингополучателе</p>
|
||
{ errors.length > 0 &&
|
||
(
|
||
<div className="questionnaire message error">
|
||
<svg width="44" height="45" viewBox="0 0 44 45" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||
<path d="M40.5425 31.1863L25.7969 8.08116C24.9653 6.77804 23.5459 6 22 6C20.4539 6 19.0345 6.77804 18.2032 8.08116L3.45741 31.1862C2.57234 32.5732 2.51363 34.3313 3.30467 35.7746C4.09572 37.2173 5.60918 38.1137 7.25444 38.1137H36.7456C38.3909 38.1137 39.9044 37.2175 40.6956 35.7742C41.4863 34.3313 41.4276 32.5733 40.5425 31.1863ZM22 34.2245C20.644 34.2245 19.5448 33.1252 19.5448 31.7694C19.5448 30.4133 20.6441 29.3141 22 29.3141C23.356 29.3141 24.4551 30.4133 24.4551 31.7694C24.4551 33.1252 23.3559 34.2245 22 34.2245ZM25.403 17.1635L24.1937 25.3052C24.0157 26.5037 22.8999 27.3309 21.7016 27.1529C20.7334 27.0091 20.0075 26.25 19.8582 25.333L18.5451 17.2074C18.2394 15.3155 19.5251 13.534 21.417 13.2283C23.3089 12.9226 25.0904 14.2083 25.3962 16.1002C25.4536 16.4565 25.4517 16.8243 25.403 17.1635Z" fill="white"/>
|
||
</svg>
|
||
<p><b>Ошибка</b>
|
||
Пожалуйста, проверьте корректность заполнения данных в форме.
|
||
</p>
|
||
</div>
|
||
) }
|
||
<div className="form_field">
|
||
<label>Краткое наименование <sup className="required_label">*</sup></label>
|
||
<input type="text"
|
||
className={ errors.indexOf("main.title") > -1 ? "error" : "" }
|
||
id="main.title"
|
||
name="main.title"
|
||
value={ this._checkStrValue(main.title) }
|
||
placeholder="Введите наименование"
|
||
onChange={ (event) => { this._removeError("main.title"); this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
required={ true }
|
||
disabled={ true }
|
||
/>
|
||
</div>
|
||
|
||
<div className="formgroup">
|
||
<div className="form_field">
|
||
<label>ИНН <sup className="required_label">*</sup></label>
|
||
<input type="text"
|
||
className={ errors.indexOf("main.inn") > -1 ? "error" : "" }
|
||
id="main.inn"
|
||
name="main.inn"
|
||
value={ this._checkStrValue(main.inn) }
|
||
placeholder="Введите ИНН"
|
||
onChange={ (event) => {this._removeError("main.inn"); this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
required={ true }
|
||
disabled={ true }
|
||
maxLength={ 12 }
|
||
/>
|
||
</div>
|
||
{ company.inn.length < 11 && (
|
||
<div className="form_field">
|
||
<label>КПП <sup className="required_label">*</sup></label>
|
||
<input type="text"
|
||
className={ errors.indexOf("main.kpp") > -1 ? "error" : "" }
|
||
id="main.kpp"
|
||
name="main.kpp"
|
||
value={ this._checkStrValue(main.kpp) }
|
||
placeholder="Введите КПП"
|
||
onChange={ (event) => {this._removeError("main.kpp"); this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
required={ true }
|
||
disabled={ true }
|
||
/>
|
||
</div>
|
||
) }
|
||
</div>
|
||
|
||
<div className="formgroup">
|
||
<div className="form_field">
|
||
<label>Телефон <sup className="required_label">*</sup></label>
|
||
<InputMask
|
||
className={ errors.indexOf("main.telephone") > -1 ? "error" : "" }
|
||
mask='+7 (999) 999 99 99'
|
||
id="main.telephone"
|
||
name="main.telephone"
|
||
value={ this._checkStrValue(main.telephone) }
|
||
placeholder="Введите номер"
|
||
onChange={ (event) => { if(event.target.value !== "" && !isNaN(parseInt(event.target.value.replace(/[^\d]+/g, ''), 10)) && parseInt(event.target.value.replace(/[^\d]+/g, ''), 10) > 7) { this._removeError("main.telephone"); } this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
required={ true }
|
||
disabled={ checking } >
|
||
</InputMask>
|
||
</div>
|
||
|
||
<div className="form_field">
|
||
<label>Сайт</label>
|
||
<input type="text"
|
||
id="main.websiteurl"
|
||
name="main.websiteurl"
|
||
value={ this._checkStrValue(main.websiteurl) }
|
||
placeholder="Введите адрес сайта, если есть"
|
||
onChange={ (event) => { this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
disabled={ checking }
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="form_field">
|
||
<label>E-mail <sup className="required_label">*</sup></label>
|
||
<input type="email"
|
||
className={ errors.indexOf("main.email") > -1 ? "error" : "" }
|
||
id="main.email"
|
||
name="main.email"
|
||
value={ this._checkStrValue(main.email) }
|
||
placeholder="Укажите адрес электронной почты"
|
||
onChange={ (event) => { this._removeError("main.email"); this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
required={ true }
|
||
disabled={ checking }
|
||
/>
|
||
<p>может использоваться для отправки лизингодателем юридически значимых сообщений в соответсвии с условиями договора лизинга, а так же для операций в электронном ПТС/ПСМ</p>
|
||
</div>
|
||
|
||
<div className="form_field">
|
||
<label>Финансовая нагрузка <sup className="required_label">*</sup></label>
|
||
<CurrencyInput
|
||
className={ errors.indexOf("main.financial_loan") > -1 ? "error" : "" }
|
||
id="main.financial_loan"
|
||
name="main.financial_loan"
|
||
value={ this._checkStrValue(main.financial_loan) !== "" && parseFloat(main.financial_loan) > 0 ? this._checkStrValue(main.financial_loan) : null }
|
||
precision="0"
|
||
selectAllOnFocus={ true }
|
||
placeholder="Укажите сумму"
|
||
onChangeEvent={ (event) => { this._removeError("main.financial_loan"); this._handle_onTextFieldChange(event.target.name, event.target.value); } }
|
||
required={ true }
|
||
disabled={ checking }
|
||
/>
|
||
<p>сумма текущих ежемесячных платежей по действующим кредитам/договорам лизинга</p>
|
||
</div>
|
||
|
||
{ company.inn.length < 11 && (
|
||
<div className="form_field">
|
||
<label><b>Организация является НКО</b></label>
|
||
<div>
|
||
<div className="form_field checkbox">
|
||
<input type="radio"
|
||
checked={ !main.nko }
|
||
hidden=""
|
||
id="main.nko_0"
|
||
name="main.nko"
|
||
onChange={ (event) => this._handle_onNonProfitChange() }
|
||
disabled={ main.nko && checking }
|
||
/>
|
||
<label htmlFor="main.nko_0" className="unselectable">Нет</label>
|
||
</div>
|
||
<div className="form_field checkbox">
|
||
<input type="radio"
|
||
checked={ main.nko }
|
||
hidden=""
|
||
id="main.nko_1"
|
||
name="main.nko"
|
||
onChange={ (event) => this._handle_onNonProfitChange() }
|
||
disabled={ !main.nko && checking }
|
||
/>
|
||
<label htmlFor="main.nko_1" className="unselectable">Да</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) }
|
||
|
||
{ !checking && (
|
||
<div className="action" style={{ flexDirection: "column" }}>
|
||
<button type="submit" className="button button-blue" onClick={ this._handle_onNextPage }>
|
||
{ loading ? (
|
||
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" style={{ marginTop: "4px" }}/>
|
||
) : "Продолжить" }
|
||
</button>
|
||
<button ref={ this.ref_submit } type="submit" style={{ display: "none" }}/>
|
||
{ status !== "empty" && (
|
||
<>
|
||
<br/><br/>
|
||
<a style={{ cursor: "pointer" }} onClick={ this._handle_onReset }>Отменить изменения в анкете</a>
|
||
</>
|
||
) }
|
||
</div>
|
||
) }
|
||
</form>
|
||
</React.Fragment>
|
||
)
|
||
}
|
||
}
|
||
|
||
function mapStateToProps(state, ownProps)
|
||
{
|
||
return {
|
||
questionnaire: state.questionnaire,
|
||
}
|
||
}
|
||
|
||
export const getServerSideProps = reduxWrapper.getServerSideProps(store =>
|
||
async ({ req, res, query }) =>
|
||
{
|
||
}
|
||
);
|
||
|
||
export default connect(mapStateToProps)(Form_1_Main); |