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

This commit is contained in:
megavrilinvv
2022-12-09 14:11:08 +03:00
parent 9cc2abb420
commit 94e6727350
3 changed files with 69 additions and 50 deletions

View File

@@ -286,7 +286,9 @@ export default {
)
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));
updateContacts.forEach((el) => this.postUpdateContact(el));
},
@@ -300,11 +302,13 @@ export default {
.then(() => this.fetchDataClients());
},
postUpdateContact(contact) {
fetchWrapper.post(`general/contact/${contact.id}/update/`, {
kind: contact.kind,
username: contact.username,
person_id: this.client.id,
});
fetchWrapper
.post(`general/contact/${contact.id}/update/`, {
kind: contact.kind,
username: contact.username,
person_id: this.client.id,
})
.then(() => this.fetchDataClients());
},
postDeleteContact(contact) {
fetchWrapper.del(`general/contact/${contact.id}/delete/`);
@@ -555,45 +559,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: {
rowOverlay() {
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() {
if (this.timer) {
this.deleteClient();

View File

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