[WIP] Фикс запросов на основыне данные, добавил запросы для контактов
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
base-modal(v-model="showModal" title="Загрузить изображение")
|
||||
base-upload-photo(
|
||||
v-model="basic[data.dataKey][field.key]"
|
||||
:confirm-upload="confirmCahngeAvatar"
|
||||
:confirm-upload="confirmChangeAvatar"
|
||||
)
|
||||
.select(v-else-if="field.type === 'select'")
|
||||
base-select(
|
||||
@@ -49,7 +49,7 @@
|
||||
)
|
||||
base-input(
|
||||
v-else,
|
||||
:readonly="checkRow(data.dataLabel)"
|
||||
:readonly="field.disabled || !isEdit"
|
||||
v-model="basic[data.dataKey][field.key]"
|
||||
@update:model-value="checkChangeInput"
|
||||
:type="field.type"
|
||||
@@ -69,10 +69,7 @@ import MedicalFormWrapper from "@/pages/newMedicalCard/components/MedicalFormWra
|
||||
import TheNotificationProvider from "@/components/Notifications/TheNotificationProvider.vue";
|
||||
import { getFieldsNameUnvalidated } from "@/shared/utils/changesObjects";
|
||||
import { addNotification } from "@/components/Notifications/notificationContext";
|
||||
import { getRequestChangeData } from "@/shared/utils/wrapperRequestChangeData";
|
||||
import { checkChangeData } from "@/shared/utils/changesObjects";
|
||||
import { fetchWrapper } from "@/shared/fetchWrapper";
|
||||
import moment from "moment";
|
||||
import {
|
||||
baseDataForm,
|
||||
genderOptions,
|
||||
@@ -117,12 +114,14 @@ export default {
|
||||
basic: (state) => state.medical.basicData,
|
||||
isNew: (state) => state.medical.medicalCard.type === "new",
|
||||
medicalCard: (state) => state.medical.medicalCard,
|
||||
addresses: (state) => state.medical.medicalCard.person.addresses,
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
...mapActions({
|
||||
createAddress: "postCreateAddress",
|
||||
updateAddress: "postUpdateAddress",
|
||||
deleteAddress: "deleteAddress",
|
||||
}),
|
||||
updateBasicData() {
|
||||
const photoFormData = new FormData();
|
||||
@@ -136,23 +135,25 @@ export default {
|
||||
}
|
||||
Object.keys(this.basic).map((key) => {
|
||||
if (key === "registrationAddress")
|
||||
this.getRequestChangeData(
|
||||
this.postAdresses(
|
||||
this.basic.registrationAddress,
|
||||
this.initDataBasic[key],
|
||||
"Адрес регистрации"
|
||||
"REGISTRATION_ADDRESS"
|
||||
);
|
||||
if (key === "residenceAddress")
|
||||
this.getRequestChangeData(
|
||||
this.postAdresses(
|
||||
this.basic.residenceAddress,
|
||||
this.initDataBasic[key],
|
||||
"Адрес проживания"
|
||||
"CURRENT_ADDRESS"
|
||||
);
|
||||
});
|
||||
this.isEdit = false;
|
||||
},
|
||||
getRequestChangeData(updateData, initData, key) {
|
||||
postAdresses(updateData, initData, key) {
|
||||
let isInitDataEmpty = [...Object.keys(removeEmptyFields(initData))]
|
||||
.length;
|
||||
let isUpdateDataEmpty = [...Object.keys(removeEmptyFields(updateData))]
|
||||
.length;
|
||||
if (Object.keys(removeEmptyFields(updateData)).length) {
|
||||
if (!isInitDataEmpty)
|
||||
return this.createAddress({
|
||||
@@ -162,19 +163,18 @@ export default {
|
||||
});
|
||||
if (JSON.stringify(updateData) !== JSON.stringify(initData))
|
||||
return this.updateAddress({
|
||||
id: this.basic.personalData.id,
|
||||
id: this.addresses.find(({ category }) => category === key).id,
|
||||
address: updateData,
|
||||
category: key,
|
||||
});
|
||||
}
|
||||
},
|
||||
checkRow(label) {
|
||||
return label === "Личные данные" ? true : !this.isEdit;
|
||||
if (isInitDataEmpty && !isUpdateDataEmpty)
|
||||
return this.deleteAddress({ id: this.basic.personalData.id });
|
||||
},
|
||||
checkChangeInput() {
|
||||
this.isCheckChange = checkChangeData(this.initDataBasic, this.basic);
|
||||
},
|
||||
confirmCahngeAvatar() {
|
||||
confirmChangeAvatar() {
|
||||
this.showModal = false;
|
||||
this.isCheckChange = true;
|
||||
},
|
||||
@@ -183,69 +183,6 @@ export default {
|
||||
this.isEdit = false;
|
||||
this.isCheckChange = false;
|
||||
},
|
||||
oldUpdateBasicData() {
|
||||
let registration = this.basic.registrationAddress;
|
||||
let residence = this.basic.residenceAddress;
|
||||
let personal = this.basic.personalData;
|
||||
const personalFormData = new FormData();
|
||||
personalFormData.append(
|
||||
"full_name",
|
||||
`${personal.last_name} ${personal.first_name} ${personal.patronymic}`
|
||||
);
|
||||
if (personal.birth_date) {
|
||||
personalFormData.append(
|
||||
"birth_date",
|
||||
moment(personal.birth_date).format("YYYY-MM-DD")
|
||||
);
|
||||
}
|
||||
if (personal.gender) {
|
||||
personalFormData.append("gender", personal.gender?.id);
|
||||
}
|
||||
if (
|
||||
personal.photo.file &&
|
||||
personal.photo.photo !== this.initDataBasic.personalData.photo.photo
|
||||
) {
|
||||
personalFormData.append("photo", personal.photo.file[0]);
|
||||
}
|
||||
const request = Object.keys(this.basic).map((key) => {
|
||||
if (key === "personalData") {
|
||||
return fetchWrapper.post(
|
||||
`general/person/${personal.id}/update/`,
|
||||
personalFormData,
|
||||
"formData"
|
||||
);
|
||||
}
|
||||
if (key === "registrationAddress") {
|
||||
let createRegistration = {
|
||||
person: personal.id,
|
||||
registration_flg: true,
|
||||
...registration,
|
||||
};
|
||||
return getRequestChangeData(
|
||||
createRegistration,
|
||||
registration,
|
||||
this.initDataBasic[key],
|
||||
"address",
|
||||
registration.id
|
||||
);
|
||||
}
|
||||
if (key === "residenceAddress") {
|
||||
let createResidence = {
|
||||
person: personal.id,
|
||||
residence_flg: true,
|
||||
...residence,
|
||||
};
|
||||
return getRequestChangeData(
|
||||
createResidence,
|
||||
residence,
|
||||
this.initDataBasic[key],
|
||||
"address",
|
||||
residence.id
|
||||
);
|
||||
}
|
||||
});
|
||||
return request;
|
||||
},
|
||||
saveChange() {
|
||||
const form = this.$refs.formBasicData;
|
||||
form.validate().then((validate) => {
|
||||
|
||||
@@ -74,9 +74,9 @@ import {
|
||||
getFieldsNameUnvalidated,
|
||||
} from "@/shared/utils/changesObjects";
|
||||
import { contactsDataForm } from "@/pages/newMedicalCard/utils/medicalConfig";
|
||||
import { getRequestArrayData } from "@/shared/utils/wrapperRequestChangeData";
|
||||
import { mapState, mapGetters } from "vuex";
|
||||
import BaseInput from "@/components/base/BaseInput.vue";
|
||||
import { mapActions } from "vuex";
|
||||
|
||||
export default {
|
||||
name: "ContactsForm",
|
||||
@@ -106,13 +106,14 @@ export default {
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
...mapActions({
|
||||
createContact: "postCreateContact",
|
||||
updateContact: "postUpdateContact",
|
||||
deleteContacts: "deleteContact",
|
||||
}),
|
||||
checkNetworksField(index) {
|
||||
if (
|
||||
this.contacts.networks[index].kind &&
|
||||
this.contacts.networks[index].username
|
||||
) {
|
||||
if (this.contacts.networks[index].kind)
|
||||
this.contacts.networks[index].filled = true;
|
||||
}
|
||||
},
|
||||
openEdit() {
|
||||
this.isEdit = true;
|
||||
@@ -123,35 +124,46 @@ export default {
|
||||
this.isCheckChange = false;
|
||||
},
|
||||
updateContacts() {
|
||||
this.isLoadingData = true;
|
||||
const allNewContacts = [
|
||||
...this.contacts.phones,
|
||||
...this.contacts.emails,
|
||||
...this.contacts.networks,
|
||||
];
|
||||
const notEmptyContacts = allNewContacts.filter(
|
||||
(el) => el.kind && el.username
|
||||
);
|
||||
return getRequestArrayData(
|
||||
this.initAllContacts,
|
||||
notEmptyContacts,
|
||||
"person",
|
||||
this.personId,
|
||||
"general",
|
||||
"contact"
|
||||
);
|
||||
const notEmptyContacts = allNewContacts.filter((el) => el.kind);
|
||||
return this.getRequestArrayData(this.initAllContacts, notEmptyContacts);
|
||||
},
|
||||
getRequestArrayData(initData, notEmptyContacts) {
|
||||
const deleteRequests = initData
|
||||
.filter((el) => !notEmptyContacts.find((data) => data.id === el.id))
|
||||
.map((el) => this.deleteContacts({ id: el.id }));
|
||||
const requests = notEmptyContacts.map((el) => {
|
||||
const requestObj = {
|
||||
category: el.kind,
|
||||
value: el.value,
|
||||
};
|
||||
delete requestObj.id;
|
||||
if (!el?.id)
|
||||
return this.createContact({ obj: requestObj, id: this.personId });
|
||||
if (
|
||||
el?.id &&
|
||||
checkChangeData(
|
||||
initData.find((obj) => obj.id === el.id),
|
||||
el
|
||||
)
|
||||
)
|
||||
return this.updateContact({ obj: requestObj, id: el.id });
|
||||
});
|
||||
return requests.concat(deleteRequests);
|
||||
},
|
||||
saveChange() {
|
||||
const form = this.$refs.formContacts;
|
||||
form.validate().then((validate) => {
|
||||
if (validate) {
|
||||
this.isLoadingData = true;
|
||||
Promise.allSettled(this.updateContacts())
|
||||
.then(() => this.$store.dispatch("getMedicalCardData"))
|
||||
.then(() => {
|
||||
this.isLoadingData = false;
|
||||
this.isEdit = false;
|
||||
this.isCheckChange = false;
|
||||
});
|
||||
this.updateContacts();
|
||||
this.isLoadingData = false;
|
||||
this.isEdit = false;
|
||||
this.isCheckChange = false;
|
||||
} else {
|
||||
getFieldsNameUnvalidated(form).forEach((errorKey) => {
|
||||
addNotification(
|
||||
@@ -180,19 +192,17 @@ export default {
|
||||
this.contacts[key].push({
|
||||
filled: false,
|
||||
kind: this.configData[key]?.kind,
|
||||
username: null,
|
||||
});
|
||||
} else {
|
||||
this.contacts[key].push({
|
||||
kind: this.configData[key]?.kind,
|
||||
username: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
this.checkChangeInput();
|
||||
},
|
||||
deleteContact(key, index) {
|
||||
this.contacts[key].splice(index, 1);
|
||||
this.contacts[key]?.splice(index, 1);
|
||||
this.checkChangeInput();
|
||||
},
|
||||
copyLinkNetwork(value) {
|
||||
|
||||
@@ -19,31 +19,37 @@ export const baseDataForm = [
|
||||
key: "last_name",
|
||||
label: "Фамилия",
|
||||
type: "text",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: "first_name",
|
||||
label: "Имя",
|
||||
type: "text",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: "patronymic",
|
||||
label: "Отчество",
|
||||
type: "text",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: "gender",
|
||||
label: "Пол",
|
||||
type: "select",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: "birth_date",
|
||||
label: "Дата рождения",
|
||||
type: "date",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: "photo",
|
||||
label: "Фото",
|
||||
type: "avatar",
|
||||
disabled: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user