toast replace by modals, and product filters working

This commit is contained in:
María
2025-08-28 13:53:06 +02:00
parent 49855b11fd
commit 71274defb2
5 changed files with 66 additions and 49 deletions

View File

@@ -140,6 +140,13 @@
<ProductsRelated :related-products="relatedProducts" /> <ProductsRelated :related-products="relatedProducts" />
</div> </div>
<ProductModal v-if="modal" :product="product" @close-modal="closeModal" /> <ProductModal v-if="modal" :product="product" @close-modal="closeModal" />
<BModal
id="modal-center"
v-model="active"
centered
title="latienda.coop"
:ok-variant="modalColor"> {{ modalText }}
</BModal>
</div> </div>
</template> </template>
@@ -160,6 +167,9 @@ export default {
modal: false, modal: false,
productUrl: null, productUrl: null,
relatedProducts: null, relatedProducts: null,
active: false,
modalText: '',
modalColor: 'info',
} }
}, },
computed: { computed: {
@@ -274,21 +284,16 @@ export default {
}, },
closeModal(value) { closeModal(value) {
console.log(value)
this.modal = false this.modal = false
if (value === 200) { this.active = true
this.$bvToast.toast(`Email enviado correctamente`, { if (value === 200 || value === 201) {
title: 'latienda.coop', this.modalText = 'Actualizado correctamente'
autoHideDelay: 5000, this.modalColor = 'success'
appendToast: true,
variant: 'success',
})
} else if (value) { } else if (value) {
this.$bvToast.toast(`Se ha producido un error en el envío`, { this.modalText = 'Se ha producido un error en el envío'
title: 'latienda.coop', this.modalColor = 'danger'
autoHideDelay: 5000,
appendToast: true,
variant: 'danger',
})
} }
}, },

View File

@@ -106,6 +106,13 @@
<ProductsRelated :related-products="relatedProducts" /> <ProductsRelated :related-products="relatedProducts" />
</div> </div>
<ProductModal v-if="modal" :product="product" @close-modal="closeModal" /> <ProductModal v-if="modal" :product="product" @close-modal="closeModal" />
<BModal
id="modal-center"
v-model="active"
centered
title="latienda.coop"
:ok-variant="modalColor"> {{ modalText }}
</BModal>
</div> </div>
</template> </template>
@@ -137,6 +144,9 @@ export default {
modal: true, modal: true,
productUrl: null, productUrl: null,
geolocation: null, geolocation: null,
active: false,
modalText: '',
modalColor: 'info',
} }
}, },
computed: { computed: {
@@ -161,19 +171,13 @@ export default {
}, },
closeModal(value) { closeModal(value) {
this.modal = false this.modal = false
if (value === 200) { if (value === 200 || value === 201) {
this.$bvToast.toast(`Email enviado correctamente`, { this.modalText = 'Actualizado correctamente'
title: 'latienda.coop', this.modalColor = 'success'
autoHideDelay: 5000,
appendToast: true,
})
} else if (value) { } else if (value) {
this.$bvToast.toast(`Se ha producido un error en el envío`, { this.modalText = 'Se ha producido un error en el envío'
title: 'latienda.coop', this.modalColor = 'danger'
autoHideDelay: 5000,
appendToast: true,
variant: 'danger',
})
} }
}, },
// TODO: implement buyIntent (review functionality, because sendLog is not working) // TODO: implement buyIntent (review functionality, because sendLog is not working)

View File

@@ -182,7 +182,7 @@ export default {
}) })
}, },
handleEmit() { handleEmit() {
this.$emit('closeModal') this.$emit('closeModal', null)
}, },
}, },
} }

View File

@@ -58,12 +58,13 @@
<h2 class="title"></h2> <h2 class="title"></h2>
<p class="count">Hay {{ count }} productos</p> <p class="count">Hay {{ count }} productos</p>
</div> </div>
<div v-if="products.length !== 0"> <div v-if="products.length !== 0">
<div v-for="product in products" :key="product.id"> <div v-for="product in products" :key="product.id">
<ProductCard :key="product.key" :product="product" /> <ProductCard :key="product.key" :product="product" />
</div> </div>
<BPagination <BPagination
v-model="currentPage" v-model="currentPage"
class="pagination" class="pagination"
:total-rows="count" :total-rows="count"
:per-page="perPage" :per-page="perPage"
@@ -82,6 +83,7 @@
</div> </div>
</div> </div>
</div> </div>
<!-- appliedFilters: {{appliedFilters}} <br> <!-- appliedFilters: {{appliedFilters}} <br>
filters: {{filters}} <br> filters: {{filters}} <br>
prices: {{prices}} <br> prices: {{prices}} <br>
@@ -126,7 +128,7 @@ export default {
defaultProducts: [], defaultProducts: [],
carouselProducts: [], carouselProducts: [],
count: 0, count: 0,
loadingProducts: true loadingProducts: true,
} }
}, },
@@ -139,15 +141,21 @@ export default {
(Array.isArray(this.appliedFilters.category) && (Array.isArray(this.appliedFilters.category) &&
this.appliedFilters.category.length > 0) this.appliedFilters.category.length > 0)
) )
}, }
}, },
watch: { watch: {
$route() { '$route.query'(newValue) {
console.log('New Value:', newValue)
console.log('Route changed:', this.$route.fullPath)
console.log('Current params:', this.$route.query)
this.updateData(newValue)
Object.assign(this.$data, this.$options.data()) Object.assign(this.$data, this.$options.data())
},
}
}, },
async beforeCreate() { async beforeCreate() {
const config = useRuntimeConfig() const config = useRuntimeConfig()
const params = import.meta.client ? clientSearch(this.$route.query) : serverSearch(this.$route.query) const params = import.meta.client ? clientSearch(this.$route.query) : serverSearch(this.$route.query)
@@ -250,20 +258,23 @@ export default {
return data.products return data.products
}, },
updateData(value) { async updateData(value) {
console.log('updateData called with:', value)
const filters = { q: this.appliedFilters.q } const filters = { q: this.appliedFilters.q }
const query = Object.keys(value).length === 0 ? { ...filters } : { ...value, ...filters }
if (Object.keys(value).length === 0) { //Review this condition this.$router.push({ name: 'busqueda', query })
return this.$router.push({
name: 'busqueda', const config = useRuntimeConfig()
query: { ...filters }, const data = await $fetch('/search_products/', {
}) baseURL: config.public.baseURL,
} else { method: 'GET',
return this.$router.push({ params: query,
name: 'busqueda', headers: { Authorization: '/' },
query: { ...value, ...filters }, })
}) this.products = data.products
} this.count = data.count
this.loadingProducts = false
}, },
removeCategory(cat) { removeCategory(cat) {

View File

@@ -133,12 +133,9 @@ export default {
async created() { async created() {
if (this.$route.params.action === 'created') { if (this.$route.params.action === 'created') {
this.$bvToast.toast(`Producto creado`, { this.modalText = 'Producto creado correctamente'
title: 'latienda.coop', this.modalColor = 'success'
autoHideDelay: 5000, this.activeModal = true
appendToast: true,
variant: 'success',
})
} }
await this.getDataFromApi() await this.getDataFromApi()
}, },