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 { SpinnerCircular } from 'spinners-react'; import { withRouter } from 'next/router'; import { reduxWrapper } from '../store'; import Header from './components/Header'; import Footer from './components/Footer'; import Company from "./components/Company"; import DateInput from './components/DatePicker'; import Pagination from './components/Pagination'; import Manager from "./components/Manager"; import AnnouncementsList from "./components/AnnouncementsList"; import { getContractsList, getImage } from '../actions'; class IndexPage extends React.Component { constructor(props) { super(props); this.state = { company: {}, contracts: null, order: "date", 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, all: false, }; } 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, order: this.state.order, sort: this.state.sort_number, }).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, order: "number", sort_number: this.state.sort_number === "desc" ? "asc" : "desc" }, () => { getContractsList({ dispatch: this.props.dispatch, order: this.state.order, sort: this.state.sort_number, all: this.state.all, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onChangeSort_date = () => { this.setState({ loading: true, order: "date", sort_date: this.state.sort_date === "desc" ? "asc" : "desc" }, () => { getContractsList({ dispatch: this.props.dispatch, order: this.state.order, sort: this.state.sort_date, all: this.state.all, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onChangeSort_status = () => { this.setState({ loading: true, order: "status", sort_status: this.state.sort_status === "desc" ? "asc" : "desc" }, () => { getContractsList({ dispatch: this.props.dispatch, order: this.state.order, sort: this.state.sort_status, all: this.state.all, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onPage = (page) => { const { order, sort_number, sort_status, search, date_from, date_to, } = this.state; this.setState({ loading: true, }, () => { getContractsList({ dispatch: this.props.dispatch, order, sort_number, sort_status, search, date_from, date_to, page, all: this.state.all, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } _handle_onAll = () => { const { order, sort_number, sort_status, search, date_from, date_to, } = this.state; this.setState({ loading: true, all: true }, () => { getContractsList({ dispatch: this.props.dispatch, order, sort_number, sort_status, search, date_from, date_to, all: this.state.all, }).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, all: this.state.all, }).then(() => { this.setState({ loading: false }); }).catch(() => {}); }); } render() { const { company, loading, page, pages, search, date_from, date_from_type, date_to, date_to_type, contracts, sort_number, sort_date, sort_status, all } = this.state; const contract_status = { "Действующий": "opened", "Закрыт": "closed", }; console.log("contracts", contracts); 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: date }) }/>
{/* this.setState({ date_from_type: "date" }) } onBlur={ () => { this.setState({ date_from_type: "text" }) } } onChange={ (date) => { this._handle_onChange_date_to(date); } }/> */} this.setState({ date_to: date }) }/>
{ loading ? (
) : (
Номер договора
Дата договора
Автомобиль
Гос.номер / 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.debt_leasing !== undefined && contract.debt_leasing !== null && parseFloat(contract.debt_leasing) > 0 && (

Задолжность: { numeral(contract.debt_leasing).format(' ., ') } ₽

) } { contract.debt_penalty_fee !== undefined && contract.debt_penalty_fee !== null && parseFloat(contract.debt_penalty_fee) > 0 && (

Пени: { numeral(contract.debt_penalty_fee).format(' ., ') } ₽

) }
{ contract.current_payment_date !== null ? ( <>{ moment(contract.current_payment_date).format("DD.MM.YYYY") }{ numeral(contract.current_payment_amount).format(' ., ') } ₽ ) : "-" }
{ contract.telematics_exists && } { contract.rat_exists && } { contract.gibddreg_exists && } { contract.fuelcard_exists && } { contract.kasko_exists && } { contract.osago_exists && } { contract.nsib_exists && } { contract.fingap_exists && }
)) : (
-
-
-
-
-
-
-
) } ) }
) } { !all && ( ) }