diff --git a/src/pages/Travel/ExtraCommunityFilter.vue b/src/pages/Travel/ExtraCommunityFilter.vue index 7fe628180..78905ee5f 100644 --- a/src/pages/Travel/ExtraCommunityFilter.vue +++ b/src/pages/Travel/ExtraCommunityFilter.vue @@ -7,6 +7,7 @@ import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue'; import VnSelect from 'src/components/common/VnSelect.vue'; import VnInput from 'src/components/common/VnInput.vue'; import VnInputDate from 'components/common/VnInputDate.vue'; +import axios from 'axios'; const { t } = useI18n(); const props = defineProps({ @@ -20,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) { @@ -34,6 +36,28 @@ const decrement = (paramsObj, key) => { paramsObj[key]--; }; + +const warehouses = async () => { + const warehousesResponse = await axios.get('Warehouses'); + const countriesResponse = await axios.get('Countries'); + const continentsResponse = await axios.get('Continents'); + + const countryContinentMap = countriesResponse.data.reduce((acc, country) => { + acc[country.id] = country.continentFk; + return acc; + }, {}); + + continentsResponse.data.forEach((continent) => { + const countriesInContinent = Object.keys(countryContinentMap).filter( + (countryId) => countryContinentMap[countryId] === continent.id.toString() + ); + + warehousesByContinent.value[continent.code] = warehousesResponse.data.filter( + (warehouse) => countriesInContinent.includes(warehouse.countryFk.toString()) + ); + }); +}; +warehouses();