Compare commits
15 Commits
f36363dbd2
...
bf0bda0e27
Author | SHA1 | Date |
---|---|---|
Alex Moreno | bf0bda0e27 | |
Jon Elias | 0cefe391cb | |
Jon Elias | 747bc4af76 | |
Jon Elias | 5ff95c2b93 | |
Alex Moreno | 0c3581f3dc | |
Javier Segarra | 0434332ec4 | |
Alex Moreno | 44f2ecca28 | |
Alex Moreno | c5acde22a3 | |
Alex Moreno | 42d24359cd | |
Alex Moreno | abd79283ff | |
Alex Moreno | 32fdc836f9 | |
Alex Moreno | e032d5988b | |
Alex Moreno | c2db7be8cd | |
Jon Elias | a64575c7cc | |
Jon Elias | 452ba788c9 |
|
@ -1,6 +1,5 @@
|
|||
<script setup>
|
||||
import { useRoute } from 'vue-router';
|
||||
import { defineProps } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
routeName: {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import axios from 'axios';
|
||||
import VnSelect from 'components/common/VnSelect.vue';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
|
||||
const props = defineProps({
|
||||
|
@ -31,47 +31,26 @@ const applyTags = () => {
|
|||
emit('applyTags', tagInfo);
|
||||
};
|
||||
|
||||
const removeTagGroupParam = (valIndex = null) => {
|
||||
if (!valIndex) {
|
||||
tagValues.value = [{}];
|
||||
} else {
|
||||
(tagValues.value || []).splice(valIndex, 1);
|
||||
}
|
||||
};
|
||||
|
||||
const getSelectedTagValues = async (tag) => {
|
||||
try {
|
||||
if (!tag?.id) return;
|
||||
const filter = {
|
||||
fields: ['value'],
|
||||
order: 'value ASC',
|
||||
limit: 30,
|
||||
};
|
||||
if (!tag?.id) return;
|
||||
const filter = {
|
||||
fields: ['value'],
|
||||
order: 'value ASC',
|
||||
limit: 30,
|
||||
};
|
||||
|
||||
const url = `Tags/${tag?.id}/filterValue`;
|
||||
const params = { filter: JSON.stringify(filter) };
|
||||
const { data } = await axios.get(url, {
|
||||
params,
|
||||
});
|
||||
tagOptions.value = data;
|
||||
} catch (err) {
|
||||
console.error('Error getting selected tag values');
|
||||
}
|
||||
const url = `Tags/${tag?.id}/filterValue`;
|
||||
const params = { filter: JSON.stringify(filter) };
|
||||
const { data } = await axios.get(url, {
|
||||
params,
|
||||
});
|
||||
tagOptions.value = data;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<QForm @submit="applyTags(tagValues)" class="all-pointer-events">
|
||||
<QForm @submit="applyTags()" class="all-pointer-events">
|
||||
<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
|
||||
:label="t('params.tag')"
|
||||
v-model="selectedTag"
|
||||
|
@ -84,17 +63,7 @@ const getSelectedTagValues = async (tag) => {
|
|||
rounded
|
||||
:emit-value="false"
|
||||
use-input
|
||||
@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({})"
|
||||
@update:model-value="getSelectedTagValues"
|
||||
/>
|
||||
<div
|
||||
v-for="(value, index) in tagValues"
|
||||
|
@ -106,7 +75,7 @@ const getSelectedTagValues = async (tag) => {
|
|||
v-if="!selectedTag?.isFree && tagOptions"
|
||||
:label="t('components.itemsFilterPanel.value')"
|
||||
v-model="value.value"
|
||||
:options="tagOptions || []"
|
||||
:options="tagOptions"
|
||||
option-value="value"
|
||||
option-label="value"
|
||||
dense
|
||||
|
@ -124,7 +93,6 @@ const getSelectedTagValues = async (tag) => {
|
|||
:label="t('components.itemsFilterPanel.value')"
|
||||
:disable="!value"
|
||||
is-outlined
|
||||
:is-clearable="false"
|
||||
class="col"
|
||||
/>
|
||||
<QBtn
|
||||
|
@ -135,11 +103,25 @@ const getSelectedTagValues = async (tag) => {
|
|||
rounded
|
||||
flat
|
||||
class="filter-icon col-2"
|
||||
:disabled="!value.value"
|
||||
@click="removeTagGroupParam(index)"
|
||||
@click="tagValues.splice(index, 1)"
|
||||
/>
|
||||
</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>
|
||||
</QForm>
|
||||
</template>
|
||||
|
|
|
@ -4,18 +4,19 @@ import { useRoute, useRouter } from 'vue-router';
|
|||
import { onBeforeMount, onMounted, onUnmounted, ref, computed, watch } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnPaginate from 'components/ui/VnPaginate.vue';
|
||||
import CatalogItem from 'components/ui/CatalogItem.vue';
|
||||
import OrderCatalogFilter from 'pages/Order/Card/OrderCatalogFilter.vue';
|
||||
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||
import CatalogItem from 'src/components/ui/CatalogItem.vue';
|
||||
import OrderCatalogFilter from 'src/pages/Order/Card/OrderCatalogFilter.vue';
|
||||
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
|
||||
import getParamWhere from 'src/filters/getParamWhere';
|
||||
import { useArrayData } from 'composables/useArrayData';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const stateStore = useStateStore();
|
||||
const { t } = useI18n();
|
||||
const arrayData = useArrayData('OrderCatalogList');
|
||||
const dataKey = 'OrderCatalogList';
|
||||
const arrayData = useArrayData(dataKey);
|
||||
const store = arrayData.store;
|
||||
const showFilter = ref(null);
|
||||
const tags = ref([]);
|
||||
|
@ -102,7 +103,7 @@ watch(
|
|||
|
||||
<template>
|
||||
<VnSearchbar
|
||||
data-key="OrderCatalogList"
|
||||
:data-key="dataKey"
|
||||
:user-params="catalogParams"
|
||||
:static-params="['orderFk', 'orderBy']"
|
||||
:redirect="false"
|
||||
|
@ -113,7 +114,7 @@ watch(
|
|||
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
|
||||
<QScrollArea v-if="showFilter" class="fit text-grey-8">
|
||||
<OrderCatalogFilter
|
||||
data-key="OrderCatalogList"
|
||||
:data-key="dataKey"
|
||||
:tag-value="tagValue"
|
||||
:tags="tags"
|
||||
:initial-catalog-params="catalogParams"
|
||||
|
@ -123,7 +124,7 @@ watch(
|
|||
<QPage class="column items-center q-pa-md">
|
||||
<div class="full-width">
|
||||
<VnPaginate
|
||||
data-key="OrderCatalogList"
|
||||
:data-key="dataKey"
|
||||
url="Orders/CatalogFilter"
|
||||
:limit="50"
|
||||
:user-params="catalogParams"
|
||||
|
|
|
@ -32,11 +32,12 @@ const route = useRoute();
|
|||
|
||||
const arrayData = useArrayData(props.dataKey);
|
||||
|
||||
const currentParams = ref({});
|
||||
const categoryList = ref(null);
|
||||
const selectedCategoryFk = ref(null);
|
||||
const typeList = ref([]);
|
||||
const selectedTypeFk = ref(null);
|
||||
const generalSearchParam = ref(null);
|
||||
const searchByTag = ref(null);
|
||||
|
||||
const vnFilterPanelRef = ref();
|
||||
const orderByList = ref([
|
||||
|
@ -52,26 +53,30 @@ const orderWayList = ref([
|
|||
const orderBySelected = ref('relevancy DESC, name');
|
||||
const orderWaySelected = ref('ASC');
|
||||
|
||||
onMounted(() => {
|
||||
selectedCategoryFk.value = getParamWhere(route, 'categoryFk');
|
||||
selectedTypeFk.value = getParamWhere(route, 'typeFk');
|
||||
});
|
||||
|
||||
const resetCategory = (params, search) => {
|
||||
selectedCategoryFk.value = null;
|
||||
typeList.value = null;
|
||||
params.categoryFk = null;
|
||||
params.typeFk = null;
|
||||
arrayData.store.userFilter = null;
|
||||
removeTagGroupParam(params, search);
|
||||
removeTagGroupParam(search);
|
||||
};
|
||||
|
||||
const selectCategory = (params, category, search) => {
|
||||
if (params.categoryFk === category?.id) {
|
||||
resetCategory(params, search);
|
||||
params.categoryFk = null;
|
||||
} else {
|
||||
selectedCategoryFk.value = category?.id;
|
||||
params.categoryFk = category?.id;
|
||||
params.typeFk = null;
|
||||
selectedTypeFk.value = null;
|
||||
loadTypes(category?.id);
|
||||
return;
|
||||
}
|
||||
selectedCategoryFk.value = category?.id;
|
||||
params.categoryFk = category?.id;
|
||||
params.typeFk = null;
|
||||
selectedTypeFk.value = null;
|
||||
loadTypes(category?.id);
|
||||
search();
|
||||
};
|
||||
|
||||
|
@ -115,13 +120,23 @@ const applyTags = (tagInfo, params, search) => {
|
|||
search();
|
||||
};
|
||||
|
||||
const removeTagGroupParam = (params, search, valIndex = null) => {
|
||||
if (!valIndex) {
|
||||
params.tagGroups = null;
|
||||
search();
|
||||
async function onSearchByTag(value) {
|
||||
if (!value.target.value) return;
|
||||
if (!currentParams.value?.tagGroups) {
|
||||
currentParams.value.tagGroups = [];
|
||||
}
|
||||
|
||||
currentParams.value.tagGroups.push({
|
||||
values: [{ value: value.target.value }],
|
||||
});
|
||||
searchByTag.value = null;
|
||||
}
|
||||
|
||||
const removeTagGroupParam = (search, valIndex) => {
|
||||
if (!valIndex && valIndex !== 0) {
|
||||
currentParams.value.tagGroups = null;
|
||||
} else {
|
||||
params.tagGroups.splice(valIndex, 1);
|
||||
search();
|
||||
currentParams.value.tagGroups.splice(valIndex, 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -142,6 +157,12 @@ const getCategoryClass = (category, params) => {
|
|||
}
|
||||
};
|
||||
|
||||
const clearFilter = (key) => {
|
||||
if (key === 'categoryFk') {
|
||||
resetCategory();
|
||||
}
|
||||
};
|
||||
|
||||
function addOrder(value, field, params) {
|
||||
let { orderBy } = params;
|
||||
orderBy = JSON.parse(orderBy);
|
||||
|
@ -157,7 +178,7 @@ onMounted(() => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData url="ItemCategories" limit="30" auto-load @on-fetch="setCategoryList" />
|
||||
<FetchData url="ItemCategories" auto-load @on-fetch="setCategoryList" />
|
||||
<VnFilterPanel
|
||||
ref="vnFilterPanelRef"
|
||||
:data-key="props.dataKey"
|
||||
|
@ -166,7 +187,8 @@ onMounted(() => {
|
|||
:expr-builder="exprBuilder"
|
||||
:custom-tags="['tagGroups', 'categoryFk']"
|
||||
:redirect="false"
|
||||
search-url="params"
|
||||
@remove="clearFilter"
|
||||
v-model="currentParams"
|
||||
>
|
||||
<template #tags="{ tag, formatFn }">
|
||||
<strong v-if="tag.label === 'typeFk'">
|
||||
|
@ -188,7 +210,7 @@ onMounted(() => {
|
|||
@remove="
|
||||
customTag.label === 'categoryFk'
|
||||
? resetCategory(params, searchFn)
|
||||
: removeTagGroupParam(params, searchFn, valIndex)
|
||||
: removeTagGroupParam(searchFn, valIndex)
|
||||
"
|
||||
>
|
||||
<strong v-if="customTag.label === 'categoryFk'">
|
||||
|
@ -288,46 +310,39 @@ onMounted(() => {
|
|||
</QItemSection>
|
||||
</QItem>
|
||||
<QSeparator />
|
||||
|
||||
<QItem class="q-mt-lg">
|
||||
<VnSelect
|
||||
<QItem class="q-mt-lg q-pa-none">
|
||||
<VnInput
|
||||
:label="t('components.itemsFilterPanel.value')"
|
||||
:options="props.tagValue"
|
||||
dense
|
||||
outlined
|
||||
rounded
|
||||
:is-clearable="false"
|
||||
v-model="generalSearchParam"
|
||||
@update:model-value="
|
||||
applyTags(
|
||||
{ values: [{ value: generalSearchParam }] },
|
||||
params,
|
||||
searchFn
|
||||
)
|
||||
"
|
||||
v-model="searchByTag"
|
||||
@keyup.enter="(val) => onSearchByTag(val, params)"
|
||||
>
|
||||
<template #prepend>
|
||||
<QIcon name="search" />
|
||||
</template>
|
||||
<template #after>
|
||||
<template #append>
|
||||
<QBtn
|
||||
icon="add_circle"
|
||||
shortcut="+"
|
||||
flat
|
||||
color="primary"
|
||||
size="md"
|
||||
dense
|
||||
/>
|
||||
<QPopupProxy>
|
||||
<CatalogFilterValueDialog
|
||||
style="display: inline-block"
|
||||
:tags="tags"
|
||||
@apply-tags="
|
||||
($event) => applyTags($event, params, searchFn)
|
||||
($event) => applyTags($event, currentParams, searchFn)
|
||||
"
|
||||
/>
|
||||
</QPopupProxy>
|
||||
</template>
|
||||
</VnSelect>
|
||||
</VnInput>
|
||||
</QItem>
|
||||
<QSeparator />
|
||||
</template>
|
||||
|
|
|
@ -24,7 +24,6 @@ function notIsLocations(ifIsFalse, ifIsTrue) {
|
|||
:descriptor="ZoneDescriptor"
|
||||
:filter-panel="notIsLocations(ZoneFilterPanel, undefined)"
|
||||
:search-data-key="notIsLocations('ZoneList', undefined)"
|
||||
:custom-url="`Zones/${route.params?.id}/getLeaves`"
|
||||
:searchbar-props="{
|
||||
url: notIsLocations('Zones', 'ZoneLocations'),
|
||||
label: notIsLocations(t('list.searchZone'), t('list.searchLocation')),
|
||||
|
|
|
@ -39,8 +39,7 @@ const url = computed(() => `Zones/${route.params.id}/getLeaves`);
|
|||
const arrayData = useArrayData(datakey, {
|
||||
url: url.value,
|
||||
});
|
||||
const { store } = arrayData;
|
||||
const storeData = computed(() => store.data);
|
||||
const store = arrayData.store;
|
||||
|
||||
const defaultNode = {
|
||||
id: null,
|
||||
|
@ -66,8 +65,20 @@ const onNodeExpanded = async (nodeKeysArray) => {
|
|||
if (!nodeKeysSet.has(null)) return;
|
||||
|
||||
const wasExpanded = !previousExpandedNodes.value.has(lastNodeKey);
|
||||
if (wasExpanded) await fetchNodeLeaves(lastNodeKey);
|
||||
else {
|
||||
if (wasExpanded && treeRef.value) {
|
||||
const node = treeRef.value?.getNodeByKey(lastNodeKey);
|
||||
const params = { parentId: node.id };
|
||||
const response = await axios.get(`Zones/${route.params.id}/getLeaves`, {
|
||||
params,
|
||||
});
|
||||
if (response.data) {
|
||||
node.childs = response.data.map((n) => {
|
||||
if (n.sons > 0) n.childs = [{}];
|
||||
return n;
|
||||
});
|
||||
}
|
||||
await fetchNodeLeaves(lastNodeKey, true);
|
||||
} else {
|
||||
const difference = new Set(
|
||||
[...previousExpandedNodes.value].filter((x) => !nodeKeysSet.has(x))
|
||||
);
|
||||
|
@ -83,41 +94,21 @@ const formatNodeSelected = (node) => {
|
|||
if (node.selected === 1) node.selected = true;
|
||||
else if (node.selected === 0) node.selected = false;
|
||||
|
||||
if (node.childs && node.childs.length > 0) {
|
||||
expanded.value.push(node.id);
|
||||
|
||||
node.childs.forEach((childNode) => {
|
||||
formatNodeSelected(childNode);
|
||||
});
|
||||
}
|
||||
|
||||
if (node.sons > 0 && !node.childs) node.childs = [{}];
|
||||
};
|
||||
|
||||
const fetchNodeLeaves = async (nodeKey) => {
|
||||
try {
|
||||
const node = treeRef.value?.getNodeByKey(nodeKey);
|
||||
if (!node || node.sons === 0) return;
|
||||
if (!treeRef.value) return;
|
||||
const node = treeRef.value?.getNodeByKey(nodeKey);
|
||||
if (node.selected === 1) node.selected = true;
|
||||
else if (node.selected === 0) node.selected = false;
|
||||
if (!node || node.sons === 0) return;
|
||||
|
||||
const params = { parentId: node.id };
|
||||
const response = await axios.get(`Zones/${route.params.id}/getLeaves`, {
|
||||
params,
|
||||
});
|
||||
if (response.data) {
|
||||
node.childs = response.data.map((n) => {
|
||||
formatNodeSelected(n);
|
||||
return n;
|
||||
});
|
||||
}
|
||||
|
||||
state.set('Tree', node);
|
||||
} catch (err) {
|
||||
console.error('Error fetching department leaves', err);
|
||||
throw new Error();
|
||||
}
|
||||
state.set('Tree', node);
|
||||
};
|
||||
|
||||
function getNodeIds(node) {
|
||||
if (!node) return [];
|
||||
let ids = [];
|
||||
if (node.id) ids.push(node.id);
|
||||
|
||||
|
@ -128,60 +119,46 @@ function getNodeIds(node) {
|
|||
return ids;
|
||||
}
|
||||
|
||||
watch(storeData, async (val) => {
|
||||
// Se triggerea cuando se actualiza el store.data, el cual es el resultado del fetch de la searchbar
|
||||
if (!nodes.value[0]) nodes.value = [defaultNode];
|
||||
nodes.value[0].childs = [...val];
|
||||
const fetchedNodeKeys = val.flatMap(getNodeIds);
|
||||
state.set('Tree', [...fetchedNodeKeys]);
|
||||
watch(
|
||||
() => store.data,
|
||||
async (val) => {
|
||||
if (!val) return;
|
||||
// // Se triggerea cuando se actualiza el store.data, el cual es el resultado del fetch de la searchbar
|
||||
if (!nodes.value[0]) nodes.value = [defaultNode];
|
||||
nodes.value[0].childs = [...val];
|
||||
const fetchedNodeKeys = val.flatMap(getNodeIds);
|
||||
state.set('Tree', [...fetchedNodeKeys]);
|
||||
|
||||
if (store.userParams?.search === '') {
|
||||
val.forEach((n) => {
|
||||
formatNodeSelected(n);
|
||||
});
|
||||
} else {
|
||||
for (let n of state.get('Tree')) await fetchNodeLeaves(n);
|
||||
expanded.value = [null, ...fetchedNodeKeys];
|
||||
}
|
||||
previousExpandedNodes.value = new Set(expanded.value);
|
||||
});
|
||||
if (!store.userParams?.search) {
|
||||
val.forEach((n) => {
|
||||
formatNodeSelected(n);
|
||||
});
|
||||
store.data = null;
|
||||
expanded.value = [null];
|
||||
} else {
|
||||
for (let n of state.get('Tree')) {
|
||||
await fetchNodeLeaves(n);
|
||||
}
|
||||
expanded.value = [null, ...fetchedNodeKeys];
|
||||
}
|
||||
previousExpandedNodes.value = new Set(expanded.value);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const reFetch = async () => {
|
||||
const { data } = await arrayData.fetch({ append: false });
|
||||
nodes.value = data;
|
||||
expanded.value = [null];
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
if (store.userParams?.search && !props.showSearchBar) {
|
||||
await reFetch();
|
||||
return;
|
||||
}
|
||||
const stateTree = state.get('Tree');
|
||||
const tree = stateTree ? [...state.get('Tree')] : [null];
|
||||
const lastStateTree = state.get('TreeState');
|
||||
if (tree) {
|
||||
for (let n of tree) {
|
||||
await fetchNodeLeaves(n);
|
||||
}
|
||||
|
||||
if (lastStateTree) {
|
||||
tree.push(lastStateTree);
|
||||
await fetchNodeLeaves(lastStateTree);
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (lastStateTree) {
|
||||
document.getElementById(lastStateTree).scrollIntoView();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
expanded.value.unshift(null);
|
||||
previousExpandedNodes.value = new Set(expanded.value);
|
||||
if (store.userParams?.search) await arrayData.fetch({});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
state.set('Tree', undefined);
|
||||
arrayData.destroy();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue