fix: #6943 createOrder from customer

This commit is contained in:
Javier Segarra 2024-11-13 11:49:29 +01:00
parent 0632b939a1
commit c72c8205f1
2 changed files with 12 additions and 20 deletions

View File

@ -203,7 +203,10 @@ const setData = (entity) => (data.value = useCardDescription(entity?.name, entit
table: JSON.stringify({
clientFk: entity.id,
}),
createForm: JSON.stringify({ clientFk: entity.id }),
createForm: JSON.stringify({
clientFk: entity.id,
addressId: entity.defaultAddressFk,
}),
},
}"
size="md"

View File

@ -141,25 +141,19 @@ const columns = computed(() => [
],
},
]);
const formInitialData = {
active: true,
addressId: null,
clientFk: null,
};
onMounted(() => {
if (!route.query.createForm) return;
const clientId = route.query.createForm;
const id = JSON.parse(clientId);
fetchClientAddress(id.clientFk, formInitialData);
fetchClientAddress(id.clientFk);
});
async function fetchClientAddress(id, formData) {
async function fetchClientAddress(id, formData = {}) {
const { data } = await axios.get(`Clients/${id}`, {
params: { filter: { include: { relation: 'addresses' } } },
});
addressesList.value = data.addresses;
formData.addressId = data.defaultAddressFk;
fetchAgencies(formData);
return formData.addressId;
}
async function fetchAgencies({ landed, addressId }) {
@ -188,7 +182,6 @@ const getDateColor = (date) => {
<OrderFilter data-key="OrderList" />
</template>
</RightMenu>
<VnTable
ref="tableRef"
data-key="OrderList"
@ -200,7 +193,11 @@ const getDateColor = (date) => {
onDataSaved: (url) => {
tableRef.redirect(url);
},
formInitialData,
formInitialData: {
active: true,
addressId: null,
clientFk: null,
},
}"
:user-params="{ showEmpty: false }"
:right-search="false"
@ -227,20 +224,12 @@ const getDateColor = (date) => {
</span>
</template>
<template #more-create-dialog="{ data }">
{{ formInitialData }}
{{ data }}
<VnSelect
url="Clients"
:include="{ relation: 'addresses' }"
v-model="data.clientFk"
:label="t('module.customer')"
@update:model-value="
(id) => {
const addressId = fetchClientAddress(id, data);
console.error('addressId', addressId);
data.addressId = addressId;
}
"
@update:model-value="(id) => fetchClientAddress(id, data)"
/>
<VnSelect
v-model="data.addressId"