refactor: 05 => xs scroll & adjust TableQuotation row index calculation

This commit is contained in:
puriphatt 2025-02-03 11:22:33 +07:00
parent 8a937dfa31
commit 1fc6b39e37
2 changed files with 137 additions and 102 deletions

View file

@ -16,12 +16,16 @@ const props = withDefaults(
grid?: boolean; grid?: boolean;
visibleColumns?: string[]; visibleColumns?: string[];
hideEdit?: boolean; hideEdit?: boolean;
page?: number;
pageSize?: number;
}>(), }>(),
{ {
row: () => [], row: () => [],
column: () => [], column: () => [],
grid: false, grid: false,
visibleColumns: () => [], visibleColumns: () => [],
page: 1,
pageSize: 30,
}, },
); );
@ -64,7 +68,11 @@ defineEmits<{
<template v-slot:body="props"> <template v-slot:body="props">
<q-tr :class="{ urgent: props.row.urgent }"> <q-tr :class="{ urgent: props.row.urgent }">
<q-td v-if="visibleColumns.includes('order')"> <q-td v-if="visibleColumns.includes('order')">
{{ props.rowIndex + 1 }} {{
$q.screen.xs
? props.rowIndex + 1
: (page - 1) * pageSize + props.rowIndex + 1
}}
</q-td> </q-td>
<q-td v-if="visibleColumns.includes('workName')"> <q-td v-if="visibleColumns.includes('workName')">

View file

@ -278,10 +278,10 @@ onMounted(async () => {
flowStore.rotate(); flowStore.rotate();
}); });
async function fetchQuotationList() { async function fetchQuotationList(mobileFetch?: boolean) {
{ {
const ret = await quotationStore.getQuotationList({ const ret = await quotationStore.getQuotationList({
page: quotationPage.value, page: mobileFetch ? 1 : quotationPage.value,
pageSize: quotationPageSize.value, pageSize: quotationPageSize.value,
status: status:
pageState.currentTab !== 'Issued' pageState.currentTab !== 'Issued'
@ -301,7 +301,10 @@ async function fetchQuotationList() {
}); });
if (ret) { if (ret) {
quotationData.value = ret.result; quotationData.value =
$q.screen.xs && !mobileFetch
? [...quotationData.value, ...ret.result]
: ret.result;
quotationPageMax.value = Math.ceil(ret.total / quotationPageSize.value); quotationPageMax.value = Math.ceil(ret.total / quotationPageSize.value);
pageState.total = ret.total; pageState.total = ret.total;
} }
@ -319,7 +322,11 @@ async function fetchQuotationList() {
watch( watch(
[() => pageState.currentTab, () => pageState.inputSearch, quotationPageSize], [() => pageState.currentTab, () => pageState.inputSearch, quotationPageSize],
fetchQuotationList, () => {
quotationPage.value = 1;
quotationData.value = [];
fetchQuotationList();
},
); );
async function storeDataLocal(id: string) { async function storeDataLocal(id: string) {
@ -383,19 +390,11 @@ async function storeDataLocal(id: string) {
" "
> >
{{ {{
pageState.currentTab === 'Issued' quotationStats[
? quotationStats.issued pageState.currentTab === 'Invoice'
: pageState.currentTab === 'Accepted' ? 'paymentInProcess'
? quotationStats.accepted : (pageState.currentTab.toLowerCase() as keyof typeof quotationStats)
: pageState.currentTab === 'Expired' ]
? quotationStats.expired
: pageState.currentTab === 'Invoice'
? quotationStats.paymentInProcess
: pageState.currentTab === 'PaymentSuccess'
? quotationStats.paymentSuccess
: pageState.currentTab === 'ProcessComplete'
? quotationStats.processComplete
: 0
}} }}
</q-badge> </q-badge>
<q-btn <q-btn
@ -625,7 +624,23 @@ async function storeDataLocal(id: string) {
</article> </article>
<article v-else class="col surface-2 full-width scroll"> <article v-else class="col surface-2 full-width scroll">
<div class="q-pa-md"> <div class="q-pa-md">
<q-infinite-scroll
:key="pageState.currentTab"
:offset="100"
@load="
(_, done) => {
if ($q.screen.gt.xs) return;
quotationPage = quotationPage + 1;
fetchQuotationList().then(() => {
done(quotationPage >= quotationPageMax);
});
}
"
>
<TableQuotation <TableQuotation
:page="quotationPage"
:page-size="quotationPageSize"
:columns="columnQuotation" :columns="columnQuotation"
:rows="quotationData" :rows="quotationData"
:visible-columns="pageState.fieldSelected" :visible-columns="pageState.fieldSelected"
@ -674,7 +689,9 @@ async function storeDataLocal(id: string) {
}); });
})() })()
" "
:status="$t(`quotation.status.${item.row.quotationStatus}`)" :status="
$t(`quotation.status.${item.row.quotationStatus}`)
"
:worker-count="item.row._count.worker" :worker-count="item.row._count.worker"
:worker-max="item.row.workerMax || item.row._count.worker" :worker-max="item.row.workerMax || item.row._count.worker"
:customer-name=" :customer-name="
@ -699,7 +716,8 @@ async function storeDataLocal(id: string) {
statusDialog: 'info', statusDialog: 'info',
quotationId: item.row.id, quotationId: item.row.id,
branchId: branchId:
item.row.customerBranch.customer.registeredBranchId, item.row.customerBranch.customer
.registeredBranchId,
}); });
} }
" "
@ -718,13 +736,22 @@ async function storeDataLocal(id: string) {
</div> </div>
</template> </template>
</TableQuotation> </TableQuotation>
<template v-slot:loading>
<div
v-if="$q.screen.lt.sm && quotationPage !== quotationPageMax"
class="row justify-center"
>
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
</div> </div>
</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="quotationPageMax > 0" v-if="quotationPageMax > 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">
@ -755,7 +782,7 @@ async function storeDataLocal(id: string) {
<PaginationComponent <PaginationComponent
v-model:current-page="quotationPage" v-model:current-page="quotationPage"
v-model:max-page="quotationPageMax" v-model:max-page="quotationPageMax"
:fetch-data="fetchQuotationList" :fetch-data="() => fetchQuotationList()"
/> />
</nav> </nav>
</footer> </footer>