WIP Изменила BaseAddingNetwork

This commit is contained in:
Daria Golova
2023-02-21 19:05:12 +03:00
parent 6c1f1279b2
commit 2f2c331189
8 changed files with 212 additions and 164 deletions

View File

@@ -61,38 +61,36 @@
@click="closeAddImage",
icon="app:icon-ok"
)
base-input.w-full(v-model="infoClient.basic.full_name", placeholder="ФИО*", outlined)
.flex.flex-col.flex-auto.l.gap-y-8
.flex
button.title-info.px-6.py-2.cursor-pointer.w-full.text-sm(
v-for="form in forms",
@click="selectForm(form.component)",
:class="{active: form.component === currentForm}",
:key="form.id",
:id="form.id"
) {{form.title}}
component(
v-bind:is="currentForm",
:basic-info="infoClient.basic",
:phone="infoClient.phone",
:email="infoClient.email",
:save-network-id="saveNetworkId",
:add-network="addNewNetwork",
:choose-option="chooseOptionNetworks",
:choose-priority="choosePriority",
:priority-list="priorityList",
:identity-document="infoClient.identity_document",
:addresses="infoClient.addresses",
:save-file="saveDocFile",
)
q-btn(
label="Создать клиента",
color="primary",
style="height: 40px; width: 180px",
no-caps,
padding="8px 24px",
@click="saveClient",
)
base-input.w-full(v-model="infoClient.basic.full_name", placeholder="ФИО*", outlined)
.flex.flex-col.flex-auto.l.gap-y-8
.flex
button.title-info.px-6.py-2.cursor-pointer.w-full.text-sm(
v-for="form in forms",
@click="selectForm(form.component)",
:class="{active: form.component === currentForm}",
:key="form.id",
:id="form.id"
) {{form.title}}
component(
v-bind:is="currentForm",
:basic-info="infoClient.basic",
:phone="infoClient.phone",
:email="infoClient.email",
:add-network="addNewNetwork",
:priority-list="priorityList",
:identity-document="infoClient.identity_document",
:addresses="infoClient.addresses",
:save-file="saveDocFile",
:networks-list="getNetworksList",
)
q-btn(
label="Создать клиента",
color="primary",
style="height: 40px; width: 180px",
no-caps,
padding="8px 24px",
@click="saveClient",
)
</template>
<script>
@@ -129,7 +127,7 @@ export default {
mixins: [v_model],
data() {
return {
networksSettings: column.find((el) => el.name === "networks"),
networksSettings: column.find((el) => el.name === "networks")?.settings,
prioritySettings: column.find((el) => el.name === "priority"),
networkId: "",
infoClient: {
@@ -142,10 +140,11 @@ export default {
},
contacts: [
{
id: "network",
kind: "TELEGRAM",
kind: {
id: "TELEGRAM",
icon: "app:icon-tg",
},
username: "",
icon: "icon-tg",
},
],
},
@@ -240,6 +239,16 @@ export default {
return { label: el.text, id: el.id };
});
},
getNetworksList() {
let contacts = [];
this.infoClient.basic.contacts.forEach((elem) =>
contacts.push(elem.kind.id)
);
let filteredNetworks = this.networksSettings.filter(
({ id }) => !contacts.includes(id)
);
return filteredNetworks;
},
},
methods: {
previewImage(event) {
@@ -262,6 +271,7 @@ export default {
!this.showModal ? this.closeForm() : null;
},
createIdentityDocument(id) {
let doc = null;
let filteredData = Object.keys(
this.filterDataEmptyProperty(this.infoClient.identity_document.pass)
);
@@ -281,46 +291,62 @@ export default {
"Паспортные данные не будут записаны в профиль клиента"
);
} else
fetchWrapper.post("general/identity_document/create/", {
series_number: this.infoClient.identity_document.pass.series_number,
issued_by_org: this.infoClient.identity_document.pass.issued_by_org,
issued_by_date: moment(
this.infoClient.identity_document.pass.issued_by_date
).format("YYYY-MM-DD"),
issued_by_org_code:
this.infoClient.identity_document.pass.issued_by_org_code,
person: id,
kind: "Паспорт",
});
fetchWrapper
.post("general/identity_document/create/", {
series_number:
this.infoClient.identity_document.pass.series_number,
issued_by_org:
this.infoClient.identity_document.pass.issued_by_org,
issued_by_date: moment(
this.infoClient.identity_document.pass.issued_by_date
).format("YYYY-MM-DD"),
issued_by_org_code:
this.infoClient.identity_document.pass.issued_by_org_code,
person: id,
kind: "Паспорт",
})
.then((res) => (doc = res));
return Promise.resolve(doc);
}
},
createAddress(id) {
let address = null;
Object.keys(this.filterDataEmptyProperty(this.infoClient.addresses))
.length > 0 &&
fetchWrapper.post("general/address/create/", {
...this.filterDataEmptyProperty(this.infoClient.addresses),
person: id,
});
fetchWrapper
.post("general/address/create/", {
...this.filterDataEmptyProperty(this.infoClient.addresses),
person: id,
})
.then((res) => (address = res));
return Promise.resolve(address);
},
createContacts(id) {
async createContacts(id) {
let phone = null,
email = null,
contacts = [];
if (this.infoClient.phone.username)
fetchWrapper.post("general/contact/create/", {
phone = await fetchWrapper.post("general/contact/create/", {
...this.filterDataEmptyProperty(this.infoClient.phone),
person: id,
});
if (this.infoClient.email.username)
fetchWrapper.post("general/contact/create/", {
email = await fetchWrapper.post("general/contact/create/", {
...this.filterDataEmptyProperty(this.infoClient.email),
person: id,
});
this.infoClient.basic.contacts.forEach((el) => {
if (el.username)
fetchWrapper.post("general/contact/create/", {
kind: el.kind,
username: el.username,
person: id,
});
fetchWrapper
.post("general/contact/create/", {
kind: el.kind.id,
username: el.username,
person: id,
})
.then((res) => contacts.push(res));
});
console.log(Promise.allSettled([phone, email, contacts]));
return Promise.allSettled([phone, email, contacts]);
},
postNewClient() {
const formData = new FormData();
@@ -340,12 +366,16 @@ export default {
.post("general/person/create/", formData, "formData")
.then((result) => {
if (result.id) {
this.createIdentityDocument(result.id);
this.createAddress(result.id);
this.createContacts(result.id);
this.writeCreatedClientId(result.id);
this.setUpdatedClients();
this.addSuccessNotification();
Promise.allSettled([
this.createIdentityDocument(result.id),
this.createAddress(result.id),
this.createContacts(result.id),
]).then((res) => {
console.log(res);
this.writeCreatedClientId(result.id);
this.setUpdatedClients();
this.addSuccessNotification();
});
} else {
this.addErrorNotification(
"Клиент не создан",
@@ -364,13 +394,10 @@ export default {
});
return postData;
},
saveNetworkId(e) {
this.networkId = e.currentTarget.id;
},
choosePriority(e) {
this.infoClient.basic.priority = e.target.id;
},
chooseOptionNetworks(e) {
/*chooseOptionNetworks(e) {
let index = this.infoClient.basic.contacts.findIndex(
(el) => el.id === this.networkId
);
@@ -379,7 +406,7 @@ export default {
).icon;
this.infoClient.basic.contacts[index].kind = e.target.id;
this.infoClient.basic.contacts[index].icon = icon;
},
},*/
saveClient() {
if (this.checkFormFullness()) {
this.postNewClient();
@@ -407,14 +434,15 @@ export default {
});
},
addNewNetwork() {
this.infoClient.basic.contacts.push({
id:
this.infoClient.basic.contacts[0].id +
this.infoClient.basic.contacts.length,
kind: "TELEGRAM",
username: "",
icon: "icon-tg",
});
const newNetwork = this.getNetworksList;
if (newNetwork[0])
this.infoClient.basic.contacts.push({
kind: {
id: newNetwork[0].id,
icon: newNetwork[0].icon,
},
username: "",
});
},
selectForm(componentName) {
this.currentForm = this.forms.find(