ข้อมูลทะเบียนประวัติ => เพิ่ม Pagination

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-02-22 17:19:52 +07:00
parent 69b6ad3a6c
commit 4874d3da8e

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, watch } from "vue"; import { ref, onMounted, watch, reactive } from "vue";
import type { QInput, QTableProps } from "quasar"; import type { QInput, QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
@ -112,12 +112,24 @@ onMounted(async () => {
fetchType(); fetchType();
}); });
/** queryString*/
const formQuery = reactive({
page: 1, //*
pageSize: 10, //*
keyword: "", //keyword
});
const maxPage = ref<number>(1);
async function fetchData() { async function fetchData() {
showLoader(); showLoader();
await http await http
.get(config.API.registryNew) .get(
config.API.registryNew +
`?page=${formQuery.page}&pageSise=${formQuery.pageSize}&keyword=${formQuery.keyword}`
)
.then(async (res) => { .then(async (res) => {
store.save(res.data.result); maxPage.value = Math.ceil(res.data.result.total / formQuery.pageSize);
store.save(res.data.result.data);
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -284,6 +296,23 @@ watch(posTypeId, () => {
}, 200); }, 200);
}); });
watch([() => formQuery.page, () => formQuery.pageSize], async () => {
await fetchData();
});
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: any) {
formQuery.page = 1;
formQuery.pageSize = newPagination.rowsPerPage;
}
async function filterFn(page: number) {
page !== 1 ? (formQuery.page = 1) : await fetchData();
}
/** /**
* function ตรวจสอบเลขประจำตวประชาชน * function ตรวจสอบเลขประจำตวประชาชน
* @param citizenId เลขประจำตวประชาชน * @param citizenId เลขประจำตวประชาชน
@ -333,7 +362,13 @@ async function changeCardID(citizenId: string | number | null) {
</q-btn> </q-btn>
<q-space /> <q-space />
<div class="row q-gutter-sm"> <div class="row q-gutter-sm">
<q-input outlined dense v-model="filterKeyword" label="ค้นหา"></q-input> <q-input
outlined
dense
v-model="formQuery.keyword"
label="ค้นหา"
@keydown.enter.prevent="filterFn(formQuery.page)"
></q-input>
<q-select <q-select
v-model="visibleColumns" v-model="visibleColumns"
multiple multiple
@ -355,7 +390,6 @@ async function changeCardID(citizenId: string | number | null) {
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="store.row" :rows="store.row"
:filter="filterKeyword"
row-key="name" row-key="name"
flat flat
bordered bordered
@ -363,6 +397,8 @@ async function changeCardID(citizenId: string | number | null) {
dense dense
class="custom-header-table" class="custom-header-table"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -376,7 +412,9 @@ async function changeCardID(citizenId: string | number | null) {
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id"> <q-td v-for="col in props.cols" :key="col.id">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }} {{
(formQuery.page - 1) * formQuery.pageSize + props.rowIndex + 1
}}
</div> </div>
<div v-else-if="col.name == 'fullName'"> <div v-else-if="col.name == 'fullName'">
{{ props.row.prefix }}{{ props.row.firstName }} {{ props.row.prefix }}{{ props.row.firstName }}
@ -432,6 +470,17 @@ async function changeCardID(citizenId: string | number | null) {
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope">
<q-pagination
v-model="formQuery.page"
active-color="primary"
color="dark"
:max="maxPage"
size="sm"
boundary-links
direction-links
></q-pagination>
</template>
</d-table> </d-table>
</div> </div>