From e3bd0e21717419a0908483e1b6d39a11bc308d1f Mon Sep 17 00:00:00 2001 From: Daria Golova Date: Mon, 24 Apr 2023 19:18:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE?= =?UTF-8?q?=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicDataForms/DocumentsForm.vue | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue b/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue index f025c2b..bd234f3 100644 --- a/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue +++ b/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue @@ -139,7 +139,7 @@ export default { checkPassportFields(val, defaultRule) { if ( this.passportFields.every((elem) => !this.docData.passport[elem]) && - !this.initialDocData.passport.series + !this.initialDocData.passport?.id ) { this.$refs.documentForm .getValidationComponents() @@ -200,12 +200,10 @@ export default { let documentsFormData = new FormData(); form.getValidationComponents().forEach((elem) => { if (!this.personDataField.includes(elem.name)) { - if (!this.approvedPassportData) - passportFormData.append(elem.name, elem.modelValue ?? ""); + passportFormData.append(elem.name, elem.modelValue ?? ""); } else documentsFormData.append(elem.name, elem.modelValue ?? ""); }); - if (!this.approvedPassportData) - this.checkChengePhoto("passport", "photo", passportFormData); + this.checkChengePhoto("passport", "photo", passportFormData); this.checkChengePhoto( "insurance_number", "photo_insurance_number", @@ -230,14 +228,43 @@ export default { passportFormData ) ); - } else + } else { + if (this.checkPhotoDeletion("passport", "photo")) + request.push( + this.deletePhoto( + `general/identity_document/${this.initialDocData.passport?.id}/delete_photo/` + ) + ); request.push( this.sendData( `general/identity_document/${this.initialDocData.passport?.id}/update/`, passportFormData ) ); + } } + if ( + this.checkPhotoDeletion( + "insurance_number", + "photo_insurance_number" + ) + ) + request.push( + this.deletePhoto( + `general/person/${this.$store.state.medical?.basicData?.personalData?.id}/delete_photo_insurance_number/` + ) + ); + if ( + this.checkPhotoDeletion( + "tax_identification_number", + "photo_tax_identification_number" + ) + ) + request.push( + this.deletePhoto( + `general/person/${this.$store.state.medical?.basicData?.personalData?.id}/delete_photo_tax_identification_number/` + ) + ); request.push( this.sendData( `general/person/${this.$store.state.medical?.basicData?.personalData?.id}/update/`, @@ -257,9 +284,18 @@ export default { if (this.docData[updatedObjId][field]?.file) formData.append(field, this.docData[updatedObjId][field]?.file[0]); }, + checkPhotoDeletion(updatedObjId, field) { + return ( + !Object.keys(this.docData[updatedObjId][field]).length && + this.initialDocData[updatedObjId][field]?.photo + ); + }, async sendData(url, body) { return await fetchWrapper.post(url, body, "formData"); }, + async deletePhoto(url) { + return await fetchWrapper.del(url); + }, addErrorNotification(title, message) { addNotification(title + message, title, message, "error", 5000); },