diff --git a/actions/signActions.js b/actions/signActions.js index 71ebe92..c928854 100644 --- a/actions/signActions.js +++ b/actions/signActions.js @@ -180,6 +180,47 @@ export const signGetFileContractProject = (payload) => console.error("ACTION", "sign", "signGetFileContractProject()", "ERROR"); console.error(error); + reject(error.data); + }); + }); +} + +export const signUploadPaperDocument = (contract_number, deal_id, files) => +{ + console.log({ contract_number, files }); + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/upload`; + + return new Promise((resolve, reject) => + { + let data = new FormData(); + data.append('contract_number', contract_number); + data.append('deal_id', deal_id); + + for(let i in files) + { + data.append('files', files[i]); + } + + axios.post(url, data, { + headers: { + "Content-Type": "multipart/form-data", + }, + withCredentials: true, + }) + .then((response) => + { + if(parseInt(process.env.LOG, 10) === 1) { console.log("ACTION", "sign", "signUploadPaperDocument()", "response", response.data); } + + setTimeout(() => + { + resolve(); + }, 2000); + }) + .catch((error) => + { + console.error("ACTION", "sign", "signUploadPaperDocument()", "ERROR"); + console.error(error); + reject(error.data); }); }); diff --git a/components/DealsStatus/components/DealContractsSignPaper.js b/components/DealsStatus/components/DealContractsSignPaper.js index f2ae34e..aa7cdc0 100644 --- a/components/DealsStatus/components/DealContractsSignPaper.js +++ b/components/DealsStatus/components/DealContractsSignPaper.js @@ -5,8 +5,9 @@ import { SpinnerCircular } from "spinners-react"; import { concatSeries } from "async"; import { eachSeries } from 'async'; import Select from 'react-select'; +import Dropzone from 'react-dropzone'; -import { createEDOProject, docEDOCancel, signCheckCreatePrintForm, signDownloadFile, signGetGUIDEntity, signGetWMDoc, docEDOSign, docEDOStatus, docEDOConnect } from "../../../actions"; +import { docEDOCancel, signCheckCreatePrintForm, signGetGUIDEntity, signGetWMDoc, docEDOStatus, getFile, signGetFileContractProject, signUploadPaperDocument } from "../../../actions"; export default class DealContractsSignPaper extends React.Component { @@ -60,9 +61,20 @@ export default class DealContractsSignPaper extends React.Component for(let i in documents) { console.log({ fin: documents[i] }); - if(!documents[i].completed) - completed = false; - break; + if(documents[i].error) + { + console.log(11111); + continue; + } + else + { + if(!documents[i].completed) + { + console.log(22222); + completed = false; + break; + } + } } return completed; @@ -84,37 +96,17 @@ export default class DealContractsSignPaper extends React.Component { callback(); } - else if(document.signing) + if(document.uploading) { - await this._updateDocs(document.index, { loading: true, }); - - const status_result = await docEDOStatus({ contract_number: document.id }); - if(status_result.status === 3) - { - await this._updateDocs(document.index, { loading: false, signing: false, ready: false, completed: true, }); - } - else - { - await this._updateDocs(document.index, { loading: false, signing: true, ready: false, }); - } - callback(); } else if(document.ready) { + callback(); + /* console.log({ document }) await this._updateDocs(document.index, { loading: true, }); - - const status_result = await docEDOStatus({ contract_number: document.id }); - console.log({ status_result }); - - if(status_result.status > 0) - { - const sign_result = await docEDOSign({ edoid: status_result.edoid }); - } - - await this._updateDocs(document.index, { loading: false, signing: true, ready: false, error: false, }); - callback(); + */ } else { @@ -150,8 +142,6 @@ export default class DealContractsSignPaper extends React.Component }); console.log({ wmdoc_result }); - const connect_result = await docEDOConnect({ contract_number: document.id }); - await this._updateDocs(document.index, { entity_id: get_guid_entity_result.entityid, ready: true, @@ -162,7 +152,12 @@ export default class DealContractsSignPaper extends React.Component } else { - await this._updateDocs(document.index, { loading: false, error: true, ready: true, message: "Возникла ошибка при создании документа для подписания." }); + await this._updateDocs(document.index, { + loading: false, + error: true, + ready: true, + message: create_print_form_result.message !== undefined && create_print_form_result.message !== null ? create_print_form_result.message : "Возникла ошибка при создании документа для подписания.", + }); callback(); } } @@ -174,7 +169,7 @@ export default class DealContractsSignPaper extends React.Component } else { - this.setState({ loading: false }); + this.setState({ loading: false, finished: false, }); } }); }); @@ -201,19 +196,23 @@ export default class DealContractsSignPaper extends React.Component } } - _handle_onDownloadFile = (index, entity_id, name) => + _handle_onDownloadFile = (index) => { - console.log("_handle_onDownloadFile", { index, entity_id }); + const { documents } = this.state; + this.setState({ loading: true, disabled: true, }, async () => { await this._updateDocs(index, { loading: true }); - const wmdoc_result = await signDownloadFile({ - payload: { entity_name: "evo_contract", entity_id, sign_type: "EDO", evo_id: "144", }, - filename: `ЛК ЭВОЛЮЦИЯ ${ name }.pdf`, + const link_result = await signGetFileContractProject({ + contract_number: documents[index].id, }); - await this._updateDocs(index, { loading: false, disabled: false, }); + console.log("_handle_onDownloadFile", { link_result }); + await getFile({ id: link_result.url, filename: `ЛК ЭВОЛЮЦИЯ ${ documents[index].id }.${ link_result.extension }` }); + + await this._updateDocs(index, { loading: false, disabled: false, ready: false, uploading: true, }); + this.setState({ loading: false, disabled: false, }); }); } @@ -225,7 +224,7 @@ export default class DealContractsSignPaper extends React.Component this.setState({ loading: true, disabled: true }, async () => { - await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "144" }); + await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "60" }); const docs = [ ...this.state.documents ]; docs.splice(index, 1); @@ -256,29 +255,33 @@ export default class DealContractsSignPaper extends React.Component onCancel(clean); } - _handle_onCheckEDOStatus = async (index) => + _handle_onUploadFile = async (files, index) => { + const { documents } = this.state; + const { deal_id } = this.props; + + console.log("_handle_onUploadFile", { files, index }); await this._updateDocs(index, { loading: true }); this.setState({ loading: true, disabled: true }, async () => { - const status_result = await docEDOStatus({ contract_number: document.id }); - console.log({ status_result }); + await signUploadPaperDocument(documents[index].id, deal_id, files); + await this._updateDocs(index, { loading: false, uploading: false, completed: true, }); - if(status_result.status === 3) + if(this._checkDocumentsCompleted()) { - await this._updateDocs(index, { loading: false, disabled: false, signing: false, completed: true, }); + this.setState({ loading: false, disabled: false, finished: true, }); } else { - await this._updateDocs(index, { loading: false, disabled: false, signing: true, completed: false, }); + this.setState({ loading: false, disabled: false, finished: false, }); } }); } - _handle_onGoToEDO = () => + _handle_onCancelUpload = async (index) => { - + await this._updateDocs(index, { ready: true, uploading: false, }); } render() @@ -320,34 +323,31 @@ export default class DealContractsSignPaper extends React.Component > ) : ( <> - { document.upload && ( - <> -
-