From af5f87a6a13397c9cdf8a1744459b1b70bee60fa Mon Sep 17 00:00:00 2001 From: Kevin Martinez Date: Wed, 20 Dec 2023 01:52:28 -0400 Subject: [PATCH] Add catalog filter --- src/components/ui/VnFilterPanel.vue | 33 ++-- src/pages/Order/Card/OrderCatalogFilter.vue | 205 ++++++++++++++++++++ src/pages/Order/OrderCatalog.vue | 5 +- 3 files changed, 229 insertions(+), 14 deletions(-) create mode 100644 src/pages/Order/Card/OrderCatalogFilter.vue diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 84893b667..6f6183224 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -31,11 +31,21 @@ const props = defineProps({ description: 'Algunos filtros vienen con parametros de búsqueda por default y necesitan tener si o si un valor, por eso de ser necesario, esta prop nos sirve para saber que filtros podemos remover y cuales no', }, + exprBuilder: { + type: Function, + default: null, + }, + hiddenTags: { + type: Array, + default: () => [], + }, }); -const emit = defineEmits(['refresh', 'clear', 'search']); +const emit = defineEmits(['refresh', 'clear', 'search', 'init']); -const arrayData = useArrayData(props.dataKey); +const arrayData = useArrayData(props.dataKey, { + exprBuilder: props.exprBuilder, +}); const store = arrayData.store; const userParams = ref({}); @@ -44,9 +54,11 @@ onMounted(() => { if (Object.keys(store.userParams).length > 0) { userParams.value = JSON.parse(JSON.stringify(store.userParams)); } + emit('init', { params: userParams.value }); }); const isLoading = ref(false); + async function search() { isLoading.value = true; const params = { ...userParams.value }; @@ -93,17 +105,12 @@ async function clearFilters() { } const tags = computed(() => { - const params = []; - - for (const param in userParams.value) { - if (!userParams.value[param]) continue; - params.push({ - label: param, - value: userParams.value[param], - }); - } - - return params; + return Object.entries(userParams.value) + .filter(([key, value]) => value && !(props.hiddenTags || []).includes(key)) + .map(([key, value]) => ({ + label: key, + value: value, + })); }); async function remove(key) { diff --git a/src/pages/Order/Card/OrderCatalogFilter.vue b/src/pages/Order/Card/OrderCatalogFilter.vue new file mode 100644 index 000000000..792a5606e --- /dev/null +++ b/src/pages/Order/Card/OrderCatalogFilter.vue @@ -0,0 +1,205 @@ + + + + + + + +en: + params: + type: Type + orderBy: Order By +es: + params: + type: Tipo + orderBy: Ordenar por + Plant: Planta + Flower: Flor + Handmade: Confección + Green: Verde + Accessories: Complemento + Fruit: Fruta + diff --git a/src/pages/Order/OrderCatalog.vue b/src/pages/Order/OrderCatalog.vue index f4cb3fa33..ec81c50f1 100644 --- a/src/pages/Order/OrderCatalog.vue +++ b/src/pages/Order/OrderCatalog.vue @@ -6,6 +6,7 @@ import { useI18n } from 'vue-i18n'; import VnPaginate from 'components/ui/VnPaginate.vue'; import VnSearchbar from 'components/ui/VnSearchbar.vue'; import OrderCatalogItem from 'pages/Order/Card/OrderCatalogItem.vue'; +import OrderCatalogFilter from 'pages/Order/Card/OrderCatalogFilter.vue'; const route = useRoute(); const stateStore = useStateStore(); @@ -54,7 +55,9 @@ function exprBuilder(param, value) { - + + +