fix: refs #7283 itemLastEntries filter
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-08-09 15:34:10 +02:00
parent bb1f507b27
commit f17ca4fe30
2 changed files with 30 additions and 43 deletions

View File

@ -1,4 +1,3 @@
<script setup></script>
<template> <template>
<div class="vn-row q-gutter-md q-mb-md"> <div class="vn-row q-gutter-md q-mb-md">
<slot /> <slot />

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { onMounted, computed, onUnmounted, reactive, ref } from 'vue'; import { onMounted, computed, onUnmounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { dateRange } from 'src/filters'; import { dateRange } from 'src/filters';
@ -11,6 +11,7 @@ import { toDateTimeFormat } from 'src/filters/date.js';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty } from 'src/filters';
import { toCurrency } from 'filters/index'; import { toCurrency } from 'filters/index';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
@ -35,26 +36,8 @@ const exprBuilder = (param, value) => {
} }
}; };
const datedRange = reactive({ const from = ref();
from: null, const to = ref();
to: null,
});
const from = computed({
get: () => datedRange.from,
set: (val) => {
updateFrom(val);
updateFilter();
},
});
const to = computed({
get: () => datedRange.to,
set: (val) => {
updateTo(val);
updateFilter();
},
});
const arrayData = useArrayData('ItemLastEntries', { const arrayData = useArrayData('ItemLastEntries', {
url: 'Items/lastEntriesFilter', url: 'Items/lastEntriesFilter',
@ -162,41 +145,48 @@ const fetchItemLastEntries = async () => {
itemLastEntries.value = data; itemLastEntries.value = data;
}; };
const updateFrom = async (date) => { const getDate = (date, type) => {
date.setHours(0, 0, 0, 0); if (type == 'from') {
datedRange.from = date.toISOString(); date.setHours(0, 0, 0, 0);
}; } else if (type == 'to') {
date.setHours(23, 59, 59, 999);
const updateTo = async (date) => { }
date.setHours(23, 59, 59, 59); return date.toISOString();
datedRange.to = date.toISOString();
}; };
const updateFilter = async () => { const updateFilter = async () => {
arrayData.store.userFilter.where.landed = { let filter;
between: [datedRange.from, datedRange.to], if (!from.value && to.value) filter = { lte: to.value };
}; else if (from.value && !to.value) filter = { gte: from.value };
else if (from.value && to.value) filter = { between: [from.value, to.value] };
arrayData.store.userFilter.where.landed = filter;
await fetchItemLastEntries(); await fetchItemLastEntries();
}; };
onMounted(async () => { onMounted(async () => {
const _from = Date.vnNew(); const _from = Date.vnNew();
_from.setDate(_from.getDate() - 75); _from.setDate(_from.getDate() - 75);
updateFrom(_from); from.value = getDate(_from, 'from');
const _to = Date.vnNew(); const _to = Date.vnNew();
_to.setDate(_to.getDate() + 10); _to.setDate(_to.getDate() + 10);
updateTo(_to); to.value = getDate(Date.vnNew(), 'to');
updateFilter(); updateFilter();
watch([from, to], ([nFrom, nTo], [oFrom, oTo]) => {
if (nFrom && nFrom != oFrom) nFrom = getDate(new Date(nFrom), 'from');
if (nTo && nTo != oTo) nTo = getDate(new Date(nTo), 'to');
updateFilter();
});
}); });
onUnmounted(() => (stateStore.rightDrawer = false)); onUnmounted(() => (stateStore.rightDrawer = false));
</script> </script>
<template> <template>
<QToolbar class="justify-end"> <VnSubToolbar>
<div id="st-data" class="row"> <template #st-data>
<VnInputDate <VnInputDate
:label="t('lastEntries.since')" :label="t('lastEntries.since')"
dense dense
@ -204,11 +194,9 @@ onUnmounted(() => (stateStore.rightDrawer = false));
class="q-mr-lg" class="q-mr-lg"
/> />
<VnInputDate :label="t('lastEntries.to')" dense v-model="to" /> <VnInputDate :label="t('lastEntries.to')" dense v-model="to" />
</div> </template>
<QSpace /> </VnSubToolbar>
<div id="st-actions"></div> <QPage class="column items-center q-pa-xd">
</QToolbar>
<QPage class="column items-center q-pa-md">
<QTable <QTable
:rows="itemLastEntries" :rows="itemLastEntries"
:columns="columns" :columns="columns"