From 1346a2e7fd52f8811ac0b2efbd0c03676becca1f Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 22 Oct 2024 12:05:44 +0200 Subject: [PATCH] fix: tag chips --- src/pages/Order/Card/OrderCatalogFilter.vue | 113 +++++++++----------- 1 file changed, 50 insertions(+), 63 deletions(-) diff --git a/src/pages/Order/Card/OrderCatalogFilter.vue b/src/pages/Order/Card/OrderCatalogFilter.vue index 850212a62..0fe8c4d64 100644 --- a/src/pages/Order/Card/OrderCatalogFilter.vue +++ b/src/pages/Order/Card/OrderCatalogFilter.vue @@ -6,8 +6,8 @@ import axios from 'axios'; import FetchData from 'components/FetchData.vue'; import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue'; import VnSelect from 'components/common/VnSelect.vue'; -// import VnInput from 'src/components/common/VnInput.vue'; import getParamWhere from 'src/filters/getParamWhere'; +import VnFilterPanelChip from 'src/components/ui/VnFilterPanelChip.vue'; const { t } = useI18n(); @@ -49,6 +49,7 @@ const orderWaySelected = ref('ASC'); const routeQuery = JSON.parse(route?.query.params ?? '{}'); const paramsSearch = ref({}); +const tagData = ref([]); onMounted(() => { paramsSearch.value = JSON.parse(routeQuery.filter ?? '{}')?.where ?? {}; @@ -120,32 +121,6 @@ const selectedType = computed(() => { return (typeList.value || []).find((type) => type?.id === selectedTypeFk.value); }); -// const applyTagFilter = (params, search) => { - -// if (params.tagGroups) params.tagGroups = null; -// if (!tagValues.value?.length) { -// params.tagGroups = null; -// search(); -// return; -// } -// if (!params.tagGroups) { -// params.tagGroups = []; -// } -// params.tagGroups.push( -// JSON.stringify({ -// values: tagValues.value.filter((obj) => Object.keys(obj).length > 0), -// tagSelection: { -// ...selectedTag.value, -// orgShowField: selectedTag?.value?.name, -// }, -// tagFk: selectedTag?.value?.tagFk, -// }) -// ); -// search(); -// selectedTag.value = null; -// tagValues.value = [{}]; -// }; - const applyTagFilter = (params, search) => { if (!tagValues.value?.length) { params.tagGroups = null; @@ -153,27 +128,46 @@ const applyTagFilter = (params, search) => { return; } - if (!params.tagGroups) { + if (!params.tagGroups || typeof params.tagGroups === 'string') { params.tagGroups = []; - } else if (typeof params.tagGroups === 'string') { - params.tagGroups = [params.tagGroups]; } - const newTagGroup = JSON.stringify({ - values: tagValues.value.filter((obj) => Object.keys(obj).length > 0), - tagSelection: { - ...selectedTag.value, - orgShowField: selectedTag?.value?.name, - }, - tagFk: selectedTag?.value?.tagFk, - }); - params.tagGroups.push(newTagGroup); + params.tagGroups.push( + JSON.stringify({ + values: tagValues.value.filter((obj) => Object.keys(obj).length > 0), + tagSelection: { + ...selectedTag.value, + orgShowField: selectedTag?.value?.name, + }, + tagFk: selectedTag?.value?.tagFk, + }) + ); + tagData.value.push(JSON.parse(params.tagGroups[params.tagGroups.length - 1])); search(); selectedTag.value = null; tagValues.value = [{}]; }; +const removeTagChip = (selection, params, search) => { + if (typeof params.tagGroups === 'string') { + try { + params.tagGroups = JSON.parse(params.tagGroups); + } catch (error) { + console.error('Error parsing tagGroups:', error); + params.tagGroups = []; + } + } + console.log('params.tagGroups: ', params.tagGroups); + console.log('selection: ', selection); + + if (Array.isArray(params.tagGroups)) { + params.tagGroups = params.tagGroups.filter((value) => value !== selection); + } + + search(); +}; + const setCategoryList = (data) => { categoryList.value = (data || []) .filter((category) => category.display) @@ -198,22 +192,6 @@ function addOrder(value, field, params) { params.orderBy = JSON.stringify(orderBy); vnFilterPanelRef.value.search(); } - -const data = ref([]); - -function getTagData(value) { - if (Array.isArray(value) && value.length >= 1) { - const parsedTags = value.map((obj) => JSON.parse(obj)); - - if (parsedTags.length === 1) { - data.value = parsedTags[0]; - } else { - data.value = parsedTags; - } - } else { - data.value = JSON.parse(value); - } -}