แก้ paging วินัย

This commit is contained in:
setthawutttty 2024-10-29 17:04:33 +07:00
parent 92333b3545
commit ab6c7abcbb
17 changed files with 407 additions and 401 deletions

View file

@ -122,6 +122,7 @@ const searchRef = ref<any>(null);
async function searchInput() { async function searchInput() {
searchRef.value.validate(); searchRef.value.validate();
if (!searchRef.value.hasError) { if (!searchRef.value.hasError) {
pagination.value.page = 1;
await getSearch(); await getSearch();
} }
} }

View file

@ -881,7 +881,7 @@ onMounted(async () => {
:card-container-class=" :card-container-class="
modeViewPlan === 'card' ? 'q-col-gutter-md' : '' modeViewPlan === 'card' ? 'q-col-gutter-md' : ''
" "
:rows-per-page-options="[1, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePaginationIdp" @update:pagination="updatePaginationIdp"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">

View file

@ -625,7 +625,7 @@ onMounted(async () => {
: 'multiple' : 'multiple'
" "
v-model:selected="selected" v-model:selected="selected"
:rows-per-page-options="[1, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination" @update:pagination="updatePagination"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">

View file

@ -26,18 +26,19 @@ const { fetchComplainst } = complainstStore;
const filterRef = ref<HTMLInputElement | null>(null); const filterRef = ref<HTMLInputElement | null>(null);
const filterTable = ref<string>(""); const filterTable = ref<string>("");
const filterKeyword = ref<string>(""); const filterKeyword = ref<string>("");
const maxPage = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const toptitle = ref<number>(0); const toptitle = ref<number>(0);
const statusFilter = ref<string>("NEW"); const statusFilter = ref<string>("NEW");
const option = ref<any[]>(complainstStore.statusOptions); const option = ref<any[]>(complainstStore.statusOptions);
async function updatePagingProp(rowPerpage: number, pageCurrent: number) { const total = ref<number>(0);
rowsPerPage.value = rowPerpage; const totalList = ref<number>(1);
page.value = pageCurrent; const pagination = ref({
await getList(); sortBy: "createdAt",
} descending: true,
page: 1,
rowsPerPage: 10,
});
/** ดึงข้อมูล เรื่องร้องเรียน */ /** ดึงข้อมูล เรื่องร้องเรียน */
async function getList() { async function getList() {
@ -45,15 +46,18 @@ async function getList() {
await http await http
.get( .get(
config.API.complaintList( config.API.complaintList(
page.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword.value, filterKeyword.value,
statusFilter.value statusFilter.value
) )
) )
// //
.then((res) => { .then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value); totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
toptitle.value = res.data.result.total; toptitle.value = res.data.result.total;
const data = res.data.result.data; const data = res.data.result.data;
fetchComplainst(data); fetchComplainst(data);
@ -74,7 +78,7 @@ function redirectToPageadd() {
/** ล้างค่าใน input */ /** ล้างค่าใน input */
function resetFilter() { function resetFilter() {
filterKeyword.value = ""; filterKeyword.value = "";
page.value = 1 pagination.value.page = 1;
if (filterRef.value) { if (filterRef.value) {
filterRef.value.focus(); filterRef.value.focus();
getList(); getList();
@ -95,6 +99,18 @@ function filterOptionFn(val: string, update: Function) {
}); });
} }
function getSearch() {
pagination.value.page = 1;
getList();
}
watch(
() => pagination.value.rowsPerPage,
async () => {
await getSearch();
}
);
/** เรียกใช้งาน ฟังชั่น ตอนเริ่มโหลดหน้า */ /** เรียกใช้งาน ฟังชั่น ตอนเริ่มโหลดหน้า */
onMounted(async () => { onMounted(async () => {
await getList(); await getList();
@ -118,7 +134,7 @@ onMounted(async () => {
option-label="name" option-label="name"
option-value="id" option-value="id"
:options="option" :options="option"
@update:model-value="getList()" @update:model-value="getSearch()"
use-input use-input
@filter="filterOptionFn" @filter="filterOptionFn"
> >
@ -133,7 +149,7 @@ onMounted(async () => {
@click.stop.prevent=" @click.stop.prevent="
(option = complainstStore.statusOptions), (option = complainstStore.statusOptions),
(statusFilter = 'ALL'), (statusFilter = 'ALL'),
getList() getSearch()
" "
class="cursor-pointer" class="cursor-pointer"
/> />
@ -165,7 +181,7 @@ onMounted(async () => {
ref="filterRef" ref="filterRef"
outlined outlined
placeholder="ค้นหา" placeholder="ค้นหา"
@keydown.enter.prevent="getList()" @keydown.enter.prevent="getSearch()"
> >
<template v-slot:append> <template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" /> <q-icon v-if="filterKeyword == ''" name="search" />
@ -199,11 +215,11 @@ onMounted(async () => {
<div class="col-12"> <div class="col-12">
<TableComplaint <TableComplaint
:filter-table="filterTable" :filter-table="filterTable"
:rows-per-page="rowsPerPage" v-model:pagination="pagination"
:page="page" v-model:total="total"
:max-page="maxPage" v-model:total-list="totalList"
@update:pagination="updatePagingProp"
:toptitle="toptitle" :toptitle="toptitle"
:get-list="getList"
/> />
</div> </div>
</q-card> </q-card>

View file

@ -6,29 +6,21 @@ import { useRouter } from "vue-router";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
const currentPage = ref<number>(1);
const router = useRouter(); const router = useRouter();
const complainstStore = useComplainstDataStore(); const complainstStore = useComplainstDataStore();
const total = defineModel<number>("total", { required: true });
const totalList = defineModel<number>("totalList", { required: true });
const pagination = defineModel<any>("pagination", { required: true });
const emit = defineEmits(["update:pagination"]); const emit = defineEmits(["update:pagination"]);
/** รับ props มาจากหน้าหลัก */ /** รับ props มาจากหน้าหลัก */
const props = defineProps({ const props = defineProps({
getList: Function,
filterTable: { filterTable: {
type: String, type: String,
default: "", default: "",
}, },
maxPage: {
type: Number,
require: true,
},
rowsPerPage: {
type: Number,
require: true,
},
page: {
type: Number,
require: true,
},
toptitle: { toptitle: {
type: Number, type: Number,
require: true, require: true,
@ -124,13 +116,6 @@ const columns = ref<QTableProps["columns"]>([
}, },
]); ]);
/** แสดงจำนวนในตาราง */
const pagination = ref({
descending: true,
page: Number(props.page),
rowsPerPage: props.rowsPerPage,
});
/** /**
* งชนสำหร เปลยน route ตาม id บมา * งชนสำหร เปลยน route ตาม id บมา
* @param id ไอดระบ * @param id ไอดระบ
@ -153,20 +138,10 @@ function onDetail(id: string) {
router.push(`/discipline/complaints-detail/${id}`); router.push(`/discipline/complaints-detail/${id}`);
} }
watch( function updatePagination(newPagination: any) {
() => currentPage.value, pagination.value.page = 1;
() => { pagination.value.rowsPerPage = newPagination.rowsPerPage;
updateProp(pagination.value.rowsPerPage, currentPage.value); }
}
);
watch(
() => pagination.value.rowsPerPage,
() => {
currentPage.value = 1;
updateProp(pagination.value.rowsPerPage, currentPage.value);
}
);
/** เริ่มโหลดหน้า page เอาข้อมูลไปเก็บ ใน store*/ /** เริ่มโหลดหน้า page เอาข้อมูลไปเก็บ ใน store*/
onMounted(() => { onMounted(() => {
@ -181,7 +156,6 @@ onMounted(() => {
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="complainstStore.rows" :rows="complainstStore.rows"
:filter="props.filterTable"
row-key="subject" row-key="subject"
flat flat
bordered bordered
@ -189,8 +163,8 @@ onMounted(() => {
dense dense
class="custom-header-table" class="custom-header-table"
:visible-columns="complainstStore.visibleColumns" :visible-columns="complainstStore.visibleColumns"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]" :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">
@ -234,7 +208,7 @@ onMounted(() => {
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ {{
(currentPage - 1) * Number(pagination.rowsPerPage) + (pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex + props.rowIndex +
1 1
}} }}
@ -249,15 +223,17 @@ onMounted(() => {
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ props.toptitle }}รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(props.maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="props.getList?.()"
></q-pagination> ></q-pagination>
</template> </template>
</d-table> </d-table>

View file

@ -61,13 +61,19 @@ const editDirectorId = ref<string>();
const dutyVal = ref<string>(); const dutyVal = ref<string>();
const commandNoVal = ref<string>(); const commandNoVal = ref<string>();
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
const filter = ref<string>(""); const filter = ref<string>("");
const isUpdate = ref<boolean>(false); const isUpdate = ref<boolean>(false);
const filterTable = ref<string>(""); const filterTable = ref<string>("");
const filterKeyword = ref<string>(""); const filterKeyword = ref<string>("");
const maxPage = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const investigationExtendStatus = ref<boolean>(false); const investigationExtendStatus = ref<boolean>(false);
@ -359,28 +365,25 @@ async function getOc(activeId: string) {
}); });
} }
async function updatePagingProp(rowPerpage: number, pageCurrent: number) {
rowsPerPage.value = rowPerpage;
page.value = pageCurrent;
await getList();
}
/** ดึงข้อมูลรายละเอียดสืบสวน */ /** ดึงข้อมูลรายละเอียดสืบสวน */
async function getList() { async function getList() {
showLoader(); showLoader();
await http await http
.get( .get(
config.API.directorList( config.API.directorList(
page.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword.value, filterKeyword2.value,
mainStore.pathDirector(route.name as string) mainStore.pathDirector(route.name as string)
) )
) )
// //
.then((res) => { .then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value);
const data = res.data.result.data; const data = res.data.result.data;
totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
investigateDis.fecthDirector(data); investigateDis.fecthDirector(data);
}) })
.catch((e) => { .catch((e) => {
@ -600,6 +603,18 @@ function filterOptionFnCauseText(val: string, update: Function) {
}); });
} }
function getSearch() {
pagination.value.page = 1;
getList();
}
watch(
() => pagination.value.rowsPerPage,
async () => {
getSearch();
}
);
/** /**
* เชคขอมลจาก props * เชคขอมลจาก props
* เมอมอม * เมอมอม
@ -1744,17 +1759,17 @@ onMounted(async () => {
<DialogDirector <DialogDirector
:get-list="getList" :get-list="getList"
:get-search="getSearch"
v-model:Modal="modal" v-model:Modal="modal"
:click-close="clickClose" :click-close="clickClose"
:rows2="investigateDis.rows2" :rows2="investigateDis.rows2"
v-model:filterKeyword2="filterKeyword2" v-model:filterKeyword2="filterKeyword2"
v-model:type="type" v-model:type="type"
:filter-table="filterTable" :filter-table="filterTable"
:rows-per-page="rowsPerPage" v-model:pagination="pagination"
:page="page" v-model:total="total"
:max-page="maxPage" v-model:total-list="totalList"
:selected-row="rows" :selected-row="rows"
@update:pagination="updatePagingProp"
@returnDirector="returnDirector" @returnDirector="returnDirector"
/> />

View file

@ -20,19 +20,15 @@ const option = ref<any[]>(dataInvestigate.statusOptions);
const filterKeyword = ref<string>(""); const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null); const filterRef = ref<HTMLInputElement | null>(null);
const statusFilter = ref<string>("NEW"); const statusFilter = ref<string>("NEW");
const currentPage = ref<number>(1);
const maxPage = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const toptitle = ref<number>(0); const toptitle = ref<number>(0);
/** const total = ref<number>(0);
*pagination ของตาราง const totalList = ref<number>(1);
*/
const pagination = ref({ const pagination = ref({
descending: false, sortBy: "createdAt",
page: page.value, descending: true,
rowsPerPage: rowsPerPage.value, page: 1,
rowsPerPage: 10,
}); });
const attrs = ref<any>(useAttrs()); const attrs = ref<any>(useAttrs());
@ -52,14 +48,17 @@ async function getList() {
await http await http
.get( .get(
config.API.investigateMain( config.API.investigateMain(
currentPage.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword.value, filterKeyword.value,
statusFilter.value statusFilter.value
) )
) )
.then((res) => { .then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value); totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
toptitle.value = res.data.result.total; toptitle.value = res.data.result.total;
const data = res.data.result.data; const data = res.data.result.data;
@ -104,20 +103,20 @@ function filterOptionFn(val: string, update: Function) {
}); });
} }
watch( function updatePagination(newPagination: any) {
() => currentPage.value, pagination.value.page = 1;
() => { pagination.value.rowsPerPage = newPagination.rowsPerPage;
rowsPerPage.value = pagination.value.rowsPerPage; }
getList();
} function getSerach() {
); pagination.value.page = 1;
getList();
}
watch( watch(
() => pagination.value.rowsPerPage, () => pagination.value.rowsPerPage,
() => { async () => {
rowsPerPage.value = pagination.value.rowsPerPage; getSerach();
currentPage.value = 1;
getList();
} }
); );
@ -145,7 +144,7 @@ onMounted(async () => {
option-label="name" option-label="name"
option-value="id" option-value="id"
:options="option" :options="option"
@update:model-value="getList()" @update:model-value="getSerach()"
use-input use-input
@filter="filterOptionFn" @filter="filterOptionFn"
> >
@ -160,7 +159,7 @@ onMounted(async () => {
@click.stop.prevent=" @click.stop.prevent="
(option = dataInvestigate.statusOptions), (option = dataInvestigate.statusOptions),
(statusFilter = 'ALL'), (statusFilter = 'ALL'),
getList() getSerach()
" "
class="cursor-pointer" class="cursor-pointer"
/> />
@ -178,7 +177,7 @@ onMounted(async () => {
ref="filterRef" ref="filterRef"
outlined outlined
placeholder="ค้นหา" placeholder="ค้นหา"
@keydown.enter.prevent="getList()" @keydown.enter.prevent="getSerach()"
> >
<template v-slot:append> <template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" /> <q-icon v-if="filterKeyword == ''" name="search" />
@ -222,8 +221,8 @@ onMounted(async () => {
class="custom-header-table" class="custom-header-table"
v-bind="attrs" v-bind="attrs"
:visible-columns="dataInvestigate.visibleColumns" :visible-columns="dataInvestigate.visibleColumns"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]" :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">
@ -271,7 +270,7 @@ onMounted(async () => {
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ {{
(currentPage - 1) * Number(pagination.rowsPerPage) + (pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex + props.rowIndex +
1 1
}} }}
@ -293,15 +292,17 @@ onMounted(async () => {
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ toptitle }}รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="getList()"
></q-pagination> ></q-pagination>
</template> </template>
</d-table> </d-table>

View file

@ -61,9 +61,7 @@ const checkRoutePermisson = ref<boolean>(
); );
const organizationOption = ref<DataOption[]>([]); const organizationOption = ref<DataOption[]>([]);
/** query string*/ /** query string*/
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const maxPage = ref<number>(1);
const filterKeyword2 = ref<string>(""); const filterKeyword2 = ref<string>("");
const listDirector = ref<any>([]); const listDirector = ref<any>([]);
const modalEditDirector = ref<boolean>(false); const modalEditDirector = ref<boolean>(false);
@ -79,6 +77,15 @@ const modalPerson = ref<boolean>(false);
/** search data table*/ /** search data table*/
const filter = ref<string>(""); const filter = ref<string>("");
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
const isSave = ref<boolean>(false); // const isSave = ref<boolean>(false); //
const isReadonly = ref<boolean>(false); // const isReadonly = ref<boolean>(false); //
const extendStatus = ref<boolean>(false); const extendStatus = ref<boolean>(false);
@ -233,7 +240,7 @@ async function deleteDirector(id: string) {
async function fetchDatadetail() { async function fetchDatadetail() {
if (props.data) { if (props.data) {
if (countNum.value === 1) { if (countNum.value === 1) {
isReadonly.value = props.data.status != "NEW" ?? true; isReadonly.value = props.data.status != "NEW" ? true : false;
isSave.value = false; isSave.value = false;
isSaveInfo.value = false; isSaveInfo.value = false;
formData.respondentType = props.data.respondentType; formData.respondentType = props.data.respondentType;
@ -444,14 +451,18 @@ async function fetchDListDirector() {
await http await http
.get( .get(
config.API.directorList( config.API.directorList(
page.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword2.value, filterKeyword2.value,
mainStore.pathDirector(route.name as string) mainStore.pathDirector(route.name as string)
) )
) )
.then((res) => { .then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value); total.value = res.data.result.total;
totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
const data = res.data.result.data; const data = res.data.result.data;
let datalistDirector: responseType[] = data.map((e: directorType) => ({ let datalistDirector: responseType[] = data.map((e: directorType) => ({
id: e.id, id: e.id,
@ -480,15 +491,6 @@ async function fetchDListDirector() {
}); });
} }
/**
* function ดเดท Paging กรรมการ
* @param rpp อหน
* @param p หน
*/
async function updatePaging(rpp: number, p: number) {
page.value = p;
rowsPerPage.value = rpp;
}
/** /**
* function return รายชอกรรมการทเลอก * function return รายชอกรรมการทเลอก
@ -709,6 +711,18 @@ function filterOptionFnCauseText(val: string, update: Function) {
}); });
} }
function getSearch() {
pagination.value.page = 1;
fetchDListDirector();
}
watch(
() => pagination.value.rowsPerPage,
async () => {
getSearch();
}
);
watch( watch(
() => formData.disciplinaryFaultLevel, () => formData.disciplinaryFaultLevel,
() => { () => {
@ -1935,16 +1949,16 @@ onMounted(async () => {
<DialogDirector <DialogDirector
v-model:Modal="modal" v-model:Modal="modal"
:get-search="getSearch"
:clickClose="clickClose" :clickClose="clickClose"
:rows2="listDirector" :rows2="listDirector"
v-model:filterKeyword2="filterKeyword2" v-model:filterKeyword2="filterKeyword2"
v-model:type="type" v-model:type="type"
:get-list="fetchDListDirector" :get-list="fetchDListDirector"
:rowsPerPage="rowsPerPage" v-model:pagination="pagination"
:page="page" v-model:total="total"
:maxPage="maxPage" v-model:total-list="totalList"
:selected-row="rows" :selected-row="rows"
@update:pagination="updatePaging"
@returnDirector="returnDirector" @returnDirector="returnDirector"
/> />

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from "vue"; import { onMounted, ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
@ -10,17 +10,22 @@ import { useInvestigateDisStore } from "@/modules/11_discipline/store/Investigat
import Table from "@/modules/11_discipline/components/3_InvestigateDisciplinary/Table.vue"; import Table from "@/modules/11_discipline/components/3_InvestigateDisciplinary/Table.vue";
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
const router = useRouter(); const router = useRouter();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const dataInvestigateDis = useInvestigateDisStore(); const dataInvestigateDis = useInvestigateDisStore();
const { showLoader, hideLoader } = mixin; const { showLoader, hideLoader } = mixin;
const { fetchList } = dataInvestigateDis; const { fetchList } = dataInvestigateDis;
const rowsPerPage = ref<number>(10);
const filter = ref<string>(""); //search data table const filter = ref<string>(""); //search data table
const page = ref<number>(1);
const maxPage = ref<number>(1);
const totalList = ref<number>();
const status = ref<string>("NEW"); const status = ref<string>("NEW");
async function fetchListDisciplinary() { async function fetchListDisciplinary() {
@ -28,12 +33,14 @@ async function fetchListDisciplinary() {
await http await http
.get( .get(
config.API.disciplineDisciplinary() + config.API.disciplineDisciplinary() +
`?page=${page.value}&pageSize=${rowsPerPage.value}&keyword=${filter.value}&status=${status.value}` `?page=${pagination.value.page}&pageSize=${pagination.value.rowsPerPage}&keyword=${filter.value}&status=${status.value}`
) )
.then((res) => { .then((res) => {
const data = res.data.result.data; const data = res.data.result.data;
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value); totalList.value = Math.ceil(
totalList.value = res.data.result.total; res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
fetchList(data); fetchList(data);
}) })
.catch((err) => {}) .catch((err) => {})
@ -57,17 +64,23 @@ function openDetail(id: string) {
router.push(`/discipline-detail/disciplinary/${id}`); router.push(`/discipline-detail/disciplinary/${id}`);
} }
async function updatePagingProp(rowPerpage: number, pageCurrent: number) {
rowsPerPage.value = rowPerpage;
page.value = pageCurrent;
await fetchListDisciplinary();
}
function filterStatus(statusReturn: string) { function filterStatus(statusReturn: string) {
status.value = statusReturn; status.value = statusReturn;
getSearch()
}
function getSearch() {
pagination.value.page = 1;
fetchListDisciplinary(); fetchListDisciplinary();
} }
watch(
() => pagination.value.rowsPerPage,
async () => {
getSearch();
}
);
/** /**
* งขอมลจำลองไปย store * งขอมลจำลองไปย store
*/ */
@ -89,19 +102,17 @@ onMounted(async () => {
:visible-columns="dataInvestigateDis.visibleColumns" :visible-columns="dataInvestigateDis.visibleColumns"
v-model:inputfilter="filter" v-model:inputfilter="filter"
v-model:inputvisible="dataInvestigateDis.visibleColumns" v-model:inputvisible="dataInvestigateDis.visibleColumns"
:pagination="rowsPerPage"
:nornmalData="true" :nornmalData="true"
:paging="true" :paging="true"
:titleText="''" :titleText="''"
:rowsPerPage="rowsPerPage" v-model:pagination="pagination"
:page="page" v-model:total="total"
:maxPage="maxPage" v-model:total-list="totalList"
:totalList="totalList"
:fetchListDisciplinary="fetchListDisciplinary" :fetchListDisciplinary="fetchListDisciplinary"
@update:pagination="updatePagingProp"
v-model:open-edit="openEdit" v-model:open-edit="openEdit"
:open-detail="openDetail" :open-detail="openDetail"
:filterStatus="filterStatus" :filterStatus="filterStatus"
:get-search="getSearch"
> >
</Table> </Table>
</div> </div>

View file

@ -4,6 +4,10 @@ import { ref, useAttrs, watch } from "vue";
import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore"; import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
const total = defineModel<number>("total", { required: true });
const totalList = defineModel<number>("totalList", { required: true });
const pagination = defineModel<any>("pagination", { required: true });
const dataInvestigateDis = useInvestigateDisStore(); const dataInvestigateDis = useInvestigateDisStore();
const table = ref<any>(null); const table = ref<any>(null);
const filterRef = ref<any>(null); const filterRef = ref<any>(null);
@ -22,6 +26,7 @@ const props = defineProps({
icon: String, icon: String,
inputvisible: Array, inputvisible: Array,
editvisible: Boolean, editvisible: Boolean,
getSearch: Function,
validate: { validate: {
type: Function, type: Function,
default: () => console.log("not function"), default: () => console.log("not function"),
@ -79,13 +84,6 @@ const emit = defineEmits([
"update:pagination", "update:pagination",
]); ]);
/** แสดงจำนวนในตาราง */
const pagination = ref({
descending: true,
page: Number(props.page),
rowsPerPage: props.rowsPerPage,
});
function paginationLabel(start: string, end: string, total: string) { function paginationLabel(start: string, end: string, total: string) {
if (paging.value == true) return " " + start + "-" + end + " ใน " + total; if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total; else return start + "-" + end + " ใน " + total;
@ -116,7 +114,7 @@ function dataUpdate() {
} }
function filterFn() { function filterFn() {
props.fetchListDisciplinary?.(); props.getSearch?.();
} }
/** /**
@ -133,20 +131,10 @@ function filterOptionFn(val: string, update: Function) {
}); });
} }
watch( function updatePagination(newPagination: any) {
() => currentPage.value, pagination.value.page = 1;
() => { pagination.value.rowsPerPage = newPagination.rowsPerPage;
updateProp(pagination.value.rowsPerPage, currentPage.value); }
}
);
watch(
() => pagination.value.rowsPerPage,
() => {
currentPage.value = 1;
updateProp(pagination.value.rowsPerPage, currentPage.value);
}
);
</script> </script>
<template> <template>
@ -232,20 +220,21 @@ watch(
virtual-scroll virtual-scroll
:virtual-scroll-sticky-size-start="48" :virtual-scroll-sticky-size-start="48"
dense dense
:pagination-label="paginationLabel"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ props.totalList }} รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(props.maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="props.fetchListDisciplinary?.()"
></q-pagination> ></q-pagination>
</template> </template>
<template v-slot:header="props"> <template v-slot:header="props">

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from "vue"; import { onMounted, ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
@ -19,16 +19,16 @@ const store = useDisciplineResultStore();
const { showLoader, hideLoader, messageError } = mixin; const { showLoader, hideLoader, messageError } = mixin;
const { fetchList } = store; const { fetchList } = store;
const initialPagination = ref<Pagination>({
rowsPerPage: 0,
});
const page = ref<number>(1);
const pageSize = ref<number>(10);
const maxPage = ref<number>(1);
const totalList = ref<number>(0);
const filter = ref<string>(""); const filter = ref<string>("");
const status = ref<string>("DONE"); const status = ref<string>("DONE");
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
/** function เรียกรายการสรุปผลการพิจารณาทางวินัย*/ /** function เรียกรายการสรุปผลการพิจารณาทางวินัย*/
async function fetchListResult() { async function fetchListResult() {
@ -36,12 +36,14 @@ async function fetchListResult() {
await http await http
.get( .get(
config.API.listResult() + config.API.listResult() +
`?page=${page.value}&pageSize=${pageSize.value}&keyword=${filter.value}&status=${status.value}` `?page=${pagination.value.page}&pageSize=${pagination.value.rowsPerPage}&keyword=${filter.value}&status=${status.value}`
) )
.then(async (res) => { .then(async (res) => {
const data = res.data.result.data; const data = res.data.result.data;
maxPage.value = Math.ceil(res.data.result.total / pageSize.value); totalList.value = Math.ceil(
totalList.value = res.data.result.total; res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
await fetchList(data); await fetchList(data);
}) })
.catch((err) => { .catch((err) => {
@ -52,13 +54,6 @@ async function fetchListResult() {
}); });
} }
async function updateQueryString(p: number, pS: number, key: string) {
page.value = pS === pageSize.value ? p : 1;
pageSize.value = pS;
filter.value = key;
await fetchListResult();
}
/** /**
* ไปหนาแกไข * ไปหนาแกไข
* @param id ไอดเฉพาะ รายบคคล * @param id ไอดเฉพาะ รายบคคล
@ -76,9 +71,21 @@ function openDetail(id: string) {
function filterStatus(statusReturn: string) { function filterStatus(statusReturn: string) {
status.value = statusReturn; status.value = statusReturn;
getSearch();
}
function getSearch() {
pagination.value.page = 1;
fetchListResult(); fetchListResult();
} }
watch(
() => pagination.value.rowsPerPage,
async () => {
getSearch();
}
);
/** /**
* งขอมลจำลองไปย store * งขอมลจำลองไปย store
*/ */
@ -100,19 +107,17 @@ onMounted(async () => {
:visible-columns="store.visibleColumns" :visible-columns="store.visibleColumns"
v-model:inputfilter="filter" v-model:inputfilter="filter"
v-model:inputvisible="store.visibleColumns" v-model:inputvisible="store.visibleColumns"
:pagination="initialPagination"
:nornmalData="true" :nornmalData="true"
:paging="true" :paging="true"
:titleText="''" :titleText="''"
:page="page"
:fetchListResult="fetchListResult" :fetchListResult="fetchListResult"
:pageSize="pageSize" :get-search="getSearch"
:maxPage="maxPage"
:totalList="totalList"
@update:queryString="updateQueryString"
v-model:open-edit="openEdit" v-model:open-edit="openEdit"
v-model:open-detail="openDetail" v-model:open-detail="openDetail"
:filterStatus="filterStatus" :filterStatus="filterStatus"
v-model:pagination="pagination"
v-model:total="total"
v-model:total-list="totalList"
> >
</Table> </Table>
</div> </div>

View file

@ -4,6 +4,10 @@ import { ref, useAttrs, watch } from "vue";
import { useDisciplineResultStore } from "@/modules/11_discipline/store/ResultStore"; import { useDisciplineResultStore } from "@/modules/11_discipline/store/ResultStore";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
const total = defineModel<number>("total", { required: true });
const totalList = defineModel<number>("totalList", { required: true });
const pagination = defineModel<any>("pagination", { required: true });
const store = useDisciplineResultStore(); const store = useDisciplineResultStore();
const table = ref<any>(null); const table = ref<any>(null);
const filterRef = ref<any>(null); const filterRef = ref<any>(null);
@ -22,6 +26,7 @@ const props = defineProps({
icon: String, icon: String,
inputvisible: Array, inputvisible: Array,
editvisible: Boolean, editvisible: Boolean,
getSearch: Function,
validate: { validate: {
type: Function, type: Function,
default: () => console.log("not function"), default: () => console.log("not function"),
@ -50,28 +55,9 @@ const props = defineProps({
type: Boolean, type: Boolean,
defualt: false, defualt: false,
}, },
page: {
type: Number,
},
pageSize: {
type: Number,
},
maxPage: {
type: Number,
},
totalList: {
type: Number,
},
}); });
const currentPage = ref<number>(1);
const filter = ref<string>(""); const filter = ref<string>("");
const pagination = ref({
descending: false,
page: props.page,
rowsPerPage: props.pageSize,
});
const emit = defineEmits([ const emit = defineEmits([
"update:inputfilter", "update:inputfilter",
"update:inputvisible", "update:inputvisible",
@ -87,26 +73,13 @@ function resetFilter() {
// reset X // reset X
emit("update:inputfilter", ""); emit("update:inputfilter", "");
filterRef.value.focus(); filterRef.value.focus();
props.fetchListResult?.(); props.getSearch?.();
}
function updateRowsPerPage(newPagination: any) {
pagination.value = newPagination;
currentPage.value = 1;
} }
function updatePaging(p: number, pS: number, key: string) { function updatePaging(p: number, pS: number, key: string) {
emit("update:queryString", p, pS, key); emit("update:queryString", p, pS, key);
} }
watch([() => currentPage.value, () => pagination.value.rowsPerPage], () => {
emit(
"update:queryString",
currentPage.value,
Number(pagination.value.rowsPerPage),
filter.value
);
});
function dataUpdate() { function dataUpdate() {
props.filterStatus(statusFilter.value); props.filterStatus(statusFilter.value);
@ -116,7 +89,7 @@ function updateInput(value: string | number | null) {
emit("update:inputfilter", value); emit("update:inputfilter", value);
} }
function filterFn() { function filterFn() {
props.fetchListResult?.(); props.getSearch?.();
} }
/** /**
@ -132,6 +105,11 @@ function filterOptionFn(val: string, update: Function) {
); );
}); });
} }
function updatePagination(newPagination: any) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
</script> </script>
<template> <template>
@ -217,8 +195,7 @@ function filterOptionFn(val: string, update: Function) {
:virtual-scroll-sticky-size-start="48" :virtual-scroll-sticky-size-start="48"
dense dense
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
:pagination="pagination" @update:pagination="updatePagination"
@update:pagination="updateRowsPerPage"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -260,7 +237,7 @@ function filterOptionFn(val: string, update: Function) {
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ {{
(currentPage - 1) * Number(pagination.rowsPerPage) + (pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex + props.rowIndex +
1 1
}} }}
@ -275,15 +252,17 @@ function filterOptionFn(val: string, update: Function) {
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ props.totalList }} รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(props.maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="props.fetchListResult?.()"
></q-pagination> ></q-pagination>
</template> </template>
</d-table> </d-table>

View file

@ -183,6 +183,7 @@ function updateSelect() {
async function searchInput() { async function searchInput() {
searchRef.value.validate(); searchRef.value.validate();
if (!searchRef.value.hasError) { if (!searchRef.value.hasError) {
pagination.value.page = 1;
await getSearch(); await getSearch();
} }
} }
@ -348,7 +349,7 @@ watch(
dense dense
class="custom-header-table" class="custom-header-table"
:visible-columns="visibleColumnsRespondent" :visible-columns="visibleColumnsRespondent"
:rows-per-page-options="[1, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination" @update:pagination="updatePagination"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">

View file

@ -24,11 +24,6 @@ const { messageError, showLoader, hideLoader, dialogRemove, success } = mixin;
const titleInvestigate = ref<string>(""); const titleInvestigate = ref<string>("");
const personalId = ref<string>(""); const personalId = ref<string>("");
const currentPage = ref<number>(1);
const maxPage = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const totalList = ref<number>(0);
const modalDetail = ref<boolean>(false); const modalDetail = ref<boolean>(false);
const isEdit = ref<boolean>(false); const isEdit = ref<boolean>(false);
@ -41,13 +36,13 @@ const dataPopUp = ref<DirectorRowsResponse>();
const filterKeyword = ref<string>(""); const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null); const filterRef = ref<HTMLInputElement | null>(null);
/** const total = ref<number>(0);
*pagination ของตาราง const totalList = ref<number>(1);
*/
const pagination = ref({ const pagination = ref({
descending: false, sortBy: "createdAt",
page: page.value, descending: true,
rowsPerPage: rowsPerPage.value, page: 1,
rowsPerPage: 10,
}); });
async function getList() { async function getList() {
@ -55,16 +50,18 @@ async function getList() {
await http await http
.get( .get(
config.API.directorList( config.API.directorList(
currentPage.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword.value, filterKeyword.value,
mainStore.pathDirector(route.name as string) mainStore.pathDirector(route.name as string)
) )
) )
.then((res) => { .then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value);
totalList.value = res.data.result.total;
const data = res.data.result.data; const data = res.data.result.data;
totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
dataStore.fetchData(data); dataStore.fetchData(data);
}) })
.catch((e) => { .catch((e) => {
@ -106,12 +103,12 @@ function resetFilter() {
filterKeyword.value = ""; filterKeyword.value = "";
if (filterRef.value) { if (filterRef.value) {
filterRef.value.focus(); filterRef.value.focus();
getList(); getSearch();
} }
} }
function filterFn() { function filterFn() {
getList(); getSearch();
} }
function openDetail(data: DirectorRowsResponse, typeChange: string) { function openDetail(data: DirectorRowsResponse, typeChange: string) {
@ -135,20 +132,20 @@ function onEdit(id: string, check: boolean) {
isEdit.value = check; isEdit.value = check;
} }
watch( function updatePagination(newPagination: any) {
() => currentPage.value, pagination.value.page = 1;
() => { pagination.value.rowsPerPage = newPagination.rowsPerPage;
rowsPerPage.value = pagination.value.rowsPerPage; }
getList();
} function getSearch() {
); pagination.value.page = 1;
getList();
}
watch( watch(
() => pagination.value.rowsPerPage, () => pagination.value.rowsPerPage,
() => { async () => {
rowsPerPage.value = pagination.value.rowsPerPage; getSearch();
currentPage.value = 1;
getList();
} }
); );
@ -228,19 +225,22 @@ onMounted(() => {
bordered bordered
:paging="true" :paging="true"
dense dense
v-model:pagination="pagination" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
:visible-columns="dataStore.visibleColumns" :visible-columns="dataStore.visibleColumns"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ totalList }} รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="getList"
></q-pagination> ></q-pagination>
</template> </template>
<template v-slot:header="props"> <template v-slot:header="props">
@ -293,7 +293,11 @@ onMounted(() => {
</q-td> </q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }} {{
(pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex +
1
}}
</div> </div>
<div <div
v-else-if=" v-else-if="

View file

@ -124,26 +124,19 @@ const columns = ref<QTableProps["columns"]>([
const openModal = () => (modal.value = true); const openModal = () => (modal.value = true);
const currentPage = ref<number>(1); const total = ref<number>(0);
const maxPage = ref<number>(1); const totalList = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const totalList = ref<number>(0);
/**
*pagination ของตาราง
*/
const pagination = ref({ const pagination = ref({
descending: false, sortBy: "createdAt",
page: page.value, descending: true,
rowsPerPage: rowsPerPage.value, page: 1,
rowsPerPage: 10,
}); });
function resetFilter() { function resetFilter() {
filterKeyword.value = ""; filterKeyword.value = "";
filterRef.value.focus(); filterRef.value.focus();
getList(); getSearch();
} }
/** เปิด popup ส่งไปออกคำสั่ง โดย PENDING*/ /** เปิด popup ส่งไปออกคำสั่ง โดย PENDING*/
@ -170,15 +163,17 @@ async function getList() {
await http await http
.get( .get(
config.API.suspendMain( config.API.suspendMain(
currentPage.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword.value filterKeyword.value
) )
) )
.then(async (res) => { .then(async (res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value);
const data = await res.data.result.data; const data = await res.data.result.data;
totalList.value = res.data.result.total; totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
await dataStore.getData(data); await dataStore.getData(data);
hideLoader(); hideLoader();
}) })
@ -190,23 +185,23 @@ async function getList() {
} }
function filterFn() { function filterFn() {
getSearch();
}
function updatePagination(newPagination: any) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
function getSearch() {
pagination.value.page = 1;
getList(); getList();
} }
watch(
() => currentPage.value,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
getList();
}
);
watch( watch(
() => pagination.value.rowsPerPage, () => pagination.value.rowsPerPage,
() => { async () => {
rowsPerPage.value = pagination.value.rowsPerPage; getSearch();
currentPage.value = 1;
getList();
} }
); );
@ -285,19 +280,21 @@ onMounted(async () => {
:rows="dataStore.rows" :rows="dataStore.rows"
row-key="id" row-key="id"
:visible-columns="dataStore.visibleColumns" :visible-columns="dataStore.visibleColumns"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ totalList }} รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="getList"
></q-pagination> ></q-pagination>
</template> </template>
<template v-slot:header="props"> <template v-slot:header="props">
@ -341,9 +338,9 @@ onMounted(async () => {
</q-btn> </q-btn>
</q-td> </q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name === 'no'"> <div v-if="col.name == 'no'">
{{ {{
(currentPage - 1) * Number(pagination.rowsPerPage) + (pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex + props.rowIndex +
1 1
}} }}

View file

@ -31,21 +31,6 @@ const type = ref<DataOption[]>([
const filterKeyword = ref<string>(""); const filterKeyword = ref<string>("");
const dataRow = ref<RowList[]>([]); const dataRow = ref<RowList[]>([]);
const currentPage = ref<number>(1);
const maxPage = ref<number>(1);
const page = ref<number>(1);
const totalList = ref<number>(0);
const rowsPerPage = ref<number>(10);
/**
*pagination ของตาราง
*/
const pagination = ref({
descending: false,
page: page.value,
rowsPerPage: rowsPerPage.value,
});
const formData = reactive<any>({ const formData = reactive<any>({
type: "ALL", type: "ALL",
@ -53,6 +38,15 @@ const formData = reactive<any>({
year: new Date().getFullYear().toString(), year: new Date().getFullYear().toString(),
}); });
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"no", "no",
"type", "type",
@ -184,23 +178,6 @@ const columns = ref<QTableProps["columns"]>([
}, },
]); ]);
watch(
() => currentPage.value,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
getData();
}
);
watch(
() => pagination.value.rowsPerPage,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
currentPage.value = 1;
getData();
}
);
/** ไปยังหน้าเพิ่มข้อมูล */ /** ไปยังหน้าเพิ่มข้อมูล */
function redirectToPageDetail(id: string) { function redirectToPageDetail(id: string) {
dataStore.rowsAdd = []; dataStore.rowsAdd = [];
@ -220,7 +197,7 @@ function editPage(id: string) {
/** ดึงข้อมูลเมื่อ กด enter */ /** ดึงข้อมูลเมื่อ กด enter */
function filterFn() { function filterFn() {
getData(); getSearch();
} }
/** ปิด pop up */ /** ปิด pop up */
@ -237,14 +214,16 @@ async function getData() {
formData.status, formData.status,
formData.type, formData.type,
formData.year, formData.year,
currentPage.value, pagination.value.page,
rowsPerPage.value, pagination.value.rowsPerPage,
filterKeyword.value filterKeyword.value
) )
) )
.then((res) => { .then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value); totalList.value = Math.ceil(
totalList.value = res.data.result.total; res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
fetchAppealComplain(res.data.result.data); fetchAppealComplain(res.data.result.data);
}) })
.catch((e) => { .catch((e) => {
@ -257,19 +236,19 @@ async function getData() {
/** update status */ /** update status */
function dataUpdate() { function dataUpdate() {
getData(); getSearch();
} }
/** set ปี ทั้งหมด */ /** set ปี ทั้งหมด */
function yearAll() { function yearAll() {
formData.year = 0; formData.year = 0;
getData(); getSearch();
} }
/** ฟังชั่น เคลียฟิลเตอร์ */ /** ฟังชั่น เคลียฟิลเตอร์ */
function resetFilter() { function resetFilter() {
filterKeyword.value = ""; filterKeyword.value = "";
getData(); getSearch();
} }
const option = ref<any[]>(dataStore.statusOptions); const option = ref<any[]>(dataStore.statusOptions);
const optionType = ref<any[]>(type.value); const optionType = ref<any[]>(type.value);
@ -297,6 +276,24 @@ function filterOptionFnType(val: string, update: Function) {
}); });
} }
function updatePagination(newPagination: any) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
function getSearch() {
pagination.value.page = 1;
getData();
}
watch(
() => pagination.value.rowsPerPage,
async () => {
getSearch();
}
);
/** เรียกใช้งาน ฟังชั่น ตอนเริ่มโหลดหน้า */ /** เรียกใช้งาน ฟังชั่น ตอนเริ่มโหลดหน้า */
onMounted(async () => { onMounted(async () => {
getData(); getData();
@ -496,19 +493,21 @@ onMounted(async () => {
dense dense
class="custom-header-table" class="custom-header-table"
:visible-columns="dataStore.visibleColumns" :visible-columns="dataStore.visibleColumns"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
> >
<template v-slot:pagination="scope"> <template v-slot:pagination="scope">
งหมด {{ totalList }} รายการ งหมด {{ total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="pagination.page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max="Number(maxPage)" :max="Number(totalList)"
size="sm" size="sm"
boundary-links boundary-links
direction-links direction-links
:max-pages="5"
@update:model-value="getData"
></q-pagination> ></q-pagination>
</template> </template>
<template v-slot:header="props"> <template v-slot:header="props">
@ -558,7 +557,7 @@ onMounted(async () => {
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ {{
(currentPage - 1) * Number(pagination.rowsPerPage) + (pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex + props.rowIndex +
1 1
}} }}

View file

@ -7,8 +7,13 @@ import type { directorType } from "@/modules/11_discipline/interface/index/Main"
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
const total = defineModel<number>("total", { required: true });
const totalList = defineModel<number>("totalList", { required: true });
const pagination = defineModel<any>("pagination", { required: true });
const filterKeyword2 = defineModel<string>("filterKeyword2", {
required: true,
});
const selected = ref<directorType[]>([]); const selected = ref<directorType[]>([]);
const currentPage = ref<number>(1);
/** ค้นหาคอลัม */ /** ค้นหาคอลัม */
const visibleColumns2 = ref<string[]>([ const visibleColumns2 = ref<string[]>([
"no", "no",
@ -84,9 +89,8 @@ const columns2 = ref<QTableProps["columns"]>([
const props = defineProps({ const props = defineProps({
Modal: Boolean, Modal: Boolean,
clickClose: Function, clickClose: Function,
getData: Function, getSearch: Function,
rows2: Array, rows2: Array,
filterKeyword2: String,
filterTable: { filterTable: {
type: String, type: String,
default: "", default: "",
@ -113,13 +117,6 @@ const props = defineProps({
}, },
}); });
/** แสดงจำนวนในตาราง */
const pagination = ref({
descending: true,
page: Number(props.page),
rowsPerPage: props.rowsPerPage,
});
const checkSelected = computed(() => { const checkSelected = computed(() => {
if (selected.value.length === 0) { if (selected.value.length === 0) {
return true; return true;
@ -127,7 +124,6 @@ const checkSelected = computed(() => {
}); });
const emit = defineEmits([ const emit = defineEmits([
"update:filterKeyword2",
"update:selected", "update:selected",
"update:pagination", "update:pagination",
"returnDirector", "returnDirector",
@ -142,45 +138,29 @@ async function directorSave() {
* งค input กลบไปหนาหล * งค input กลบไปหนาหล
* @param value าจาก input ลเตอร * @param value าจาก input ลเตอร
*/ */
function updateInput(value: any) { function updateInput() {
emit("update:filterKeyword2", value); props.getSearch?.();
} }
/**รีเซ็ตค่าในช่องค้นหา */ /**รีเซ็ตค่าในช่องค้นหา */
function Reset() { function Reset() {
emit("update:filterKeyword2", ""); filterKeyword2.value = ''
props.getSearch?.();
} }
/** function updatePagination(newPagination: any) {
* งเลขหน กลบไปหนาหล pagination.value.page = 1;
* @param newPagination จำนวนขอมลทองการแสดง pagination.value.rowsPerPage = newPagination.rowsPerPage;
* @param page เลขหนาปจจ
*/
function updateProp(newPagination: any, page: number) {
// event parent component props
emit("update:pagination", newPagination, page);
} }
/** เช็คค่า props.Modal === true */ /** เช็คค่า props.Modal === true */
watchEffect(() => {
if (props.Modal === true) {
selected.value = props.selectedRow;
props.getList();
}
});
watch( watch(
() => currentPage.value, () => props.Modal,
() => { () => {
updateProp(pagination.value.rowsPerPage, currentPage.value); if (props.Modal === true) {
} selected.value = props.selectedRow;
); props.getList();
}
watch(
() => pagination.value.rowsPerPage,
() => {
currentPage.value = 1;
updateProp(pagination.value.rowsPerPage, currentPage.value);
} }
); );
</script> </script>
@ -197,8 +177,8 @@ watch(
dense dense
class="col-12 q-mb-sm" class="col-12 q-mb-sm"
debounce="300" debounce="300"
:model-value="filterKeyword2" v-model="filterKeyword2"
@update:model-value="updateInput" @keydown.enter.prevent="updateInput"
placeholder="ค้นหารายชื่อ" placeholder="ค้นหารายชื่อ"
style="max-width: 100%" style="max-width: 100%"
> >
@ -216,14 +196,28 @@ watch(
<d-table <d-table
:columns="columns2" :columns="columns2"
:rows="rows2" :rows="rows2"
:filter="filterKeyword2"
row-key="id" row-key="id"
:visible-columns="visibleColumns2" :visible-columns="visibleColumns2"
selection="multiple" selection="multiple"
v-model:selected="selected" v-model:selected="selected"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
v-model:pagination="pagination" @update:pagination="updatePagination"
> >
<template v-slot:pagination="scope">
งหมด {{ total }} รายการ
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="Number(totalList)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="props.getList?.()"
></q-pagination>
</template>
<template v-slot:header-selection="scope"> <template v-slot:header-selection="scope">
<q-checkbox <q-checkbox
keep-color keep-color
@ -244,7 +238,11 @@ watch(
</q-td> </q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }} {{
(pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex +
1
}}
</div> </div>
<div v-else> <div v-else>
{{ col.value }} {{ col.value }}