import React from "react"
import numeral from "numeral";
import moment from "moment";
import { SpinnerCircular } from "spinners-react";
import FileDropzoneDeals from "../FileDropzoneDeals";
import { acceptDealOffers } from "../../actions";
class Step extends React.Component
{
componentDidMount()
{
if(this.status.indexOf(this.props.statuscode_id) > -1)
{
this.setState({ open: true });
}
}
componentDidUpdate(prevProps, prevState)
{
if(this.props.statuscode_id !== prevProps.statuscode_id)
{
if(this.status.indexOf(this.props.statuscode_id) > -1)
{
this.setState({ open: true });
}
else
{
this.setState({ open: false });
}
}
}
_handle_onSwitch = () =>
{
const { statuscode_id } = this.props;
this.setState({ open: !this.state.open ? true : false });
}
_renderHeader = (title) =>
{
const { statuscode_id } = this.props;
const { open } = this.state;
return (
= this.status[ 0 ] ? { position: "relative", } : { position: "relative", cursor: "inherit" }} onClick={ statuscode_id >= this.status[ 0 ] ? this._handle_onSwitch : () => {} }>
{ this.status.indexOf(statuscode_id) > -1 && (
)}
{ title }
{ statuscode_id >= this.status[ 0 ] && (
) }
{ this._renderHeaderButtons !== undefined && this._renderHeaderButtons() }
)
}
}
class Offers extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
loading: false,
checked: [],
};
this.status = [ 100 ];
}
_handle_onCheckOffer = (quote_number) =>
{
const checked = [ ...this.state.checked ];
let is_new = true;
if(checked.indexOf(quote_number) > -1)
{
checked.splice(checked.indexOf(quote_number), 1);
is_new = false;
}
if(is_new)
{
checked.push(quote_number);
}
this.setState({ checked });
}
_handle_onSend = (event) =>
{
event.preventDefault();
event.stopPropagation();
this.setState({ loading: true }, () =>
{
const { checked } = this.state;
const { dealSelected, onDealsUpdate } = this.props;
acceptDealOffers({ deal_id: dealSelected, offers: checked })
.then(() =>
{
onDealsUpdate()
.then(() =>
{
this.setState({ loading: false });
})
.catch(() =>
{
this.setState({ loading: false });
});
})
});
}
_renderHeaderButtons = () =>
{
const { open, checked, loading } = this.state;
if(!loading && open && checked.length > 0)
{
return (
)
}
return null;
}
render()
{
const { index, statuscode_id, offers } = this.props;
const { checked, open, loading } = this.state;
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Выбор КП ") }
{ offers === undefined || loading ? (
) : (
<>
{ offers.length > 0 ? (
) : (
Нет предложений
) }
>
) }
)
}
}
class FinancialProgram extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
};
this.status = [ 101 ];
}
render()
{
const { index, statuscode_id } = this.props;
const { open } = this.state;
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Программа финансирования") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class DocumentsForm extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
files: {},
};
this.status = [ 102 ];
}
_renderHeaderButtons = () =>
{
const { open, files } = this.state;
if(open && Object.keys(files).length > 0)
{
return (
)
}
return null;
}
_handle_onAddFile = (file_id, files) =>
{
const existed_files = this.state.files;
const document_files = existed_files[ file_id ] === undefined ? [] : existed_files[ file_id ];
for(let nf in files)
{
let e = false;
for(let ef in document_files)
{
if(document_files[ef].name === files[nf].name) { e = true; }
}
if(!e)
{
document_files.push(files[nf]);
}
existed_files[ file_id ] = document_files;
this.setState({ files: existed_files });
}
}
_handle_onDeleteFile = (file_id, file) =>
{
const files = { ...this.state.files };
const list = [];
for(let i in files[file_id])
{
if(files[file_id][i].name !== file.name)
{
list.push(files[file_id][i]);
}
}
if(list.length > 0)
{
files[file_id] = list;
}
else
{
delete files[file_id];
}
this.setState({ files });
}
render()
{
const { index, statuscode_id, documents, questionnaire_status } = this.props;
const { open, files } = this.state;
console.log("DocumentsForm", { documents });
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Сборка пакета документов") }
{ questionnaire_status === "need_to_fill" ? (
Требуется обновить данные в анкете
) : (
<>
{ questionnaire_status !== "up_to_date" ? (
Проводится проверка анкеты Вашей организации
) : (
Вам не требуется актуализация данных анкеты Клиента
) }
>
) }
{ documents === undefined ? (
<>>
) : (
<>
{ documents.map((document, index) => (
{ this._handle_onAddFile(document.doc_id, file) } }
onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) }
/>
)) }
>
)}
{/*}
Документы, отправленные Вами принадлежат другой организации бла бла коммент от менеджера
{*/}
)
}
}
class StatusDocumentsCheck extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
};
this.status = [ 103 ];
}
render()
{
const { index, statuscode_id } = this.props;
const { open } = this.state;
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Проверка документов") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class StatusDecisionMaking extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
};
this.status = [ 104, 105, ];
}
render()
{
const { index, statuscode_id } = this.props;
const { open } = this.state;
return (
-1 ? "current" : (statuscode_id > this.status[0] && statuscode_id > this.status[1]) ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Принятие решения по сделке") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class StatusLeasingRegistration extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
};
this.status = [ 106 ];
}
render()
{
const { index, statuscode_id } = this.props;
const { open } = this.state;
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Принято положительное решение") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class SigningTypeSelection extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
};
this.status = [ 107 ];
this.types = [
{
title: "Подготовлено",
key: "prepared_contracts",
},
{
title: "К подписанию",
key: "signing_plan_contracts",
},
{
title: "Выдано",
key: "issued_contracts",
},
{
title: "Подписано",
key: "signing_fact_contracts",
},
{
title: "Анулировано",
key: "annulled_contracts",
},
];
}
_render_preparedContracts = () =>
{
const contracts = this.props.contracts['prepared_contracts'];
console.log("_render_preparedContracts", { contracts });
return (
{ contracts.map((contract, index) => (
)) }
)
}
_render_signingPlanContracts = () =>
{
const contracts = this.props.contracts['prepared_contracts'];
console.log("_render_signingPlanContracts", { contracts });
return (
{ contracts.map((contract, index) => (
{ contract.name }
{ moment().format("DD.MM.YYYY") }
)) }
)
}
_render_issuedContracts = () =>
{
const contracts = this.props.contracts['issued_contracts'];
console.log("_render_issuedContracts", { contracts });
return (
)
}
_render_signingFactContracts = () =>
{
const contracts = this.props.contracts['signing_fact_contracts'];
console.log("_render_signingFactContracts", { contracts });
return (
)
}
_render_annuledContracts = () =>
{
const contracts = this.props.contracts['annulled_contracts'];
console.log("_render_annuledContracts", { contracts });
return (
)
}
_render_contracts = (type) =>
{
const { contracts } = this.props;
if(contracts !== undefined)
{
switch (type)
{
case "prepared_contracts":
{
return this._render_preparedContracts();
}
case "signing_plan_contracts":
{
return this._render_signingPlanContracts();
}
case "issued_contracts":
{
return this._render_issuedContracts();
}
case "signing_fact_contracts":
{
return this._render_signingFactContracts();
}
case "annulled_contracts":
{
return this._render_annuledContracts();
}
}
}
else
{
return null;
}
}
render()
{
const { index, statuscode_id } = this.props;
const { open } = this.state;
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
Сделка { index + 1 }
{ this._renderHeader("Оформление лизинга") }
{ this.types.map((type, index) => (
{ this._render_contracts(type.key) }
)) }
)
}
}
export default class SingleDeal extends React.Component
{
constructor(props)
{
super(props);
}
render()
{
const { index, status, deals, dealSelected, onCloseDeal, } = this.props;
console.log({ "deals": deals });
const offers = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].offers : undefined;
const documents = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].documents : undefined;
const contracts = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].contracts : undefined;
return (
)
}
}