From e4985064c19c9221c1d3b0ac0f91fa7fd195e54f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 21 Oct 2024 11:37:49 +0200 Subject: [PATCH] feat: refs #8110 #8110 apply pagination --- src/pages/Item/Card/ItemDiary.vue | 67 +++++++++++++------------------ 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/src/pages/Item/Card/ItemDiary.vue b/src/pages/Item/Card/ItemDiary.vue index dd20bc79a..b249660e8 100644 --- a/src/pages/Item/Card/ItemDiary.vue +++ b/src/pages/Item/Card/ItemDiary.vue @@ -36,17 +36,13 @@ const itemBalances = ref([]); const warehouseFk = ref(null); const _showWhatsBeforeInventory = ref(false); const inventoriedDate = ref(null); -const pageSize = 50; -const lastPage = ref(0); -const loading = ref(false); -const pagination = { - rowsPerPage: 0, -}; - -const nextPage = ref(1); - -const rows = ref([]); -const tableRef = ref(null); +const loading = ref(true); +const pagination = ref({ + rowsPerPage: 5, + sortBy: 'desc', + descending: false, + page: 1, +}); 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({ get: () => _showWhatsBeforeInventory.value, set: (val) => { @@ -133,11 +111,10 @@ const showWhatsBeforeInventory = computed({ else itemsBalanceFilter.where.date = inventoriedDate.value ?? new Date(); }, }); -function handleOnFetch(data) { +async function handleOnFetch(data) { itemBalances.value = data; if (data.length < 1) return; - lastPage.value = Math.ceil(data.length / pageSize); - sliceRows(); + await scrollToToday(); } const fetchItemBalances = async () => await itemBalancesRef.value.fetch(); @@ -158,7 +135,9 @@ const scrollToToday = async () => { const todayIndex = itemBalances.value.findIndex((item) => 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 = { @@ -196,7 +175,6 @@ onMounted(async () => { const { data } = await axios.get('Configs/findOne'); inventoriedDate.value = data.inventoried; await fetchItemBalances(); - await scrollToToday(); }); onUnmounted(() => (stateStore.rightDrawer = false)); @@ -208,6 +186,9 @@ watch( itemBalancesRef.value.fetch(); } ); +const pagesNumber = computed(() => + Math.ceil(itemBalances.value.length / pagination.value.rowsPerPage) +);