refactor: 07, 13 => remove console logs, improve infinite scroll handling, and enhance TableReceipt component

This commit is contained in:
puriphatt 2025-02-03 17:05:04 +07:00
parent 465f126376
commit 74f0764ae8
3 changed files with 103 additions and 78 deletions

View file

@ -460,7 +460,6 @@ watch(
@load=" @load="
(_, done) => { (_, done) => {
if ($q.screen.gt.xs || page === pageMax) return; if ($q.screen.gt.xs || page === pageMax) return;
console.log('load');
page = page + 1; page = page + 1;
fetchData().then(() => done(page >= pageMax)); fetchData().then(() => done(page >= pageMax));
} }

View file

@ -15,10 +15,8 @@ import QuotationCard from 'src/components/05_quotation/QuotationCard.vue';
import { useNavigator } from 'src/stores/navigator'; import { useNavigator } from 'src/stores/navigator';
import { columns, hslaColors } from './constants'; import { columns, hslaColors } from './constants';
import useFlowStore from 'src/stores/flow'; import useFlowStore from 'src/stores/flow';
import { useRequestList } from 'src/stores/request-list';
import { usePayment, useReceipt } from 'src/stores/payment'; import { usePayment, useReceipt } from 'src/stores/payment';
import { Receipt, PaymentDataStatus } from 'src/stores/payment/types'; import { PaymentDataStatus } from 'src/stores/payment/types';
import { Quotation } from 'src/stores/quotations';
import { QSelect, useQuasar } from 'quasar'; import { QSelect, useQuasar } from 'quasar';
const $q = useQuasar(); const $q = useQuasar();
@ -53,7 +51,7 @@ async function fetchList(opts?: { rotateFlowId?: boolean }) {
query: pageState.inputSearch, query: pageState.inputSearch,
}); });
if (ret) { if (ret) {
data.value = ret.result; data.value = $q.screen.xs ? [...data.value, ...ret.result] : ret.result;
pageState.total = ret.total; pageState.total = ret.total;
pageMax.value = Math.ceil(ret.total / pageSize.value); pageMax.value = Math.ceil(ret.total / pageSize.value);
} }
@ -89,7 +87,6 @@ onMounted(async () => {
navigatorStore.current.title = 'receipt.title'; navigatorStore.current.title = 'receipt.title';
navigatorStore.current.path = [{ text: 'receipt.caption', i18n: true }]; navigatorStore.current.path = [{ text: 'receipt.caption', i18n: true }];
await fetchList({ rotateFlowId: true }); await fetchList({ rotateFlowId: true });
}); });
@ -98,9 +95,12 @@ watch(
() => pageState.inputSearch, () => pageState.inputSearch,
() => pageState.statusFilter, () => pageState.statusFilter,
() => pageSize.value, () => pageSize.value,
() => page.value,
], ],
() => fetchList({ rotateFlowId: true }), () => {
page.value = 1;
data.value = [];
fetchList({ rotateFlowId: true });
},
); );
</script> </script>
<template> <template>
@ -289,12 +289,23 @@ watch(
<NoData :not-found="!!pageState.inputSearch" /> <NoData :not-found="!!pageState.inputSearch" />
</article> </article>
<article v-else class="col surface-2 full-width scroll q-pa-md"> <article v-else class="col surface-2 full-width scroll q-pa-md">
<q-infinite-scroll
:offset="10"
@load="
(_, done) => {
if ($q.screen.gt.xs || page === pageMax) return;
page = page + 1;
fetchList().then(() => done(page >= pageMax));
}
"
>
<TableReceipt <TableReceipt
:columns="columns" :columns="columns"
:rows="data" :rows="data"
:grid="pageState.gridView" :grid="pageState.gridView"
@view=" @view="
(data) => triggerView({ quotationId: data.invoice.quotation.id }) (data) =>
triggerView({ quotationId: data.invoice.quotation.id })
" "
@preview="(data) => viewDocExample(data.id)" @preview="(data) => viewDocExample(data.id)"
> >
@ -358,12 +369,21 @@ watch(
</div> </div>
</template> </template>
</TableReceipt> </TableReceipt>
<template v-slot:loading>
<div
v-if="$q.screen.lt.sm && page !== pageMax"
class="row justify-center"
>
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
</article> </article>
<!-- SEC: footer content --> <!-- SEC: footer content -->
<footer <footer
class="row justify-between items-center q-px-md q-py-sm surface-2" class="row justify-between items-center q-px-md q-py-sm surface-2"
v-if="pageMax > 0" v-if="pageMax > 0 && $q.screen.gt.xs"
> >
<div class="col-4"> <div class="col-4">
<div class="row items-center no-wrap"> <div class="row items-center no-wrap">
@ -394,7 +414,11 @@ watch(
<PaginationComponent <PaginationComponent
v-model:current-page="page" v-model:current-page="page"
v-model:max-page="pageMax" v-model:max-page="pageMax"
:fetch-data="() => fetchList({ rotateFlowId: true })" :fetch-data="
() => {
fetchList({ rotateFlowId: true });
}
"
/> />
</nav> </nav>
</footer> </footer>

View file

@ -75,7 +75,7 @@ defineEmits<{
} & Omit<Parameters<QTableSlots['body']>[0], 'row'>" } & Omit<Parameters<QTableSlots['body']>[0], 'row'>"
> >
<q-tr :class="{ dark: $q.dark.isActive }" class="text-center"> <q-tr :class="{ dark: $q.dark.isActive }" class="text-center">
<q-td v-for="col in columns" :align="col.align"> <q-td v-for="col in columns" :align="col.align" :key="col.name">
<!-- NOTE: custom column will starts with # --> <!-- NOTE: custom column will starts with # -->
<template v-if="!col.name.startsWith('#')"> <template v-if="!col.name.startsWith('#')">
<span> <span>
@ -88,7 +88,9 @@ defineEmits<{
</template> </template>
<template v-if="col.name === '#order'"> <template v-if="col.name === '#order'">
{{ {{
col.field(props.row) + $q.screen.xs
? props.rowIndex + 1
: col.field(props.row) +
(receiptStore.page - 1) * receiptStore.pageSize (receiptStore.page - 1) * receiptStore.pageSize
}} }}
</template> </template>