Merge branch '10-editing-blocks' into 'master'

Resolve "При нажатии не происходит перехода на мед.карту", "Редактирование основных данных на мед.карте"

Closes #10

See merge request astra/astra-frontend!503
This commit is contained in:
Kirill Andrusyak
2023-08-17 17:45:43 +00:00
7 changed files with 176 additions and 141 deletions

View File

@@ -33,14 +33,14 @@
size="M"
)
base-input(
v-model="addresses.house_number",
v-model="addresses.house",
label="Дом",
placeholder="Номер дома",
disabled,
size="M"
)
base-input(
v-model="addresses.apartment_number",
v-model="addresses.flat",
label="Квартира",
placeholder="Номер квартиры",
disabled,

View File

@@ -24,7 +24,7 @@
.thumb.h-full.rounded(:style="thumbStyle")
span.grey-color {{ medcardInfo?.filling_percentage || 0 }}%
.field(:style="{...headerStyle(headerConfig[6])}")
q-icon.medcard.cursor-pointer(name="app:medcard", size="20px")
q-icon.medcard.cursor-pointer(name="app:medcard", size="20px", @click="openMedicalCard")
</template>
<script>
@@ -36,6 +36,7 @@ import * as moment from "moment/moment";
import TheNotificationProvider from "@/components/Notifications/TheNotificationProvider";
import { addNotification } from "@/components/Notifications/notificationContext";
import avatar from "@/assets/images/person.png";
import { mapActions } from "vuex";
export default {
name: "MedicalCardSearchRow",
components: { TheNotificationProvider },
@@ -72,6 +73,15 @@ export default {
},
},
methods: {
...mapActions({
getMedicalCardData: "getMedicalCardDataByPersonId",
}),
openMedicalCard() {
this.getMedicalCardData({
personId: this.medcardInfo.person_id,
successCallback: (id) => this.$router.push("medical-card/" + id),
});
},
convertDate(date) {
return moment(date)?.format("DD MMMM YYYY");
},

View File

@@ -4,7 +4,7 @@
:is-check-change="isCheckChange"
:is-loading-data="isLoadingData"
:is-edit="isEdit"
:save="saveChange"
:save="updateBasicData"
:cancel="cancelEdit"
:open-edit="openEdit"
)
@@ -25,11 +25,11 @@
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(
:readonly="!isEdit"
readonly,
v-model="basic[data.dataKey][field.key]"
@update:model-value="checkChangeInput"
:hide-dropdown-icon="!isEdit"
@@ -43,13 +43,13 @@
v-else-if="field.type === 'date'",
v-model="basic[data.dataKey][field.key]",
size="M",
:readonly="!isEdit",
readonly
@update:model-value="checkChangeInput",
:width="302"
)
base-input(
v-else,
:readonly="!isEdit"
:readonly="field.disabled || !this.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,
@@ -81,6 +78,8 @@ import {
import { mapGetters, mapState } from "vuex";
import BaseInput from "@/components/base/BaseInput.vue";
import BaseInputDate from "@/components/base/BaseInputDate.vue";
import { mapActions } from "vuex";
import { removeEmptyFields } from "@/shared/utils/changesObjects";
export default {
name: "BasicDataForm",
@@ -115,13 +114,62 @@ 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",
}),
updateBasicData() {
const photoFormData = new FormData();
if (
this.basic.personalData.photo.file &&
this.basic.personalData.photo.photo !==
this.initDataBasic.personalData.photo.photo
) {
photoFormData.append("photo", this.basic.personalData?.photo?.file[0]);
console.log("photo_update");
}
Object.keys(this.basic).map((key) => {
if (key === "registrationAddress")
this.postAdresses(
this.basic.registrationAddress,
this.initDataBasic[key],
"REGISTRATION_ADDRESS"
);
if (key === "residenceAddress")
this.postAdresses(
this.basic.residenceAddress,
this.initDataBasic[key],
"CURRENT_ADDRESS"
);
});
this.isEdit = false;
},
postAdresses(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.addresses.find(({ category }) => category === key).id,
address: updateData,
category: key,
});
}
},
checkChangeInput() {
this.isCheckChange = checkChangeData(this.initDataBasic, this.basic);
},
confirmCahngeAvatar() {
confirmChangeAvatar() {
this.showModal = false;
this.isCheckChange = true;
},
@@ -130,89 +178,14 @@ export default {
this.isEdit = false;
this.isCheckChange = false;
},
updateBasicData() {
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) => {
if (validate) {
let person = this.basic.personalData;
this.$store.dispatch("setMedicalCardData", {
...this.medicalCard,
person: {
...this.medicalCard.person,
...person,
},
});
//let updateBasic = this.updateBasicData();
// Promise.allSettled(updateBasic)
// .then(() => this.$store.dispatch("getMedicalCardData"))
// .then(() => {
// this.isLoadingData = false;
// this.isEdit = false;
// this.isCheckChange = false;
// });
this.updateBasicData();
this.isLoadingData = false;
this.isEdit = false;
this.isCheckChange = false;
} else {
getFieldsNameUnvalidated(form).forEach((errorKey) => {
addNotification(

View File

@@ -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",
delContacts: "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.id);
return this.changeContacts(this.initAllContacts, notEmptyContacts);
},
changeContacts(initData, notEmptyContacts) {
const deleteRequests = initData
.filter((el) => !notEmptyContacts.find((data) => data.id === el.id))
.map((el) => this.delContacts({ id: el.id }));
const requests = notEmptyContacts.map((el) => {
const requestObj = {
category: el.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.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) {

View File

@@ -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,
},
],
},
@@ -55,27 +61,33 @@ export const baseDataForm = [
key: "region",
label: "Регион",
type: "text",
rules: [(val) => ruleNotValue(val)],
error: "Поле 'Регион' должны быть заполнены",
},
{
key: "city",
label: "Город",
type: "text",
rules: [(val) => ruleNotValue(val)],
error: "Поле 'Город' должны быть заполнены",
},
{
key: "street",
label: "Улица",
type: "text",
rules: [(val) => ruleNotValue(val)],
error: "Поле 'Улица' должны быть заполнены",
},
{
key: "house_number",
key: "house",
label: "Дом",
type: "text",
rules: [(val) => !/^[\W0]/.test(val)],
rules: [(val) => ruleNotValue(val)],
error:
"Номер дома должен начинатся не с нуля и только с цифробуквенного символа",
},
{
key: "apartment_number",
key: "flat",
label: "Квартира",
type: "text",
rules: [(val) => !/^[\W0]/.test(val)],
@@ -104,7 +116,7 @@ export const baseDataForm = [
type: "text",
},
{
key: "house_number",
key: "house",
label: "Дом",
type: "text",
rules: [(val) => !/^[\W0]/.test(val)],
@@ -112,7 +124,7 @@ export const baseDataForm = [
"Номер дома должен начинатся не с нуля и только с цифробуквенного символа",
},
{
key: "apartment_number",
key: "flat",
label: "Квартира",
type: "text",
rules: [(val) => !/^[\W0]/.test(val)],
@@ -124,12 +136,12 @@ export const baseDataForm = [
];
export const errorMap = {
house_number: {
house: {
title: "Дом",
error:
"Номер дома должен начинатся не с нуля и только с цифробуквенного символа",
},
apartment_number: {
flat: {
title: "Квартира",
error:
"Номер квартиры должен начинатся не с нуля и только с цифробуквенного символа",

View File

@@ -45,7 +45,7 @@ function request(method, url, headers = {}, body, type = "") {
requestOptions.body = JSON.stringify(body);
}
}
if (method === "POST" || method === "PUT") {
if (method === "POST" || method === "PUT" || method === "PATCH") {
if (type && type === "formData") {
requestOptions = {
method: method,
@@ -83,6 +83,10 @@ function post(url, body, type, headers, attempts = 3) {
return handleRequest("POST", url, headers, attempts, body, type);
}
function patch(url, body, type, headers, attempts = 3) {
return handleRequest("PATCH", url, headers, attempts, body, type);
}
function put(url, headers, body, attempts = 3) {
return handleRequest("PUT", url, headers, attempts, null, body);
}
@@ -92,4 +96,5 @@ export const fetchWrapper = {
del,
post,
put,
patch,
};

View File

@@ -24,15 +24,15 @@ const state = () => ({
region: null,
city: null,
street: null,
house_number: null,
apartment_number: null,
house: null,
flat: null,
},
residenceAddress: {
region: null,
city: null,
street: null,
house_number: null,
apartment_number: null,
house: null,
flat: null,
},
insuranceDMS: {
series: null,
@@ -134,10 +134,13 @@ const state = () => ({
const getters = {
getBasicData(state, rootState) {
let registrationAddress =
state.medicalCard?.person?.address?.find((el) => el.registration_flg) ||
{};
state.medicalCard?.person?.addresses?.find(
(el) => el.category === "REGISTRATION_ADDRESS"
) || {};
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 OMS = person?.insurance_policy?.find((e) => e.title === "OMS");
let DMS = person?.insurance_policy?.find((e) => e.title === "DMS");
@@ -163,17 +166,15 @@ const getters = {
region: registrationAddress?.region || "",
city: registrationAddress?.city || "",
street: registrationAddress?.street || "",
house_number: registrationAddress?.house_number || "",
apartment_number: registrationAddress?.apartment_number || "",
id: registrationAddress?.id || "",
house: registrationAddress?.house || "",
flat: registrationAddress?.flat || "",
},
residenceAddress: {
region: residenceAddress?.region || "",
city: residenceAddress?.city || "",
street: residenceAddress?.street || "",
house_number: residenceAddress?.house_number || "",
apartment_number: residenceAddress?.apartment_number || "",
id: residenceAddress?.id || "",
house: residenceAddress?.house || "",
flat: residenceAddress?.flat || "",
},
insuranceDMS: {
series: DMS?.series,
@@ -259,7 +260,6 @@ const getters = {
state.medicalCard?.person?.contacts
?.filter((el) => el.category === "PHONE")
?.map((el) => {
el.value = el.value.length > 10 ? el.value.slice(1) : el.value;
return { ...el };
}) || [];
let emails =
@@ -429,6 +429,31 @@ const getters = {
};
const actions = {
postCreateAddress(context, { id, address, category }) {
fetchWrapper.post(`address`, {
person_id: id,
...address,
category: category,
});
},
postUpdateAddress(context, { id, address, category }) {
fetchWrapper.patch(`address/${id}`, {
...address,
category: category,
});
},
postCreateContact(context, { obj, id }) {
fetchWrapper.post("contacts", {
person_id: id,
...obj,
});
},
postUpdateContact(context, { obj, id }) {
fetchWrapper.patch(`contacts/${id}`, obj);
},
deleteContact(context, { id }) {
fetchWrapper.del(`contacts/${id}`);
},
deleteItemData({ commit }, props) {
commit("setDataWithouDeleted", props);
},