From 606f4f08920289aebb569bfda030f2bd57b706ab Mon Sep 17 00:00:00 2001 From: Kevin Martinez Date: Tue, 2 Jan 2024 11:40:07 -0400 Subject: [PATCH] Implement orders catalog tag filter --- src/components/ui/VnFilterPanel.vue | 3 +- src/pages/Order/Card/OrderCatalogFilter.vue | 171 ++++++++++++++++++-- src/pages/Order/OrderCatalog.vue | 22 ++- 3 files changed, 183 insertions(+), 13 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 6f6183224..a138e0b64 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -41,7 +41,7 @@ const props = defineProps({ }, }); -const emit = defineEmits(['refresh', 'clear', 'search', 'init']); +const emit = defineEmits(['refresh', 'clear', 'search', 'init', 'remove']); const arrayData = useArrayData(props.dataKey, { exprBuilder: props.exprBuilder, @@ -116,6 +116,7 @@ const tags = computed(() => { async function remove(key) { userParams.value[key] = null; await search(); + emit('remove', key) } function formatValue(value) { diff --git a/src/pages/Order/Card/OrderCatalogFilter.vue b/src/pages/Order/Card/OrderCatalogFilter.vue index 46de63abd..00606d57c 100644 --- a/src/pages/Order/Card/OrderCatalogFilter.vue +++ b/src/pages/Order/Card/OrderCatalogFilter.vue @@ -6,6 +6,7 @@ import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue'; import VnSelectFilter from 'components/common/VnSelectFilter.vue'; import axios from 'axios'; import { useRoute } from 'vue-router'; +import VnInput from 'components/common/VnInput.vue'; const { t } = useI18n(); const route = useRoute(); @@ -14,6 +15,10 @@ const props = defineProps({ type: String, required: true, }, + tags: { + type: Array, + required: true, + }, }); const categoryList = ref(null); @@ -21,16 +26,27 @@ const selectedCategoryFk = ref(null); const typeList = ref(null); const selectedTypeFk = ref(null); -const selectCategory = (params, category) => { +const resetCategory = () => { + selectedCategoryFk.value = null; + typeList.value = null; +}; + +const clearFilter = (key) => { + if (key === 'categoryFk') { + resetCategory(); + } +}; + +const selectCategory = (params, category, search) => { if (params.categoryFk === category?.id) { - selectedCategoryFk.value = null; + resetCategory(); params.categoryFk = null; - typeList.value = null; } else { selectedCategoryFk.value = category?.id; params.categoryFk = category?.id; loadTypes(category?.id); } + search(); }; const loadTypes = async (categoryFk) => { @@ -67,6 +83,27 @@ function exprBuilder(param, value) { return { [param]: value }; } } + +const selectedTag = ref(null); +const tagValues = ref([{}]); +const tagOptions = ref(null); + +const applyTagFilter = (params, search) => { + if (!tagValues.value?.length) { + params.tagGroups = null; + search(); + return; + } + params.tagGroups = JSON.stringify({ + values: tagValues.value, + tagSelection: { + ...selectedTag.value, + orgShowField: selectedTag.value.name, + }, + tagFk: selectedTag.value.tagFk, + }); + search(); +};