0
0
Fork 0

fix(CatalogFilterValueDialog): from dev and fix

This commit is contained in:
Alex Moreno 2024-11-20 13:38:22 +01:00
parent 32fdc836f9
commit abd79283ff
3 changed files with 79 additions and 38 deletions

View File

@ -59,15 +59,6 @@ const getSelectedTagValues = async (tag) => {
<template> <template>
<QForm @submit="applyTags(tagValues)" class="all-pointer-events"> <QForm @submit="applyTags(tagValues)" class="all-pointer-events">
<QCard class="q-pa-sm column q-pa-lg"> <QCard class="q-pa-sm column q-pa-lg">
<QBtn
round
color="primary"
style="position: absolute; z-index: 1; right: 0; top: 0"
icon="search"
type="submit"
>
</QBtn>
<VnSelect <VnSelect
:label="t('params.tag')" :label="t('params.tag')"
v-model="selectedTag" v-model="selectedTag"
@ -82,16 +73,6 @@ const getSelectedTagValues = async (tag) => {
use-input use-input
@update:model-value="($event) => getSelectedTagValues($event)" @update:model-value="($event) => getSelectedTagValues($event)"
/> />
<QBtn
icon="add_circle"
shortcut="+"
flat
class="filter-icon q-mb-md"
size="md"
dense
:disabled="!selectedTag || !tagValues[0].value"
@click="tagValues.unshift({})"
/>
<div <div
v-for="(value, index) in tagValues" v-for="(value, index) in tagValues"
:key="value" :key="value"
@ -120,7 +101,6 @@ const getSelectedTagValues = async (tag) => {
:label="t('components.itemsFilterPanel.value')" :label="t('components.itemsFilterPanel.value')"
:disable="!value" :disable="!value"
is-outlined is-outlined
:is-clearable="false"
class="col" class="col"
/> />
<QBtn <QBtn
@ -131,11 +111,25 @@ const getSelectedTagValues = async (tag) => {
rounded rounded
flat flat
class="filter-icon col-2" class="filter-icon col-2"
:disabled="!value.value" @click="tagValues.splice(index, 1)"
@click="removeTagGroupParam(index)"
/> />
</div> </div>
</div> </div>
<QBtn
icon="add_circle"
shortcut="+"
flat
class="filter-icon q-mb-md"
size="md"
dense
@click="tagValues.push({})"
/>
<QBtn
color="primary"
icon="search"
type="submit"
:label="$t('globals.search')"
/>
</QCard> </QCard>
</QForm> </QForm>
</template> </template>

View File

@ -1,30 +1,57 @@
<script setup> <script setup>
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { onMounted, onUnmounted, ref } from 'vue'; import { onBeforeMount, onMounted, onUnmounted, ref, computed, watch } from 'vue';
import axios from 'axios'; import axios from 'axios';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import VnPaginate from 'components/ui/VnPaginate.vue'; import VnPaginate from 'components/ui/VnPaginate.vue';
import CatalogItem from 'components/ui/CatalogItem.vue'; import CatalogItem from 'components/ui/CatalogItem.vue';
import OrderCatalogFilter from 'pages/Order/Card/OrderCatalogFilter.vue'; import OrderCatalogFilter from 'pages/Order/Card/OrderCatalogFilter.vue';
import VnSearchbar from 'src/components/ui/VnSearchbar.vue'; import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
import getParamWhere from 'src/filters/getParamWhere';
import { useArrayData } from 'composables/useArrayData';
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const stateStore = useStateStore(); const stateStore = useStateStore();
const { t } = useI18n(); const { t } = useI18n();
const arrayData = useArrayData('OrderCatalogList');
const store = arrayData.store;
const showFilter = ref(null);
const tags = ref([]); const tags = ref([]);
let catalogParams = {
orderFk: route.params.id,
orderBy: JSON.stringify({ field: 'relevancy DESC, name', way: 'ASC', isTag: false }),
};
onBeforeMount(() => {
const whereParams = getParamWhere(route);
if (whereParams) {
const formattedWhereParams = {};
if (whereParams.and) {
whereParams.and.forEach((item) => {
Object.assign(formattedWhereParams, item);
});
} else {
Object.assign(formattedWhereParams, whereParams);
}
catalogParams = {
...catalogParams,
...formattedWhereParams,
};
} else {
showFilter.value = true;
}
});
onMounted(() => { onMounted(() => {
stateStore.rightDrawer = true; stateStore.rightDrawer = true;
checkOrderConfirmation(); checkOrderConfirmation();
}); });
onUnmounted(() => (stateStore.rightDrawer = false));
const catalogParams = { onUnmounted(() => (stateStore.rightDrawer = false));
orderFk: route.params.id,
orderBy: JSON.stringify({ field: 'relevancy DESC, name', way: 'ASC', isTag: false }),
};
async function checkOrderConfirmation() { async function checkOrderConfirmation() {
const response = await axios.get(`Orders/${route.params.id}`); const response = await axios.get(`Orders/${route.params.id}`);
@ -34,6 +61,7 @@ async function checkOrderConfirmation() {
} }
function extractTags(items) { function extractTags(items) {
if (!items || !items.length) return;
const resultTags = []; const resultTags = [];
(items || []).forEach((item) => { (items || []).forEach((item) => {
(item.tags || []).forEach((tag) => { (item.tags || []).forEach((tag) => {
@ -61,6 +89,15 @@ function extractValueTags(items) {
); );
tagValue.value = resultValueTags; tagValue.value = resultValueTags;
} }
const autoLoad = computed(() => !!catalogParams.categoryFk);
watch(
() => store.data,
(val) => {
extractTags(val);
},
{ immediate: true }
);
</script> </script>
<template> <template>
@ -74,11 +111,12 @@ function extractValueTags(items) {
:info="t('You can search items by name or id')" :info="t('You can search items by name or id')"
/> />
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above> <QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
<QScrollArea class="fit text-grey-8"> <QScrollArea v-if="showFilter" class="fit text-grey-8">
<OrderCatalogFilter <OrderCatalogFilter
data-key="OrderCatalogList" data-key="OrderCatalogList"
:tag-value="tagValue" :tag-value="tagValue"
:tags="tags" :tags="tags"
:initial-catalog-params="catalogParams"
/> />
</QScrollArea> </QScrollArea>
</QDrawer> </QDrawer>
@ -89,8 +127,9 @@ function extractValueTags(items) {
url="Orders/CatalogFilter" url="Orders/CatalogFilter"
:limit="50" :limit="50"
:user-params="catalogParams" :user-params="catalogParams"
@on-fetch="extractTags" @on-fetch="showFilter = true"
:update-router="false" :update-router="false"
:auto-load="autoLoad"
> >
<template #body="{ rows }"> <template #body="{ rows }">
<div class="catalog-list"> <div class="catalog-list">
@ -102,6 +141,7 @@ function extractValueTags(items) {
:key="row.id" :key="row.id"
:item="row" :item="row"
is-catalog is-catalog
class="fill-icon"
/> />
</div> </div>
</template> </template>

View File

@ -59,20 +59,20 @@ const resetCategory = (params, search) => {
params.categoryFk = null; params.categoryFk = null;
params.typeFk = null; params.typeFk = null;
arrayData.store.userFilter = null; arrayData.store.userFilter = null;
removeTagGroupParam(params, search); removeTagGroupParam(search);
}; };
const selectCategory = (params, category, search) => { const selectCategory = (params, category, search) => {
if (params.categoryFk === category?.id) { if (params.categoryFk === category?.id) {
resetCategory(params, search); resetCategory(params, search);
params.categoryFk = null; params.categoryFk = null;
} else { return;
}
selectedCategoryFk.value = category?.id; selectedCategoryFk.value = category?.id;
params.categoryFk = category?.id; params.categoryFk = category?.id;
params.typeFk = null; params.typeFk = null;
selectedTypeFk.value = null; selectedTypeFk.value = null;
loadTypes(category?.id); loadTypes(category?.id);
}
search(); search();
}; };
@ -155,6 +155,12 @@ const getCategoryClass = (category, params) => {
} }
}; };
const clearFilter = (key) => {
if (key === 'categoryFk') {
resetCategory();
}
};
function addOrder(value, field, params) { function addOrder(value, field, params) {
let { orderBy } = params; let { orderBy } = params;
orderBy = JSON.parse(orderBy); orderBy = JSON.parse(orderBy);
@ -179,6 +185,7 @@ onMounted(() => {
:expr-builder="exprBuilder" :expr-builder="exprBuilder"
:custom-tags="['tagGroups', 'categoryFk']" :custom-tags="['tagGroups', 'categoryFk']"
:redirect="false" :redirect="false"
@remove="clearFilter"
v-model="currentParams" v-model="currentParams"
> >
<template #tags="{ tag, formatFn }"> <template #tags="{ tag, formatFn }">
@ -328,7 +335,7 @@ onMounted(() => {
style="display: inline-block" style="display: inline-block"
:tags="tags" :tags="tags"
@apply-tags=" @apply-tags="
($event) => applyTags($event, params, searchFn) ($event) => applyTags($event, currentParams, searchFn)
" "
/> />
</QPopupProxy> </QPopupProxy>