forked from verdnatura/salix-front
refactor: refs #5447 changed warehouse out filter behavior
This commit is contained in:
parent
45a6c49907
commit
83d56e5d32
|
@ -21,6 +21,7 @@ const warehousesOptions = ref([]);
|
||||||
const continentsOptions = ref([]);
|
const continentsOptions = ref([]);
|
||||||
const agenciesOptions = ref([]);
|
const agenciesOptions = ref([]);
|
||||||
const suppliersOptions = ref([]);
|
const suppliersOptions = ref([]);
|
||||||
|
const warehousesByContinent = ref({});
|
||||||
|
|
||||||
const add = (paramsObj, key) => {
|
const add = (paramsObj, key) => {
|
||||||
if (paramsObj[key] === undefined) {
|
if (paramsObj[key] === undefined) {
|
||||||
|
@ -36,28 +37,25 @@ const decrement = (paramsObj, key) => {
|
||||||
paramsObj[key]--;
|
paramsObj[key]--;
|
||||||
};
|
};
|
||||||
|
|
||||||
const warehousesAm = ref([]);
|
|
||||||
const warehouses = async () => {
|
const warehouses = async () => {
|
||||||
const warehouses = await axios.get('Warehouses');
|
const warehousesResponse = await axios.get('Warehouses');
|
||||||
const countries = await axios.get('Countries');
|
const countriesResponse = await axios.get('Countries');
|
||||||
const continents = await axios.get('Continents', {
|
const continentsResponse = await axios.get('Continents');
|
||||||
params: {
|
|
||||||
filter: { where: { code: 'AM' } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const countryContinent = countries.data.reduce((acc, c) => {
|
const countryContinentMap = countriesResponse.data.reduce((acc, country) => {
|
||||||
acc[c.id] = c.continentFk;
|
acc[country.id] = country.continentFk;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const countriesInAM = Object.keys(countryContinent).filter(
|
continentsResponse.data.forEach((continent) => {
|
||||||
(countryId) => countryContinent[countryId] === continents.data[0].id.toString()
|
const countriesInContinent = Object.keys(countryContinentMap).filter(
|
||||||
|
(countryId) => countryContinentMap[countryId] === continent.id.toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
warehousesAm.value = warehouses.data.filter((w) =>
|
warehousesByContinent.value[continent.code] = warehousesResponse.data.filter(
|
||||||
countriesInAM.includes(w.countryFk.toString())
|
(warehouse) => countriesInContinent.includes(warehouse.countryFk.toString())
|
||||||
);
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
warehouses();
|
warehouses();
|
||||||
</script>
|
</script>
|
||||||
|
@ -173,27 +171,13 @@ warehouses();
|
||||||
/>
|
/>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem>
|
<QItem v-if="warehousesByContinent[params.continent]">
|
||||||
<QItemSection>
|
<QItemSection>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
v-if="params.continent === 'AM'"
|
|
||||||
:label="t('params.warehouseOutFk')"
|
:label="t('params.warehouseOutFk')"
|
||||||
v-model="params.warehouseOutFk"
|
v-model="params.warehouseOutFk"
|
||||||
@update:model-value="searchFn()"
|
@update:model-value="searchFn()"
|
||||||
:options="warehousesAm"
|
:options="warehousesByContinent[params.continent]"
|
||||||
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"
|
|
||||||
option-value="id"
|
option-value="id"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
hide-selected
|
hide-selected
|
||||||
|
@ -240,7 +224,6 @@ warehouses();
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('params.continent')"
|
:label="t('params.continent')"
|
||||||
v-model="params.continent"
|
v-model="params.continent"
|
||||||
@update:model-value="searchFn()"
|
|
||||||
:options="continentsOptions"
|
:options="continentsOptions"
|
||||||
option-value="code"
|
option-value="code"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
|
|
Loading…
Reference in New Issue