0
0
Fork 0

feat(orderList): correct create order

This commit is contained in:
Alex Moreno 2024-08-09 14:19:08 +02:00
parent ee71ae9d24
commit dc7c686508
1 changed files with 54 additions and 31 deletions

View File

@ -15,9 +15,9 @@ import OrderFilter from './Card/OrderFilter.vue';
const { t } = useI18n(); const { t } = useI18n();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
const tableRef = ref(); const tableRef = ref();
const clientList = ref([]);
const agencyList = ref([]); const agencyList = ref([]);
const selectedAddress = ref(); const addressesList = ref([]);
const clientId = ref();
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -102,20 +102,19 @@ const columns = computed(() => [
align: 'left', align: 'left',
name: 'agencyModeFk', name: 'agencyModeFk',
label: t('module.agency'), label: t('module.agency'),
component: 'select', format: (row) => row?.agencyName,
cardVisible: true, columnFilter: {
attrs: { component: 'select',
url: 'agencyModes', attrs: {
fields: ['id', 'name'], url: 'agencyModes',
find: { fields: ['id', 'name'],
value: 'agencyModeFk', find: {
label: 'agencyName', value: 'agencyModeFk',
label: 'agencyName',
},
}, },
}, },
columnField: { cardVisible: true,
component: null,
},
format: (row) => row?.agencyName,
}, },
{ {
align: 'left', align: 'left',
@ -138,10 +137,22 @@ const columns = computed(() => [
}, },
]); ]);
async function fetchClientAddress(id, data) { async function fetchClientAddress(id, formData) {
const clientData = await axios.get(`Clients/${id}`); const { data } = await axios.get(`Clients/${id}`, {
selectedAddress.value = clientData.data.defaultAddressFk; params: { filter: { include: { relation: 'addresses' } } },
data.addressId = selectedAddress.value; });
addressesList.value = data.addresses;
formData.addressId = data.defaultAddressFk;
fetchAgencies(formData);
}
async function fetchAgencies({ landed, addressId }) {
if (!landed || !addressId) return (agencyList.value = []);
const { data } = await axios.get('Agencies/landsThatDay', {
params: { addressFk: addressId, landed },
});
agencyList.value = data;
} }
</script> </script>
<template> <template>
@ -175,29 +186,41 @@ async function fetchClientAddress(id, data) {
<template #more-create-dialog="{ data }"> <template #more-create-dialog="{ data }">
<VnSelect <VnSelect
url="Clients" url="Clients"
v-model="data.id" :include="{ relation: 'addresses' }"
v-model="clientId"
:label="t('module.customer')" :label="t('module.customer')"
:options="clientList"
option-value="id"
option-label="name"
@update:model-value="(id) => fetchClientAddress(id, data)" @update:model-value="(id) => fetchClientAddress(id, data)"
/> />
<VnSelect <VnSelect
url="Clients" v-model="data.addressId"
v-model="selectedAddress" :options="addressesList"
:label="t('module.address')" :label="t('module.address')"
:options="selectedAddress" option-value="id"
option-value="defaultAddressFk" option-label="nickname"
option-label="street" @update:model-value="() => fetchAgencies(data)"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel>
{{ scope.opt?.nickname }}: {{ scope.opt?.street }},
{{ scope.opt?.city }}</QItemLabel
>
</QItemSection>
</QItem>
</template>
</VnSelect>
<VnInputDate
v-model="data.landed"
:label="t('module.landed')"
@update:model-value="() => fetchAgencies(data)"
/> />
<VnInputDate v-model="data.landed" :label="t('module.landed')" />
<VnSelect <VnSelect
url="Agencies"
v-model="data.agencyModeId" v-model="data.agencyModeId"
:label="t('module.agency')" :label="t('module.agency')"
:options="agencyList" :options="agencyList"
option-value="id" option-value="agencyModeFk"
option-label="name" option-label="agencyMode"
/> />
</template> </template>
</VnTable> </VnTable>