131 lines
3.9 KiB
JavaScript
131 lines
3.9 KiB
JavaScript
import React from "react";
|
|
import { connect } from "react-redux";
|
|
import moment from "moment";
|
|
import { SpinnerCircular } from "spinners-react";
|
|
|
|
import { signCheckEDOCreatePrintForm } from "../../actions";
|
|
//import { getDeals, getDealOffers, getDealDocuments, getDealContracts } from "../../actions";
|
|
|
|
class EDOSign extends React.Component
|
|
{
|
|
constructor(props)
|
|
{
|
|
super(props)
|
|
this.state = {
|
|
operators: null,
|
|
loading: false,
|
|
selected: {},
|
|
}
|
|
}
|
|
|
|
static getDerivedStateFromProps(nextProps, prevState)
|
|
{
|
|
console.log("EDOSign", "getDerivedStateFromProps", { nextProps });
|
|
return {
|
|
operators: nextProps.operators,
|
|
}
|
|
}
|
|
|
|
componentDidMount()
|
|
{
|
|
if(this.state.selected.box_id === undefined)
|
|
{
|
|
this.setState({ selected: this.state.operators !== null && this.state.operators[0] !== undefined ? this.state.operators[0] : {} });
|
|
}
|
|
}
|
|
|
|
_handle_onFormSubmit = (event) =>
|
|
{
|
|
event.preventDefault();
|
|
|
|
const { documents } = this.props;
|
|
const { selected } = this.state;
|
|
console.log("_handle_onFormSubmit");
|
|
console.log({ documents, selected });
|
|
|
|
this.setState({ loading: true }, () =>
|
|
{
|
|
const contracts = [];
|
|
for(let i in documents)
|
|
{
|
|
contracts.push(documents[i].id);
|
|
signCheckEDOCreatePrintForm({ contracts, sign_type: "EDO" })
|
|
.then((checks) =>
|
|
{
|
|
console.log({ checks });
|
|
})
|
|
.catch((error) =>
|
|
{
|
|
console.log({ error });
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
_handle_onSelectOperator = (operator) =>
|
|
{
|
|
this.setState({ selected: operator });
|
|
}
|
|
|
|
render()
|
|
{
|
|
const { operators, loading, selected } = this.state;
|
|
const { onCancel, documents } = this.props;
|
|
console.log({ operators, documents });
|
|
|
|
return (
|
|
<div className="edo_detail">
|
|
<div className="docs_list medium-icon">
|
|
<p className="list_title">Подписание через ЭДО</p>
|
|
</div>
|
|
<div className="docs_list medium-icon">
|
|
{ documents.map((document, index) =>
|
|
(
|
|
<p className="doc_name i-pdf extension edo_sign_document" data-format={ document.extension } key={ index }>
|
|
{ document.name } от { moment(document.date).format("DD.MM.YYYY") }
|
|
{ document.type !== undefined && (<span>{ document.type }</span>) }
|
|
</p>
|
|
)) }
|
|
</div>
|
|
<form ref={ this.ref_form } onSubmit={ this._handle_onFormSubmit } onKeyDown={(e) => {if (e.key === 'Enter') e.preventDefault() }}>
|
|
<div className="form_field edo_list_field">
|
|
<label>Выберите оператора для отправки пакета документов</label>
|
|
<div className="edo_list_selection">
|
|
{ operators !== undefined && operators !== null && operators.map((operator, index) => (
|
|
<div className="form_field checkbox item" key={ index }>
|
|
<input type="radio"
|
|
checked={ operator.box_id === selected.box_id }
|
|
hidden=""
|
|
id={ `operator_${ index }` }
|
|
name={ `operator_${ index }` }
|
|
onChange={ (event) => this._handle_onSelectOperator(operator) }
|
|
disabled={ false }
|
|
/>
|
|
<label htmlFor={ `operator_${ index }` } className="unselectable">{ operator.provider_edo }</label>
|
|
</div>
|
|
)) }
|
|
</div>
|
|
</div>
|
|
<div className="form_field" style={{ display: "flex", justifyContent: "space-between" }}>
|
|
<button className="button button-blue" onClick={ onCancel }>Отменить</button>
|
|
<button type="submit" className="button button-blue">
|
|
{ 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>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
function mapStateToProps(state, ownProps)
|
|
{
|
|
console.log("EDOSign", "mapStateToProps", { state: state });
|
|
return {
|
|
operators: state.edo.operators,
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps)(EDOSign) |