feat: refs #8110 #8110 apply pagination
gitea/salix-front/pipeline/pr-dev This commit looks good Details
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Javier Segarra 2024-10-21 11:37:49 +02:00
parent 066b0ffca0
commit e4985064c1
1 changed files with 27 additions and 40 deletions

View File

@ -36,17 +36,13 @@ const itemBalances = ref([]);
const warehouseFk = ref(null); const warehouseFk = ref(null);
const _showWhatsBeforeInventory = ref(false); const _showWhatsBeforeInventory = ref(false);
const inventoriedDate = ref(null); const inventoriedDate = ref(null);
const pageSize = 50; const loading = ref(true);
const lastPage = ref(0); const pagination = ref({
const loading = ref(false); rowsPerPage: 5,
const pagination = { sortBy: 'desc',
rowsPerPage: 0, descending: false,
}; page: 1,
});
const nextPage = ref(1);
const rows = ref([]);
const tableRef = ref(null);
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -107,24 +103,6 @@ const columns = computed(() => [
}, },
]); ]);
function onScroll(data) {
const { to, ref } = data;
if (!tableRef.value) tableRef.value = ref;
const lastIndex = rows.value.length - 1;
if (loading.value !== true && nextPage.value < lastPage.value && to === lastIndex) {
loading.value = true;
nextPage.value++;
sliceRows();
nextTick(() => {
ref.refresh();
loading.value = false;
});
}
}
function sliceRows() {
rows.value = itemBalances.value.slice(0, pageSize * nextPage.value);
}
const showWhatsBeforeInventory = computed({ const showWhatsBeforeInventory = computed({
get: () => _showWhatsBeforeInventory.value, get: () => _showWhatsBeforeInventory.value,
set: (val) => { set: (val) => {
@ -133,11 +111,10 @@ const showWhatsBeforeInventory = computed({
else itemsBalanceFilter.where.date = inventoriedDate.value ?? new Date(); else itemsBalanceFilter.where.date = inventoriedDate.value ?? new Date();
}, },
}); });
function handleOnFetch(data) { async function handleOnFetch(data) {
itemBalances.value = data; itemBalances.value = data;
if (data.length < 1) return; if (data.length < 1) return;
lastPage.value = Math.ceil(data.length / pageSize); await scrollToToday();
sliceRows();
} }
const fetchItemBalances = async () => await itemBalancesRef.value.fetch(); const fetchItemBalances = async () => await itemBalancesRef.value.fetch();
@ -158,7 +135,9 @@ const scrollToToday = async () => {
const todayIndex = itemBalances.value.findIndex((item) => const todayIndex = itemBalances.value.findIndex((item) =>
date.isSameDate(today.toISOString(), item.shipped) date.isSameDate(today.toISOString(), item.shipped)
); );
if (todayIndex > -1) tableRef.value.scrollTo(todayIndex); if (todayIndex > -1)
pagination.value.page = Math.ceil(todayIndex / pagination.value.rowsPerPage);
loading.value = false;
}; };
const originTypeMap = { const originTypeMap = {
@ -196,7 +175,6 @@ onMounted(async () => {
const { data } = await axios.get('Configs/findOne'); const { data } = await axios.get('Configs/findOne');
inventoriedDate.value = data.inventoried; inventoriedDate.value = data.inventoried;
await fetchItemBalances(); await fetchItemBalances();
await scrollToToday();
}); });
onUnmounted(() => (stateStore.rightDrawer = false)); onUnmounted(() => (stateStore.rightDrawer = false));
@ -208,6 +186,9 @@ watch(
itemBalancesRef.value.fetch(); itemBalancesRef.value.fetch();
} }
); );
const pagesNumber = computed(() =>
Math.ceil(itemBalances.value.length / pagination.value.rowsPerPage)
);
</script> </script>
<template> <template>
@ -254,15 +235,21 @@ watch(
<div id="st-actions"></div> <div id="st-actions"></div>
</QToolbar> </QToolbar>
<QPage class="column items-center q-pa-md"> <QPage class="column items-center q-pa-md">
<div class="row justify-center">
<QPagination
v-model="pagination.page"
:max="pagesNumber"
size="sm"
input
ref="paginationRef"
/>
</div>
<QTable <QTable
:rows="rows" :loading="loading"
:rows="itemBalances"
:columns="columns" :columns="columns"
class="full-width q-mt-md" class="full-width q-mt-md"
:no-data-label="t('globals.noResults')" v-model:pagination="pagination"
:loading="loading"
virtual-scroll
:pagination="pagination"
@virtual-scroll="onScroll"
> >
<template #body-cell-claim="{ row }"> <template #body-cell-claim="{ row }">
<QTd @click.stop> <QTd @click.stop>