diff --git a/src/pages/newMedicalCard/components/BasicDataForms/BasicDataForm.vue b/src/pages/newMedicalCard/components/BasicDataForms/BasicDataForm.vue index f88906c..5d7c6e7 100644 --- a/src/pages/newMedicalCard/components/BasicDataForms/BasicDataForm.vue +++ b/src/pages/newMedicalCard/components/BasicDataForms/BasicDataForm.vue @@ -121,7 +121,8 @@ export default { }, methods: { ...mapActions({ - postAddress: "postAddress", + createAddress: "postCreateAddress", + updateAddress: "postUpdateAddress", }), updateBasicData() { const photoFormData = new FormData(); @@ -137,25 +138,35 @@ export default { if (key === "registrationAddress") this.getRequestChangeData( this.basic.registrationAddress, - this.initDataBasic[key] + this.initDataBasic[key], + "Адрес регистрации" ); if (key === "residenceAddress") this.getRequestChangeData( this.basic.residenceAddress, - this.initDataBasic[key] + this.initDataBasic[key], + "Адрес проживания" ); }); this.isEdit = false; }, - getRequestChangeData(updateData, initData) { - if ( - Object.keys(removeEmptyFields(updateData)).length && - JSON.stringify(updateData) !== JSON.stringify(initData) - ) - return this.postAddress({ - id: this.basic.personalData.id, - address: updateData, - }); + getRequestChangeData(updateData, initData, key) { + let isInitDataEmpty = [...Object.keys(removeEmptyFields(initData))] + .length; + if (Object.keys(removeEmptyFields(updateData)).length) { + if (!isInitDataEmpty) + return this.createAddress({ + id: this.basic.personalData.id, + address: updateData, + category: key, + }); + if (JSON.stringify(updateData) !== JSON.stringify(initData)) + return this.updateAddress({ + id: this.basic.personalData.id, + address: updateData, + category: key, + }); + } }, checkRow(label) { return label === "Личные данные" ? true : !this.isEdit; diff --git a/src/store/modules/medicalCard.js b/src/store/modules/medicalCard.js index b78f350..b5e0908 100644 --- a/src/store/modules/medicalCard.js +++ b/src/store/modules/medicalCard.js @@ -165,7 +165,6 @@ const getters = { street: registrationAddress?.street || "", house: registrationAddress?.house || "", flat: registrationAddress?.flat || "", - category: "Адрес регистрации", }, residenceAddress: { region: residenceAddress?.region || "", @@ -173,7 +172,6 @@ const getters = { street: residenceAddress?.street || "", house: residenceAddress?.house || "", flat: residenceAddress?.flat || "", - category: "Адрес проживания", }, insuranceDMS: { series: DMS?.series, @@ -429,9 +427,17 @@ const getters = { }; const actions = { - postAddress(context, { id, address }) { + postCreateAddress(context, { id, address, category }) { + fetchWrapper.post(`address`, { + person_id: id, + ...address, + category: category, + }); + }, + postUpdateAddress(context, { id, address, category }) { fetchWrapper.post(`address/${id}`, { ...address, + category: category, }); }, deleteItemData({ commit }, props) {