WIP Добавил обновление Контактов

This commit is contained in:
DwCay
2023-04-19 18:11:05 +03:00
parent 5baefcc1f8
commit a2898f4b4f
6 changed files with 120 additions and 50 deletions

View File

@@ -9,8 +9,8 @@
:open-edit="openEdit"
)
.flex.flex-col.gap-19px.w-full
.flex.flex-col.gap-4
.flex.gap-4.items-center(v-for="(allergy, index) in allergies")
.flex.flex-col.gap-4.w-full
.flex.gap-4.items-center.w-full.justify-between(v-for="(allergy, index) in allergies")
.label-field.font-sm.text-sm.whitespace-nowrap {{ `Аллерген ${index+1}:` }}
.flex.gap-2.w-full.items-center
base-input(
@@ -51,6 +51,7 @@ import BaseButton from "@/components/base/BaseButton.vue";
import BaseInput from "@/components/base/BaseInput.vue";
import { checkChangeData } from "@/shared/utils/changesObjects";
import { mapState, mapGetters } from "vuex";
import { getRequestArrayData } from "@/shared/utils/wrapperRequestChangeData";
export default {
name: "AllergiesForm",
@@ -65,15 +66,35 @@ export default {
computed: {
...mapState({
allergies: (state) => state.medical.allergies,
personId: (state) => state.medical.medicalCard.person.id,
}),
...mapGetters({
initAllergies: "getAllergiesData",
}),
},
methods: {
updateAllergies() {
const notEmptyAllergies = this.allergies.filter(
(el) => el.name && el.title
);
return getRequestArrayData(
this.initAllergies,
notEmptyAllergies,
"person",
this.personId,
"general",
"allergic"
);
},
saveChange() {
this.isEdit = false;
this.isCheckChange = false;
this.isLoadingData = true;
Promise.allSettled(this.updateAllergies())
.then(() => this.$store.dispatch("getMedicalCardData"))
.then(() => {
this.isLoadingData = false;
this.isEdit = false;
this.isCheckChange = false;
});
},
cancelEdit() {
this.$store.dispatch("returnInitData");

View File

@@ -8,7 +8,7 @@
:cancel="cancelEdit"
:open-edit="openEdit"
)
.form-wrap.gap-24.w-full
q-form.form-wrap.gap-24.w-full(ref="formContacts")
.flex.flex-col.gap-4(v-for="(contact, key) in contacts")
.font-semibold.text-sm.whitespace-nowrap {{configData[key].title}}
.flex.w-full.justify-between.items-center.gap-4(v-for="(data, index) in contact")
@@ -44,6 +44,7 @@
:disabled="!isEdit"
v-model="data.username"
:mask="configData[key].inputMask"
:rule="configData[key].rules"
@update:model-value="checkChangeInput"
type="text"
:standout="!isEdit"
@@ -72,6 +73,7 @@ import BaseSelectNetworks from "@/components/base/BaseSelectNetworks.vue";
import { mapNetworks } from "@/pages/newMedicalCard/utils/medicalConfig";
import { checkChangeData } from "@/shared/utils/changesObjects";
import { contactsDataForm } from "@/pages/newMedicalCard/utils/medicalConfig";
import { getRequestArrayData } from "@/shared/utils/wrapperRequestChangeData";
import { mapState, mapGetters } from "vuex";
export default {
@@ -92,6 +94,8 @@ export default {
}),
...mapState({
contacts: (state) => state.medical.contactsData,
personId: (state) => state.medical.medicalCard.person.id,
initAllContacts: (state) => state.medical.medicalCard.person.contacts,
}),
},
methods: {
@@ -111,11 +115,37 @@ export default {
this.isEdit = false;
this.isCheckChange = false;
},
updateContacts() {
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"
);
},
saveChange() {
this.isLoadingData = true;
this.$store.dispatch("updateContactsData").then(() => {
this.isEdit = false;
this.isLoadingData = false;
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;
});
}
});
},
checkChangeInput() {

View File

@@ -1,3 +1,5 @@
import { ruleLengthValue, ruleEmailValue } from "@/shared/utils/rulesInputs";
export const baseDataForm = [
{
dataLabel: "Личные данные",
@@ -147,11 +149,13 @@ export const contactsDataForm = {
title: "Телефон",
fieldName: "Телефон",
kind: "PHONE",
rules: [(val) => ruleLengthValue(val, 18)],
inputMask: "+7 (###) ###-##-##",
},
emails: {
title: "Почта",
fieldName: "Email",
rules: [(val) => ruleEmailValue(val)],
kind: "EMAIL",
},
networks: {