0
0
Fork 0

refactor: refs #5447 changed warehouse out filter behavior

This commit is contained in:
Jon Elias 2024-06-10 09:28:38 +02:00
parent 45a6c49907
commit 83d56e5d32
1 changed files with 16 additions and 33 deletions

View File

@ -21,6 +21,7 @@ const warehousesOptions = ref([]);
const continentsOptions = ref([]);
const agenciesOptions = ref([]);
const suppliersOptions = ref([]);
const warehousesByContinent = ref({});
const add = (paramsObj, key) => {
if (paramsObj[key] === undefined) {
@ -36,28 +37,25 @@ const decrement = (paramsObj, key) => {
paramsObj[key]--;
};
const warehousesAm = ref([]);
const warehouses = async () => {
const warehouses = await axios.get('Warehouses');
const countries = await axios.get('Countries');
const continents = await axios.get('Continents', {
params: {
filter: { where: { code: 'AM' } },
},
});
const warehousesResponse = await axios.get('Warehouses');
const countriesResponse = await axios.get('Countries');
const continentsResponse = await axios.get('Continents');
const countryContinent = countries.data.reduce((acc, c) => {
acc[c.id] = c.continentFk;
const countryContinentMap = countriesResponse.data.reduce((acc, country) => {
acc[country.id] = country.continentFk;
return acc;
}, {});
const countriesInAM = Object.keys(countryContinent).filter(
(countryId) => countryContinent[countryId] === continents.data[0].id.toString()
continentsResponse.data.forEach((continent) => {
const countriesInContinent = Object.keys(countryContinentMap).filter(
(countryId) => countryContinentMap[countryId] === continent.id.toString()
);
warehousesAm.value = warehouses.data.filter((w) =>
countriesInAM.includes(w.countryFk.toString())
warehousesByContinent.value[continent.code] = warehousesResponse.data.filter(
(warehouse) => countriesInContinent.includes(warehouse.countryFk.toString())
);
});
};
warehouses();
</script>
@ -173,27 +171,13 @@ warehouses();
/>
</QItemSection>
</QItem>
<QItem>
<QItem v-if="warehousesByContinent[params.continent]">
<QItemSection>
<VnSelect
v-if="params.continent === 'AM'"
:label="t('params.warehouseOutFk')"
v-model="params.warehouseOutFk"
@update:model-value="searchFn()"
:options="warehousesAm"
option-value="id"
option-label="name"
hide-selected
dense
outlined
rounded
/>
<VnSelect
v-else
:label="t('params.warehouseOutFk')"
v-model="params.warehouseOutFk"
@update:model-value="searchFn()"
:options="warehousesOptions"
:options="warehousesByContinent[params.continent]"
option-value="id"
option-label="name"
hide-selected
@ -240,7 +224,6 @@ warehouses();
<VnSelect
:label="t('params.continent')"
v-model="params.continent"
@update:model-value="searchFn()"
:options="continentsOptions"
option-value="code"
option-label="name"