diff --git a/components/ProductFilter.vue b/components/ProductFilter.vue index 4d1f355..9d77316 100644 --- a/components/ProductFilter.vue +++ b/components/ProductFilter.vue @@ -1,129 +1,120 @@ @@ -133,23 +124,23 @@ export default { props: { filters: { type: Object, - default: () => ({}) + default: () => ({}), }, prices: { type: Object, - default: () => ({}) + default: () => ({}), }, currentFilters: { type: Object, - default: () => ({}) + default: () => ({}), }, geo: { type: Object, - default: () => ({}) - } + default: () => ({}), + }, }, - emits: ['applyFilters'], + emits: ["applyFilters"], data() { return { @@ -157,87 +148,101 @@ export default { shipping_cost: false, discount: false, }, + screenSize: null, visible: true, checkedCategories: [], categories: [ - 'Alimentación', - 'Agricultura ', - 'Energía', - 'Hogar y jardín', - 'Moda y Textil', - 'Salud y Cuidados', - 'Movilidad y Mensajería', - 'Ocio y Deporte', - 'Turismo y Gastronomía', - 'Cultura, Educación y Medios', - 'Tecnología y Servicios Digitales', - 'Economía Circular y Reparación', - 'Finanzas Éticas y Seguros', - 'Servicios Profesionales', + "Alimentación", + "Agricultura ", + "Energía", + "Hogar y jardín", + "Moda y Textil", + "Salud y Cuidados", + "Movilidad y Mensajería", + "Ocio y Deporte", + "Turismo y Gastronomía", + "Cultura, Educación y Medios", + "Tecnología y Servicios Digitales", + "Economía Circular y Reparación", + "Finanzas Éticas y Seguros", + "Servicios Profesionales", ], priceRange: [0, 500], priceRangeFilter: {}, place: null, coordinates: null, - } + }; + }, + + computed: { + isMobile() { + return this.screenSize <= 768; + }, }, watch: { currentFilters(newCurrentFilters) { if (newCurrentFilters) { - if (newCurrentFilters['category']) { - this.checkedCategories = newCurrentFilters['category'] + if (newCurrentFilters["category"]) { + this.checkedCategories = newCurrentFilters["category"]; } else { - this.checkedCategories = [] + this.checkedCategories = []; } - if (Object.keys(newCurrentFilters).includes('shipping_cost')) { - this.filterForm.shipping_cost = true + if (Object.keys(newCurrentFilters).includes("shipping_cost")) { + this.filterForm.shipping_cost = true; } else { - this.filterForm.shipping_cost = false + this.filterForm.shipping_cost = false; } } - this.filterForm.discount = this.$route.query.hasOwnProperty('discount') + this.filterForm.discount = this.$route.query.hasOwnProperty("discount"); }, prices(newPrices) { if (newPrices.min && newPrices.max) { - this.priceRange = [newPrices.min, newPrices.max] + this.priceRange = [newPrices.min, newPrices.max]; } }, }, mounted() { if (this.prices.min && this.prices.max) { - this.priceRange = [this.prices.min, this.prices.max] + this.priceRange = [this.prices.min, this.prices.max]; } + this.screenSize = window.innerWidth; + window.addEventListener("resize", () => { + this.screenSize = window.innerWidth; + }); + }, + beforeUnmount() { + window.removeEventListener("resize", () => { + this.screenSize = window.innerWidth; + }); }, methods: { getPlace(value) { - this.place = value + this.place = value; }, applyFilters() { - const filters = {} - filters.price_min = this.priceRange[0] - filters.price_max = this.priceRange[1] - if (this.filterForm.shipping_cost) filters.shipping_cost = false - if (this.filterForm.discount) filters.discount = true - filters.category = this.checkedCategories + const filters = {}; + filters.price_min = this.priceRange[0]; + filters.price_max = this.priceRange[1]; + if (this.filterForm.shipping_cost) filters.shipping_cost = false; + if (this.filterForm.discount) filters.discount = true; + filters.category = this.checkedCategories; if (this.place) { - filters.latitude = this.place.geo.latitude - filters.longitude = this.place.geo.longitude + filters.latitude = this.place.geo.latitude; + filters.longitude = this.place.geo.longitude; } - this.$emit('applyFilters', filters) + this.$emit("applyFilters", filters); }, }, -} +};