update Pagination สรรหา

This commit is contained in:
Warunee Tamkoo 2023-10-25 00:07:58 +07:00
parent 4ead339be2
commit a916ce797f
2 changed files with 139 additions and 277 deletions

View file

@ -1,51 +1,19 @@
<template>
<div class="q-px-md q-pb-md">
<q-card
bordered
flat
class="col-12 row q-py-sm items-center bg-grey-1"
v-show="statusPayment"
>
<q-card bordered flat class="col-12 row q-py-sm items-center bg-grey-1" v-show="statusPayment">
<div class="col-12 row q-col-gutter-sm">
<span class="text-subtitle1">{{ titleText }}</span>
<q-select
dense
outlined
:model-value="inputvisibleFilter"
:options="optionsFilter"
option-value="id"
option-label="name"
map-options
class="col-xs-12 col-sm-3"
label="สถานะ"
emit-value
@update:model-value="updateVisibleFilter"
v-if="optionsFilter != undefined && optionsFilter.length > 0"
/>
<q-file
v-model="files"
dense
:label="setSeat == false ? 'อัปโหลดที่นั่งสอบ' : 'อัปโหลดคะแนนสอบ'"
outlined
use-chips
multiple
class="col-xs-12 col-sm-4"
v-if="statusPayment"
>
<q-select dense outlined :model-value="inputvisibleFilter" :options="optionsFilter" option-value="id"
option-label="name" map-options class="col-xs-12 col-sm-3" label="สถานะ" emit-value
@update:model-value="updateVisibleFilter" v-if="optionsFilter != undefined && optionsFilter.length > 0" />
<q-file v-model="files" dense :label="setSeat == false ? 'อัปโหลดที่นั่งสอบ' : 'อัปโหลดคะแนนสอบ'" outlined
use-chips multiple class="col-xs-12 col-sm-4" v-if="statusPayment">
<template v-slot:prepend>
<q-icon name="attach_file" color="blue" />
</template>
</q-file>
<div>
<q-btn
size="md"
icon="mdi-upload"
round
flat
color="blue"
v-if="statusPayment"
@click="uploadFile"
>
<q-btn size="md" icon="mdi-upload" round flat color="blue" v-if="statusPayment" @click="uploadFile">
<q-tooltip v-if="setSeat == false">อัปโหลดที่นั่งสอบ</q-tooltip>
<q-tooltip v-if="setSeat == true">อัปโหลดคะแนนสอบ</q-tooltip>
</q-btn>
@ -54,34 +22,15 @@
</q-card>
<div class="col-12 row q-py-sm items-center q-col-gutter-sm">
<div class="col-xs-12 col-sm-3" v-show="!statusPayment">
<q-select
dense
outlined
:model-value="inputvisibleFilter"
:options="optionsFilter"
option-value="id"
option-label="name"
map-options
class=""
label="สถานะ"
emit-value
@update:model-value="updateVisibleFilter"
v-if="optionsFilter != undefined && optionsFilter.length > 0"
/>
<q-select dense outlined :model-value="inputvisibleFilter" :options="optionsFilter" option-value="id"
option-label="name" map-options class="" label="สถานะ" emit-value @update:model-value="updateVisibleFilter"
v-if="optionsFilter != undefined && optionsFilter.length > 0" />
</div>
<div>
<q-btn
size="md"
icon="mdi-playlist-check"
round
flat
color="primary"
@click="candidateCheckProfileDialog"
:disabled="
attrs.rows.filter((r) => r.status == 'checkRegister').length == 0 ||
<q-btn size="md" icon="mdi-playlist-check" round flat color="primary" @click="candidateCheckProfileDialog"
:disabled="attrs.rows.filter((r: any) => r.status == 'checkRegister').length == 0 ||
selected.length == 0
"
>
">
<q-tooltip>ตรวจสอบขอม/ไดบใบสมครแล</q-tooltip>
</q-btn>
</div>
@ -93,21 +42,11 @@
<q-item clickable v-close-popup @click="downloadFileDashboard">
<q-item-section>ดาวนโหลดสรปขอมลสมครสอบ</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click.stop.prevent="clickCandidateList()"
>
<q-item clickable v-close-popup @click.stop.prevent="clickCandidateList()">
<q-item-section>ดาวนโหลดรายชอผทธสอบ</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click.stop.prevent="clickPassExam()"
>
<q-item-section
>ดาวนโหลดรายชอผสอบคดเลอกได</q-item-section
>
<q-item clickable v-close-popup @click.stop.prevent="clickPassExam()">
<q-item-section>ดาวนโหลดรายชอผสอบคดเลอกได</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="downloadFile()">
<q-item-section>ดาวนโหลดจดการรายชอผสมคร</q-item-section>
@ -120,88 +59,35 @@
</q-btn>
</div>
<div>
<q-btn
size="md"
icon="mdi-content-save-move-outline"
round
flat
color="indigo"
v-if="statusPayment && setSeat == true"
@click="candidateToPlacement"
>
<q-btn size="md" icon="mdi-content-save-move-outline" round flat color="indigo"
v-if="statusPayment && setSeat == true" @click="candidateToPlacement">
<q-tooltip>บรรจานการคดเลอก</q-tooltip>
</q-btn>
</div>
<q-space />
<div class="items-center gt-xs" style="display: flex">
<!-- นหาขอความใน table -->
<q-input
standout
dense
:model-value="inputfilter"
ref="filterRef"
@update:model-value="updateInput"
outlined
debounce="300"
placeholder="ค้นหา"
style="max-width: 200px"
class="q-ml-sm"
>
<q-input standout dense :model-value="inputfilter" ref="filterRef" @update:model-value="updateInput" outlined
debounce="300" placeholder="ค้นหา" style="max-width: 200px" class="q-ml-sm">
<template v-slot:append>
<q-icon v-if="inputfilter == ''" name="search" />
<q-icon
v-if="inputfilter !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
<q-icon v-if="inputfilter !== ''" name="clear" class="cursor-pointer" @click="resetFilter" />
</template>
</q-input>
<!-- แสดงคอลมนใน table -->
<q-select
:model-value="inputvisible"
@update:model-value="updateVisible"
:display-value="$q.lang.table.columns"
multiple
outlined
dense
:options="attrs.columns"
options-dense
option-value="name"
map-options
emit-value
style="min-width: 150px"
class="q-ml-sm"
/>
<q-select :model-value="inputvisible" @update:model-value="updateVisible" :display-value="$q.lang.table.columns"
multiple outlined dense :options="attrs.columns" options-dense option-value="name" map-options emit-value
style="min-width: 150px" class="q-ml-sm" />
</div>
</div>
<q-table
ref="table"
flat
bordered
class="custom-header-table"
v-bind="attrs"
virtual-scroll
:virtual-scroll-sticky-size-start="48"
dense
:pagination-label="paginationLabel"
:pagination="initialPagination"
:rows-per-page-options="paging == true ? [25, 50, 100, 500] : []"
row-key="id"
selection="multiple"
v-model:selected="selected"
>
<q-table ref="table" flat bordered class="custom-header-table" v-bind="attrs" virtual-scroll
:virtual-scroll-sticky-size-start="48" dense :pagination="initialPagination"
:rows-per-page-options="paging == true ? [25, 50, 100, 500] : []" row-key="id" selection="multiple"
v-model:selected="selected" @update:pagination="updatePagination">
<template v-slot:pagination="scope">
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="scope.pagesNumber"
:max-pages="5"
size="sm"
boundary-links
direction-links
></q-pagination>
งหมด {{ props.total }} รายการ
<q-pagination v-model="currentPage" active-color="primary" color="dark" :max-pages="5" size="sm" boundary-links direction-links :max="props.maxPage < 1 ? 1 : props.maxPage"></q-pagination>
</template>
<template v-slot:header="props">
<q-tr :props="props">
@ -212,12 +98,8 @@
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th
auto-width
v-if="
editvisible == true || nextPageVisible == true || history == true
"
/>
<q-th auto-width v-if="editvisible == true || nextPageVisible == true || history == true
" />
</q-tr>
</template>
<template #body="props">
@ -227,7 +109,7 @@
</div>
</template>
<script setup lang="ts">
import { ref, useAttrs } from "vue";
import { ref, useAttrs, watch, watchEffect } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
@ -251,12 +133,6 @@ const selected = ref<string[]>([]);
const { messageError, showLoader, hideLoader } = mixin;
const dateFilter = ref<[Date, Date]>([new Date(), new Date()]); //
const pagination = ref({
// sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
const props = defineProps({
inputfilter: String,
inputvisible: Array,
@ -287,6 +163,22 @@ const props = defineProps({
type: Boolean,
defualt: false,
},
pageSize: {
type: Number,
defualt: 25
},
page: {
type: Number,
defualt: 1
},
maxPage: {
type: Number,
defualt: 1
},
total: {
type: Number,
defualt: 0
},
nornmalData: {
type: Boolean,
defualt: false,
@ -337,11 +229,32 @@ const props = defineProps({
type: Function,
default: () => console.log("not function"),
},
changePage: {
type: Function,
default: () => console.log("not function"),
}
});
// Pagination - page & change page & get new data
const currentPage = ref<number>(1)
watch(currentPage, () => {
props.changePage(currentPage.value, props.pageSize, true);
});
// Pagination - initial pagination
const initialPagination = ref<any>({
rowsPerPage: props.paging == true ? 25 : 0,
sortBy: null,
descending: false,
page: 1,
rowsPerPage: props.pageSize,
});
// Pagination - update rowsPerPage
async function updatePagination(newPagination: any) {
props.changePage(1, newPagination.rowsPerPage, true);
initialPagination.value = newPagination
}
const emit = defineEmits([
"update:inputfilter",
"update:inputvisible",
@ -350,8 +263,14 @@ const emit = defineEmits([
"update:inputvisibleFilter",
]);
const updateInput = (value: any) => {
emit("update:inputfilter", value);
const updateInput = async (value: any) => {
await emit("update:inputfilter", value);
// search & get new data by keyword
if (value.length > 3) {
props.changePage(1, props.pageSize);
currentPage.value = 1
}
};
const updateVisible = (value: any) => {
emit("update:inputvisible", value);
@ -360,12 +279,6 @@ const updateVisibleFilter = (value: any) => {
emit("update:inputvisibleFilter", value);
};
const paginationLabel = (start: string, end: string, total: string) => {
if (props.paging == true)
return " " + start + " ถึง " + end + " จากจำนวน " + total + " รายการ";
else return start + "-" + end + " ใน " + total;
};
const uploadFile = async () => {
if (files.value.length > 0) {
if (props.setSeat == false) {
@ -406,8 +319,8 @@ const candidateToPlacement = async () => {
router.go(-1);
});
})
.onCancel(() => {})
.onDismiss(() => {});
.onCancel(() => { })
.onDismiss(() => { });
};
const uploadDataSeat = async () => {
@ -486,7 +399,7 @@ const downloadFileDetail = async () => {
};
const checkCandidates = async () => {
var _selected = [];
var _selected: any[] = [];
selected.value.map((r: any) => {
_selected.push(r.id.toString());
});
@ -568,6 +481,10 @@ const resetFilter = () => {
// reset X
emit("update:inputfilter", "");
filterRef.value.focus();
// clear keyword & get new data
props.changePage(1, props.pageSize);
currentPage.value = 1
};
const downloadFileDashboard = async () => {
@ -633,11 +550,14 @@ const clickCandidateList = async () => {
.icon-color {
color: #4154b3;
}
.custom-header-table {
max-height: 64vh;
.q-table tr:nth-child(odd) td {
background: white;
}
.q-table tr:nth-child(even) td {
background: #f8f8f8;
}
@ -650,11 +570,13 @@ const clickCandidateList = async () => {
position: sticky;
z-index: 1;
}
/* this will be the loading indicator */
.q-table thead tr:last-child th {
/* height of all previous header rows */
top: 48px;
}
.q-table thead tr:first-child th {
top: 0;
}

View file

@ -1,35 +1,16 @@
<template>
<div class="toptitle text-dark col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.go(-1)"
/>
<q-btn icon="mdi-arrow-left" unelevated round dense flat color="primary" class="q-mr-sm" @click="router.go(-1)" />
{{ name }}
{{
`ครั้งที่${round == null ? "" : round}/${
yearly == null ? "" : yearly + 543
}`
`ครั้งที่${round == null ? "" : round}/${yearly == null ? "" : yearly + 543
}`
}}
<q-space />
<q-btn
@click="visible = !visible"
dense
round
size="13px"
:style="
visible == false
<q-btn @click="visible = !visible" dense round size="13px" :style="visible == false
? 'transform: rotate(90deg);transition-duration: 0.8s;'
: 'transform: rotate(0);transition-duration: 0.8s;'
"
icon="mdi-pin"
flat
></q-btn>
" icon="mdi-pin" flat></q-btn>
</div>
<q-slide-transition>
<q-card class="row col-12 q-mb-sm" v-show="visible">
@ -39,23 +20,16 @@
<div class="col-12 row">
<div class="col-12">
<div class="row col-12 q-col-gutter-sm fit">
<div
style="width: 25%"
v-for="(num, index) in dataNum"
:key="index"
>
<div style="width: 25%" v-for="(num, index) in dataNum" :key="index">
<q-card bordered flat class="row fit cardNum items-center">
<div class="col-12 row items-center q-pa-sm">
<div
:class="
'col-12 text-h5 text-weight-bold text-' +
`${num.color}`
"
>
<div :class="'col-12 text-h5 text-weight-bold text-' +
`${num.color}`
">
{{
num.count != null
? num.count.toLocaleString("en-US")
: ""
? num.count.toLocaleString("en-US")
: ""
}}
</div>
<div class="col-12 text-dark ellipsis">
@ -72,53 +46,27 @@
</q-card>
</q-slide-transition>
<q-card flat bordered class="col-12 q-pt-sm">
<TableCandidate
style="max-height: 80vh"
:rows="rows"
:columns="columns"
:filter="filter"
:visible-columns="visibleColumns"
v-model:inputfilter="filter"
v-model:inputvisible="visibleColumns"
v-model:inputvisibleFilter="status"
v-model:optionsFilter="optionsStatus"
:pagination="initialPagination"
:nornmalData="true"
:paging="true"
:titleText="''"
:statusPayment="statusPayment"
:setSeat="setSeat"
:fetchData="fetchDataCom"
:history="true"
>
<TableCandidate style="max-height: 80vh" :rows="rows" :columns="columns" :filter="filter"
:visible-columns="visibleColumns" v-model:inputfilter="filter" v-model:inputvisible="visibleColumns"
v-model:inputvisibleFilter="status" v-model:optionsFilter="optionsStatus"
:nornmalData="true" :paging="true" :titleText="''" :statusPayment="statusPayment" :setSeat="setSeat"
:fetchData="fetchDataCom" :history="true" :page-size="page_size" :total="total" :page="page" :changePage="changePage" :max-page="maxPage">
<template #columns="props">
<q-tr :props="props" class="cursor-pointer">
<q-td auto-width>
<q-checkbox v-model="props.selected" />
</q-td>
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
@click="viewDetail(props.row.id, props.row.status)"
>
<q-td v-for="col in props.cols" :key="col.name" :props="props"
@click="viewDetail(props.row.id, props.row.status)">
<div v-if="col.name == 'no'" class="table_ellipsis">
{{ props.rowIndex + 1 }}
</div>
<div v-else-if="col.name == 'fullname'">
<div class="row col-12 items-center">
<img
v-if="props.row.avatar == ''"
src="@/assets/avatar_user.jpg"
class="q-mr-sm col-4"
style="width: 28px; height: 28px; border-radius: 50%"
/>
<img
v-else
:src="props.row.avatar"
class="q-mr-sm col-4"
style="width: 28px; height: 28px; border-radius: 50%"
/>
<img v-if="props.row.avatar == ''" src="@/assets/avatar_user.jpg" class="q-mr-sm col-4"
style="width: 28px; height: 28px; border-radius: 50%" />
<img v-else :src="props.row.avatar" class="q-mr-sm col-4"
style="width: 28px; height: 28px; border-radius: 50%" />
<div class="col-4">
<div class="text-weight-medium">
{{ props.row.fullname }}
@ -151,17 +99,13 @@
</div>
</div>
</div>
<div
v-else-if="col.name == 'status'"
:class="
props.row.status == 'checkRegister' ||
<div v-else-if="col.name == 'status'" :class="props.row.status == 'checkRegister' ||
props.row.status == 'checkPayment' ||
props.row.status == 'checkSeat' ||
props.row.status == 'checkPoint'
? 'text-blue'
: ''
"
>
? 'text-blue'
: ''
">
{{ statusCandidate(props.row.status) }}
</div>
<div v-else-if="col.name == 'registerDate'" class="table_ellipsis">
@ -172,16 +116,8 @@
</div>
</q-td>
<q-td auto-width>
<q-btn
color="primary"
flat
dense
round
size="14px"
icon="mdi-file-chart-outline"
v-if="props.row.status == 'done'"
@click="clickPointRow(props.row)"
>
<q-btn color="primary" flat dense round size="14px" icon="mdi-file-chart-outline"
v-if="props.row.status == 'done'" @click="clickPointRow(props.row)">
<q-tooltip>ผลสอบ</q-tooltip>
</q-btn>
</q-td>
@ -194,14 +130,7 @@
<q-card-section class="row items-center q-py-sm">
<div class="text-bold">ใบทานสอบขอม</div>
<q-space />
<q-btn
icon="close"
unelevated
round
dense
v-close-popup
style="color: #ff8080; background-color: #ffdede"
/>
<q-btn icon="close" unelevated round dense v-close-popup style="color: #ff8080; background-color: #ffdede" />
</q-card-section>
<q-separator />
<q-card-section class="row items-center">
@ -253,9 +182,6 @@ const visible = ref(true); //เปิดปิด card สรุปข้อม
const dataNum = ref<DataNumObject[]>([]); //
const rows = ref<any>([]);
const checkProfile = ref<any>([]);
const initialPagination = ref<Pagination>({
rowsPerPage: 0,
});
const visibleColumns = ref<String[]>([
// "check",
"no",
@ -467,12 +393,26 @@ const fetchDataCom = async () => {
await fetchData();
};
const fetchData = async () => {
showLoader();
// paging
const page = ref<number>(1)
const page_size = ref<number>(5)
const total = ref<number>(0)
const maxPage = ref<number>(1)
async function changePage(pageVal: number, pageSizeVal: number, loading: boolean = false) {
page.value = await pageVal
page_size.value = await pageSizeVal
fetchData(loading)
}
const fetchData = async (loading: boolean = true) => {
loading === true ?? showLoader()
await http
.get(config.API.candidateOfPeriodExam(status.value, examId.value))
.get(config.API.candidateOfPeriodExam(status.value, examId.value) + `?page=${page.value}&pageSize=${page_size.value}&keyword=${filter.value}`)
.then((res) => {
const data = res.data.result;
total.value = data.total
maxPage.value = Math.ceil(data.total / page_size.value)
rows.value = [];
data.data.map((r: any) => {
rows.value.push({
@ -499,7 +439,7 @@ const fetchData = async () => {
messageError($q, e);
})
.finally(() => {
hideLoader();
loading === true ?? hideLoader();
});
};