[WIP] Фикс апдейта данных клиента

This commit is contained in:
megavrilinvv
2022-12-09 14:11:08 +03:00
parent 343ded6c07
commit a451ef055a
3 changed files with 69 additions and 50 deletions

View File

@@ -1,19 +1,21 @@
<template lang="pug"> <template lang="pug">
.flex.box-border.container.items-center.cursor-pointer.justify-center.relative( .flex.box-border.container.items-center.cursor-pointer.justify-center.relative(
@click="changeSelect" @click="changeSelect",
v-click-outside="closeSelect",
:class="{border: styleBorder}" :class="{border: styleBorder}"
) )
.flex.select.cursor-pointer.w-full.text-xl.items-center.networks(:class="optionData, 'px-2.5'") .flex.select.cursor-pointer.w-full.text-xl.items-center.networks(:class="optionData, 'px-2.5'")
.absolute.options.top-11.left-0( .absolute.options.top-11.left-0(
v-show="isSelectOpen" v-show="isSelectOpen",
:id="id") :id="id"
)
.flex.option.justify-center.py-1.text-xl( .flex.option.justify-center.py-1.text-xl(
v-for="data in listData" v-for="data in listData",
@click="(e) => chooseOption(e)" @click="(e) => chooseOption(e)",
:key="data.network" :key="data.network",
:id="data.network" :id="data.network",
:class="data.icon" :class="data.icon"
) )
.select-form-separator.cursor-pointer.mr-6px(v-if="separator") .select-form-separator.cursor-pointer.mr-6px(v-if="separator")
</template> </template>
@@ -45,6 +47,9 @@ export default {
changeSelect() { changeSelect() {
this.isSelectOpen = !this.isSelectOpen; this.isSelectOpen = !this.isSelectOpen;
}, },
closeSelect() {
this.isSelectOpen = false;
},
}, },
}; };
</script> </script>

View File

@@ -282,7 +282,9 @@ export default {
) )
updateContacts.push(this.dataClient.email); updateContacts.push(this.dataClient.email);
}); });
createContacts.forEach((el) => this.postCreateContact(el)); createContacts.forEach((el) => {
if (!el.id) this.postCreateContact(el);
});
deleteContacts.forEach((el) => this.postDeleteContact(el)); deleteContacts.forEach((el) => this.postDeleteContact(el));
updateContacts.forEach((el) => this.postUpdateContact(el)); updateContacts.forEach((el) => this.postUpdateContact(el));
}, },
@@ -296,11 +298,13 @@ export default {
.then(() => this.fetchDataClients()); .then(() => this.fetchDataClients());
}, },
postUpdateContact(contact) { postUpdateContact(contact) {
fetchWrapper.post(`general/contact/${contact.id}/update/`, { fetchWrapper
kind: contact.kind, .post(`general/contact/${contact.id}/update/`, {
username: contact.username, kind: contact.kind,
person_id: this.client.id, username: contact.username,
}); person_id: this.client.id,
})
.then(() => this.fetchDataClients());
}, },
postDeleteContact(contact) { postDeleteContact(contact) {
fetchWrapper.del(`general/contact/${contact.id}/delete/`); fetchWrapper.del(`general/contact/${contact.id}/delete/`);
@@ -549,45 +553,55 @@ export default {
}); });
}, },
}, },
created() {
this.dataClient = {
id: this.client.id,
fullName: `${this.client.last_name || ""} ${
this.client.first_name || ""
} ${this.client.patronymic || ""}`,
age: this.client.birth_date || "",
priority: this.prioritySettings.settings.find(
(el) =>
el.priority === this.client.priority || this.client.priority === el.id
).text,
phone: {
id: this.client.contacts.find((el) => el.kind === "PHONE")?.id || "",
kind: "PHONE",
username:
this.client.contacts.find((el) => el.kind === "PHONE")?.username ||
"",
},
email: {
id: this.client.contacts.find((el) => el.kind === "EMAIL")?.id || "",
kind: "EMAIL",
username:
this.client.contacts.find((el) => el.kind === "EMAIL")?.username ||
"",
},
contacts: [...this.client.contacts],
avatar: this.client.first_name
? this.client.last_name[0] + this.client.first_name[0]
: this.client.last_name.substr(0, 2),
color: this.client.color,
photo: this.client.photo,
};
},
watch: { watch: {
rowOverlay() { rowOverlay() {
if (this.rowOverlay) this.startTimer(); if (this.rowOverlay) this.startTimer();
}, },
client: {
deep: true,
immediate: true,
handler(newValue) {
if (newValue) {
this.dataClient = {
id: this.client.id,
fullName: `${this.client.last_name || ""} ${
this.client.first_name || ""
} ${this.client.patronymic || ""}`,
age: this.client.birth_date || "",
priority: this.prioritySettings.settings.find(
(el) =>
el.priority === this.client.priority ||
this.client.priority === el.id
).text,
phone: {
id:
this.client.contacts.find((el) => el.kind === "PHONE")?.id ||
"",
kind: "PHONE",
username:
this.client.contacts.find((el) => el.kind === "PHONE")
?.username || "",
},
email: {
id:
this.client.contacts.find((el) => el.kind === "EMAIL")?.id ||
"",
kind: "EMAIL",
username:
this.client.contacts.find((el) => el.kind === "EMAIL")
?.username || "",
},
contacts: [...this.client.contacts],
avatar: this.client.first_name
? this.client.last_name[0] + this.client.first_name[0]
: this.client.last_name.substr(0, 2),
color: this.client.color,
photo: this.client.photo,
};
}
},
},
}, },
beforeUnmount() { beforeUnmount() {
if (this.timer) { if (this.timer) {
this.deleteClient(); this.deleteClient();

View File

@@ -73,7 +73,7 @@ export const column = [
icon: "icon-tg", icon: "icon-tg",
}, },
{ {
network: "GOOGLE", network: "GMAIL",
icon: "icon-google", icon: "icon-google",
}, },
{ {