import React from "react"; import Head from 'next/head'; import Image from 'next/image'; import Link from "next/link"; import cookie from 'cookie'; import { connect } from "react-redux"; import numeral from "numeral"; import moment from 'moment'; import { withRouter } from 'next/router'; import { reduxWrapper } from '../store'; import Header from './components/Header'; import Footer from './components/Footer'; import DateInput from './components/DatePicker'; import Pagination from './components/Pagination'; import { getContractsList } from '../actions'; class IndexPage extends React.Component { constructor(props) { super(props); this.state = { contracts: null, sort_number: "desc", sort_date: "desc", sort_status: "desc", search: "", date_from: undefined, date_from_type: "text", date_to: undefined, date_to_type: "text", loading: false, page: 1, pages: 1, }; } static getDerivedStateFromProps(nextProps, prevState) { return { company: nextProps.company, contracts: nextProps.contracts, page: nextProps.page, pages: nextProps.pages, }; } componentDidMount() { this.setState({ loading: true }, () => { getContractsList({ dispatch: this.props.dispatch }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onChange_search = (value) => { this.setState({ search: value }); } _handle_onChange_date_from = (value) => { this.setState({ date_from: value }); } _handle_onChange_date_to = (value) => { this.setState({ date_to: value }); } _handle_onChangeSort_number = () => { this.setState({ loading: true, sort_number: this.state.sort_number === "desc" ? "asc" : "desc" }, () => { getContractsList({ dispatch: this.props.dispatch, order: "number", sort: this.state.sort_number, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onChangeSort_date = () => { this.setState({ loading: true, sort_date: this.state.sort_date === "desc" ? "asc" : "desc" }, () => { getContractsList({ dispatch: this.props.dispatch, order: "date", sort: this.state.sort_date, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onChangeSort_status = () => { this.setState({ loading: true, sort_status: this.state.sort_status === "desc" ? "asc" : "desc" }, () => { getContractsList({ dispatch: this.props.dispatch, order: "status", sort: this.state.sort_status, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onPage = (page) => { const { sort_number, sort_status, search, date_from, date_to, } = this.state; this.setState({ loading: true, }, () => { getContractsList({ dispatch: this.props.dispatch, sort_number, sort_status, search, date_from, date_to, page, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onSearch = () => { const { search, date_from, date_to, } = this.state; this.setState({ loading: true, }, () => { getContractsList({ dispatch: this.props.dispatch, search, date_from, date_to, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } render() { const { loading, page, pages, search, date_from, date_from_type, date_to, date_to_type, contracts, sort_number, sort_date, sort_status } = this.state; const contract_status = { "Действующий": "opened", "Закрыт": "closed", }; return ( ЛК Эволюция автолизинга

Личный кабинет

{ event.preventDefault(); } }>
{ this._handle_onChange_search(event.target.value); } }/>
{/* this.setState({ date_from_type: "date" }) } onBlur={ () => { this.setState({ date_from_type: "text" }) } } onChange={ (date) => { this._handle_onChange_date_from(date); } }/> */}
{/* this.setState({ date_from_type: "date" }) } onBlur={ () => { this.setState({ date_from_type: "text" }) } } onChange={ (date) => { this._handle_onChange_date_to(date); } }/> */}
Номер договора
Дата договора
Автомобиль
Гос.номер
Vin
Статус
Следующий платеж
{ contracts !== null && ( <> { contracts.length > 0 ? contracts.map((contract, index) => (
{ moment(contract.date).format("DD.MM.YYYY") }
{ contract.car?.brand?.name } { contract.car?.model?.name }
{ contract.car?.reg_number !== null ? contract.car?.reg_number : "Без рег. номера" }
{ contract.car?.vin_number }

{ contract.status }

{ contract.current_payment_amount !== null ? ( <>{ moment(contract.current_payment_date).format("DD.MM.YYYY") }{ numeral(contract.current_payment_amount).format('') } р. ) : "-" }
)) : (
-
-
-
-
-
-
-
) } ) } {/*
Договор № 1234-2022
21.02.2021
Lada Granta седан Standard 1.6 87hp 5MT
Х 123 АМ 777
4USBT53544LT26841

Действующий

20.01.2021 45,000 р.
Договор № 1234-2023
21.02.2021
Lada Granta седан Standard 1.6 87hp 5MT
Х 123 АМ 777
4USBT53544LT26841

Закрыт

20.01.2021 45,000 р.
*/}