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