fix(KPI):sort

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-10-02 16:27:36 +07:00
parent 8287e4e3c1
commit a97775e66a
5 changed files with 100 additions and 253 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, watch } from "vue"; import { onMounted, ref } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
@ -8,6 +8,7 @@ import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/14_KPI/store"; import { useKpiDataStore } from "@/modules/14_KPI/store";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
import { calculateFiscalYear } from "@/utils/function"; import { calculateFiscalYear } from "@/utils/function";
import { usePagination } from "@/composables/usePagination";
/** importType*/ /** importType*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
@ -24,18 +25,13 @@ import DialogIndividual from "@/modules/14_KPI/components/results/dialogIndividu
const $q = useQuasar(); const $q = useQuasar();
const { showLoader, messageError, hideLoader } = useCounterMixin(); const { showLoader, messageError, hideLoader } = useCounterMixin();
const store = useKpiDataStore(); const store = useKpiDataStore();
const { pagination, params, onRequest } = usePagination("", fetcDataList);
/** props*/ /** props*/
const tab = defineModel<string>("tab", { required: true }); const tab = defineModel<string>("tab", { required: true });
/** /** ตัวแปร*/
* วแปร
*/
const rows = ref<ResDevelopment[]>([]); // const rows = ref<ResDevelopment[]>([]); //
const page = ref<number>(1);
const pageSize = ref<number>(10);
const maxPage = ref<number>(1);
const total = ref<number>(1);
const keyword = ref<string>(""); const keyword = ref<string>("");
const modalDetail = ref<boolean>(false); const modalDetail = ref<boolean>(false);
const devId = ref<string>(""); const devId = ref<string>("");
@ -52,11 +48,11 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
{ {
name: "fullName", name: "firstname",
align: "left", align: "left",
label: "ชื่อ-นามสกุล", label: "ชื่อ-นามสกุล",
sortable: true, sortable: true,
field: "fullName", field: "firstname",
format: (val, row) => { format: (val, row) => {
return `${row.prefix ?? ""}${row.firstname ?? ""} ${row.lastname ?? ""}`; return `${row.prefix ?? ""}${row.firstname ?? ""} ${row.lastname ?? ""}`;
}, },
@ -120,7 +116,7 @@ const columns = ref<QTableProps["columns"]>([
]); ]);
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"no", "no",
"fullName", "firstname",
"name", "name",
"organization", "organization",
"position", "position",
@ -128,10 +124,6 @@ const visibleColumns = ref<string[]>([
"posLevelName", "posLevelName",
"root", "root",
]); ]);
const pagination = ref({
page: page.value,
rowsPerPage: pageSize.value,
});
/** ตัวแปร*/ /** ตัวแปร*/
const year = ref<number | null>(calculateFiscalYear(new Date())); // const year = ref<number | null>(calculateFiscalYear(new Date())); //
@ -142,19 +134,18 @@ async function fetcDataList() {
showLoader(); showLoader();
await http await http
.post(config.API.achievementDev, { .post(config.API.achievementDev, {
page: page.value, ...params.value,
pageSize: pageSize.value,
keyword: keyword.value.trim(), keyword: keyword.value.trim(),
kpiPeriodId: store.formQuery.round ? store.formQuery.round : "", kpiPeriodId: store.formQuery.round ? store.formQuery.round : "",
}) })
.then(async (res) => { .then(async (res) => {
const data = await res.data.result; const result = await res.data.result;
rows.value = data.data; pagination.value.rowsNumber = result.total;
total.value = data.total; rows.value = result.data;
maxPage.value = Math.ceil(total.value / pageSize.value);
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
rows.value = [];
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();
@ -201,13 +192,13 @@ async function fetchRoundOption() {
/** function เปลี่ยนรอบการประเมิน และ เรียกข้อมูลรายการแผนพัฒนาการปฏิบัติราชการรายบุคคลย้อนหลัง*/ /** function เปลี่ยนรอบการประเมิน และ เรียกข้อมูลรายการแผนพัฒนาการปฏิบัติราชการรายบุคคลย้อนหลัง*/
function changRound() { function changRound() {
store.formQuery.page = 1; pagination.value.page = 1;
fetcDataList(); fetcDataList();
} }
/** ค้นหาข้อมูล*/ /** ค้นหาข้อมูล*/
function onSearchData() { function onSearchData() {
page.value = 1; pagination.value.page = 1;
fetcDataList(); fetcDataList();
} }
@ -220,12 +211,6 @@ function onClickView(id: string) {
devId.value = id; devId.value = id;
} }
/** ทำงานเมื่อมีการเปลี่ยนแถวต่อหน้า*/
watch(pagination, () => {
page.value = 1;
pageSize.value = pagination.value.rowsPerPage;
});
/** HookLifecycle*/ /** HookLifecycle*/
onMounted(async () => { onMounted(async () => {
store.formQuery.round = ""; store.formQuery.round = "";
@ -313,14 +298,15 @@ onMounted(async () => {
style="min-width: 140px" style="min-width: 140px"
/> />
</div> </div>
<d-table <p-table
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
row-key="id" row-key="id"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
v-model:pagination="pagination"
:paging="true" :paging="true"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
@request="onRequest"
v-model:pagination="pagination"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -355,7 +341,7 @@ onMounted(async () => {
</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'">
{{ (page - 1) * pageSize + props.rowIndex + 1 }} {{ props.rowIndex + 1 }}
</div> </div>
<div <div
v-else-if="col.name == 'organization'" v-else-if="col.name == 'organization'"
@ -370,21 +356,7 @@ onMounted(async () => {
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> </p-table>
งหมด {{ total }} รายการ
<q-pagination
v-model="page"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetcDataList()"
></q-pagination>
</template>
</d-table>
</q-card-section> </q-card-section>
<DialogIndividual v-model:devId="devId" v-model:modal="modalDetail" /> <DialogIndividual v-model:devId="devId" v-model:modal="modalDetail" />

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, watch } from "vue"; import { onMounted, ref } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
@ -27,21 +27,19 @@ const {
hideLoader, hideLoader,
date2Thai, date2Thai,
} = useCounterMixin(); } = useCounterMixin();
const { convertResults, convertStatus } = useKpiDataStore(); const { convertResults } = useKpiDataStore();
const store = useKpiDataStore(); const store = useKpiDataStore();
/** props*/ /** props*/
const tab = defineModel<string>("tab", { required: true }); const tab = defineModel<string>("tab", { required: true });
const rows = defineModel<ResResults[]>("row", { required: true }); const rows = defineModel<ResResults[]>("row", { required: true });
const page = defineModel<number>("page", { required: true });
const pageSize = defineModel<number>("pageSize", { required: true });
const maxPage = defineModel<number>("maxPage", { required: true });
const total = defineModel<number>("total", { required: true });
const keyword = defineModel<string>("keyword", { required: true }); const keyword = defineModel<string>("keyword", { required: true });
const result = defineModel<string>("result", { required: true }); const result = defineModel<string>("result", { required: true });
const pagination = defineModel<any>("pagination", { required: true });
const porps = defineProps({ const props = defineProps({
fetchData: { type: Function, required: true }, // function fetchData: { type: Function, required: true }, // function
onRequest: { type: Function, required: true },
}); });
/** Table*/ /** Table*/
@ -57,11 +55,11 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
{ {
name: "fullName", name: "firstname",
align: "left", align: "left",
label: "ผู้รับการประเมิน", label: "ผู้รับการประเมิน",
sortable: true, sortable: true,
field: "fullName", field: "firstname",
format: (val, row) => { format: (val, row) => {
return `${row.prefix ?? ""}${row.firstname ?? ""} ${row.lastname ?? ""}`; return `${row.prefix ?? ""}${row.firstname ?? ""} ${row.lastname ?? ""}`;
}, },
@ -96,7 +94,7 @@ const columns = ref<QTableProps["columns"]>([
name: "evaluationResults", name: "evaluationResults",
align: "left", align: "left",
label: "ผลการประเมิน", label: "ผลการประเมิน",
sortable: true, sortable: false,
field: "evaluationResults", field: "evaluationResults",
format(val, row) { format(val, row) {
return convertResults(val); return convertResults(val);
@ -152,7 +150,7 @@ const columns = ref<QTableProps["columns"]>([
]); ]);
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"no", "no",
"fullName", "firstname",
"createdAt", "createdAt",
// "evaluationStatus", // "evaluationStatus",
"evaluationResults", "evaluationResults",
@ -162,10 +160,6 @@ const visibleColumns = ref<string[]>([
"posLevelName", "posLevelName",
"root", "root",
]); ]);
const pagination = ref({
page: page.value,
rowsPerPage: pageSize.value,
});
/** ตัวแปร*/ /** ตัวแปร*/
const year = ref<number | null>(calculateFiscalYear(new Date())); // const year = ref<number | null>(calculateFiscalYear(new Date())); //
@ -184,7 +178,7 @@ function onAnnounce() {
id: ids, id: ids,
}) })
.then(async () => { .then(async () => {
await porps.fetchData(); await props.fetchData();
await success($q, "ประกาศผลสำเร็จ"); await success($q, "ประกาศผลสำเร็จ");
selected.value = []; selected.value = [];
}) })
@ -223,7 +217,7 @@ async function fetchRoundOption() {
roundOp.value = list; roundOp.value = list;
store.formQuery.round = list[0].id; store.formQuery.round = list[0].id;
await porps.fetchData(); await props.fetchData();
} else { } else {
roundOp.value = []; roundOp.value = [];
store.formQuery.round = ""; store.formQuery.round = "";
@ -239,15 +233,15 @@ async function fetchRoundOption() {
} }
/** function เปลี่ยนรอบการประเมิน และ เรียกข้อมูลรายการแผนพัฒนาการปฏิบัติราชการรายบุคคลย้อนหลัง*/ /** function เปลี่ยนรอบการประเมิน และ เรียกข้อมูลรายการแผนพัฒนาการปฏิบัติราชการรายบุคคลย้อนหลัง*/
function changRound() { function changeRound() {
store.formQuery.page = 1; pagination.value.page = 1;
porps.fetchData(); props.fetchData();
} }
/** ค้นหาข้อมูล*/ /** ค้นหาข้อมูล*/
function onSearchData() { function onSearchData() {
page.value = 1; pagination.value.page = 1;
porps.fetchData(); props.fetchData();
} }
/** /**
@ -271,13 +265,6 @@ function filterSelector(val: string, update: Function, refData: string) {
} }
} }
/** ทำงานเมื่อมีการเปลี่ยนแถวต่อหน้า*/
watch(pagination, () => {
page.value = 1;
pageSize.value = pagination.value.rowsPerPage;
});
/** ทำงานเมื่อมีการเปลี่ยนแถวต่อหน้า*/
onMounted(async () => { onMounted(async () => {
store.formQuery.round = ""; store.formQuery.round = "";
await fetchRoundOption(); await fetchRoundOption();
@ -366,7 +353,7 @@ onMounted(async () => {
style="min-width: 150px" style="min-width: 150px"
emit-value emit-value
map-options map-options
@update:model-value="changRound" @update:model-value="changeRound"
/> />
</div> </div>
@ -409,16 +396,17 @@ onMounted(async () => {
</div> </div>
<div class="col-12"> <div class="col-12">
<d-table <p-table
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
row-key="id" row-key="id"
:selection="tab === 'COMPLETE' ? 'multiple' : null" :selection="tab === 'COMPLETE' ? 'multiple' : null"
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"
:paging="true" :paging="true"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
v-model:pagination="pagination"
@request="props.onRequest"
> >
<template v-slot:header-selection="scope" v-if="tab === 'COMPLETE'"> <template v-slot:header-selection="scope" v-if="tab === 'COMPLETE'">
<q-checkbox <q-checkbox
@ -444,7 +432,7 @@ onMounted(async () => {
</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'">
{{ (page - 1) * pageSize + props.rowIndex + 1 }} {{ props.rowIndex + 1 }}
</div> </div>
<div <div
v-else-if="col.name == 'organization'" v-else-if="col.name == 'organization'"
@ -459,21 +447,7 @@ onMounted(async () => {
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> </p-table>
งหมด {{ total }} รายการ
<q-pagination
v-model="page"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="porps.fetchData()"
></q-pagination>
</template>
</d-table>
</div> </div>
</div> </div>
</q-card-section> </q-card-section>

View file

@ -7,16 +7,11 @@ import { checkPermission } from "@/utils/permissions";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { calculateFiscalYear } from "@/utils/function"; import { calculateFiscalYear } from "@/utils/function";
import { usePagination } from "@/composables/usePagination";
/** importType*/ /** importType*/
import type { import type { DataOption } from "@/modules/14_KPI/interface/index/Main";
DataOption, import type { FormRound } from "@/modules/14_KPI/interface/request/Main";
NewPagination,
} from "@/modules/14_KPI/interface/index/Main";
import type {
FormQueryRound,
FormRound,
} from "@/modules/14_KPI/interface/request/Main";
import type { ResRound } from "@/modules/14_KPI/interface/response/Main"; import type { ResRound } from "@/modules/14_KPI/interface/response/Main";
/** importComponents*/ /** importComponents*/
@ -33,11 +28,13 @@ const {
dialogConfirm, dialogConfirm,
dialogRemove, dialogRemove,
} = useCounterMixin(); } = useCounterMixin();
const { pagination, params, onRequest, checkAndUpdatePage } = usePagination(
"",
fetchList
);
/** Table*/ /** Table*/
const rows = ref<ResRound[]>([]); // const rows = ref<ResRound[]>([]); //
const totalList = ref<number>(1); //
const total = ref<number>(0); //
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "year", name: "year",
@ -99,16 +96,12 @@ const visibleColumns = ref<string[]>([
"isActive", "isActive",
]); ]);
//
const formQuery = reactive<FormQueryRound>({
page: 1, //
pageSize: 10, //
year: calculateFiscalYear(new Date()), //
keyword: "",
});
const modalDialog = ref<boolean>(false); //modal const modalDialog = ref<boolean>(false); //modal
const isStatusEdit = ref<boolean>(false); //status const isStatusEdit = ref<boolean>(false); //status
const fiscalyear = ref<number>(calculateFiscalYear(new Date())); //
const keyword = ref<string>(""); //
// //
const formData = reactive<FormRound>({ const formData = reactive<FormRound>({
durationKPI: "", // durationKPI: "", //
@ -129,15 +122,17 @@ const roundOp = ref<DataOption[]>([
async function fetchList() { async function fetchList() {
showLoader(); showLoader();
await http await http
.get( .get(config.API.kpiPeriod + "/admin", {
config.API.kpiPeriod + params: {
`/admin?page=${formQuery.page}&pageSize=${formQuery.pageSize}&keyword=${formQuery.keyword}&year=${formQuery.year}` ...params.value,
) year: fiscalyear.value,
keyword: keyword.value.trim(),
},
})
.then(async (res) => { .then(async (res) => {
const data = await res.data.result; const result = await res.data.result;
totalList.value = Math.ceil(data.total / formQuery.pageSize); pagination.value.rowsNumber = result.total;
total.value = data.total; rows.value = result.data;
rows.value = data.data;
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -289,6 +284,7 @@ function onDeleteRound(id: string) {
http http
.delete(config.API.kpiPeriodById(id)) .delete(config.API.kpiPeriodById(id))
.then(async () => { .then(async () => {
await checkAndUpdatePage(rows.value.length);
await fetchList(); await fetchList();
await success($q, "ลบข้อมูลสำเร็จ"); await success($q, "ลบข้อมูลสำเร็จ");
}) })
@ -312,29 +308,12 @@ function connvertName(val: string) {
return findData?.name; return findData?.name;
} }
/**
* งก updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: NewPagination) {
formQuery.page = 1;
formQuery.pageSize = newPagination.rowsPerPage;
}
/** function อัพเดทปีงบประมาณ และ fetch รายการรอบการประเมินผลการปฏิบัติหน้าที่ราชการ*/ /** function อัพเดทปีงบประมาณ และ fetch รายการรอบการประเมินผลการปฏิบัติหน้าที่ราชการ*/
function handleUpdateYear() { function handleUpdateYear() {
formQuery.page = 1; pagination.value.page = 1;
fetchList(); fetchList();
} }
/** callback function fetch รายการรอบการประเมินผลการปฏิบัติหน้าที่ราชการ เมือมีการเปลี่ยนแถวต่อหน้า*/
watch(
() => formQuery.pageSize,
() => {
fetchList();
}
);
/** callback function เช็ต วันเริ่มต้น และวันสิ้นสุด รอบการประเมินผลการปฏิบัติหน้าที่ราชการ*/ /** callback function เช็ต วันเริ่มต้น และวันสิ้นสุด รอบการประเมินผลการปฏิบัติหน้าที่ราชการ*/
watch( watch(
[() => formData.durationKPI, () => formData.year], [() => formData.durationKPI, () => formData.year],
@ -365,7 +344,7 @@ onMounted(async () => {
<div class="row q-col-gutter-sm"> <div class="row q-col-gutter-sm">
<div class="row col-12"> <div class="row col-12">
<datepicker <datepicker
v-model="formQuery.year" v-model="fiscalyear"
:locale="'th'" :locale="'th'"
autoApply autoApply
year-picker year-picker
@ -381,7 +360,7 @@ onMounted(async () => {
dense dense
outlined outlined
:model-value=" :model-value="
formQuery.year === 0 ? 'ทั้งหมด' : Number(formQuery.year) + 543 fiscalyear === 0 ? 'ทั้งหมด' : Number(fiscalyear) + 543
" "
:label="`${'ปีงบประมาณ'}`" :label="`${'ปีงบประมาณ'}`"
> >
@ -393,11 +372,11 @@ onMounted(async () => {
> >
</q-icon> </q-icon>
</template> </template>
<template v-if="formQuery.year" v-slot:append> <template v-if="fiscalyear" v-slot:append>
<q-icon <q-icon
name="cancel" name="cancel"
@click.stop.prevent=" @click.stop.prevent="
(formQuery.year = 0), (formQuery.page = 1), fetchList() (fiscalyear = 0), (pagination.page = 1), fetchList()
" "
class="cursor-pointer" class="cursor-pointer"
/> />
@ -435,7 +414,7 @@ onMounted(async () => {
</div> </div>
<div class="col-12"> <div class="col-12">
<d-table <p-table
for="table" for="table"
ref="table" ref="table"
:columns="columns" :columns="columns"
@ -447,7 +426,8 @@ onMounted(async () => {
class="custom-header-table" class="custom-header-table"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination" v-model:pagination="pagination"
@request="onRequest"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -493,21 +473,7 @@ onMounted(async () => {
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> </p-table>
งหมด {{ total }} รายการ
<q-pagination
v-model="formQuery.page"
active-color="primary"
color="dark"
:max="Number(totalList)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchList"
></q-pagination>
</template>
</d-table>
</div> </div>
</div> </div>
</q-card> </q-card>

View file

@ -7,6 +7,7 @@ import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/14_KPI/store"; import { useKpiDataStore } from "@/modules/14_KPI/store";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
import { calculateFiscalYear } from "@/utils/function"; import { calculateFiscalYear } from "@/utils/function";
import { usePagination } from "@/composables/usePagination";
import config from "@/app.config"; import config from "@/app.config";
import http from "@/plugins/http"; import http from "@/plugins/http";
@ -22,11 +23,10 @@ const $q = useQuasar();
const router = useRouter(); const router = useRouter();
const store = useKpiDataStore(); const store = useKpiDataStore();
const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin(); const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin();
const { pagination, params, onRequest } = usePagination("", fetchList);
const year = ref<number | null>(calculateFiscalYear(new Date())); // const year = ref<number | null>(calculateFiscalYear(new Date())); //
const formQuery = reactive({ const formQuery = reactive({
page: 1, //
pageSize: 10, //
status: "", status: "",
results: "", results: "",
}); });
@ -42,25 +42,23 @@ const rows = ref<any[]>([]); //รายการการประเมิน
const maxPage = ref<number>(1); // const maxPage = ref<number>(1); //
const totalList = ref<number>(0); // const totalList = ref<number>(0); //
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"name", "firstName",
"createdAt", "createdAt",
"evaluationStatus", "evaluationStatus",
"evaluationResults", "evaluationResults",
]); ]);
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "name", name: "firstName",
align: "left", align: "left",
label: "ผู้รับการประเมิน", label: "ผู้รับการประเมิน",
sortable: true, sortable: true,
field: "name", field: "firstName",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
format(val, row) { format(val, row) {
return `${row.prefix}${row.firstname} ${row.lastname}`; return `${row.prefix}${row.firstname} ${row.lastname}`;
}, },
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "createdAt", name: "createdAt",
@ -71,32 +69,26 @@ const columns = ref<QTableProps["columns"]>([
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
format: (v) => date2Thai(v, false, true), format: (v) => date2Thai(v, false, true),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "evaluationStatus", name: "evaluationStatus",
align: "left", align: "left",
label: "สถานะการประเมิน", label: "สถานะการประเมิน",
sortable: true, sortable: false,
field: "evaluationStatus", field: "evaluationStatus",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
format: (v) => store.convertStatus(v), format: (v) => store.convertStatus(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "evaluationResults", name: "evaluationResults",
align: "left", align: "left",
label: "ผลการประเมิน", label: "ผลการประเมิน",
sortable: true, sortable: false,
field: "evaluationResults", field: "evaluationResults",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
format: (v) => store.convertResults(v), format: (v) => store.convertResults(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
]); ]);
@ -142,8 +134,7 @@ async function fetchRoundOption() {
async function fetchList() { async function fetchList() {
showLoader(); showLoader();
const body = { const body = {
page: formQuery.page, ...params.value,
pageSize: formQuery.pageSize,
kpiPeriodId: store.formQuery.round, kpiPeriodId: store.formQuery.round,
keyword: store.formQuery.keyword.trim(), keyword: store.formQuery.keyword.trim(),
status: formQuery.status === "" ? undefined : formQuery.status, status: formQuery.status === "" ? undefined : formQuery.status,
@ -154,10 +145,9 @@ async function fetchList() {
await http await http
.post(config.API.kpiUserEvaluation + `/list`, body) .post(config.API.kpiUserEvaluation + `/list`, body)
.then(async (res) => { .then(async (res) => {
const data = await res.data.result; const result = await res.data.result;
maxPage.value = Math.ceil(data.total / formQuery.pageSize); pagination.value.rowsNumber = result.total;
totalList.value = data.total; rows.value = result.data;
rows.value = data.data;
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -173,7 +163,7 @@ async function fetchList() {
* แลวเรยกขอมลรายการการประเมนผลการปฏราชการระดบบคคลใหม * แลวเรยกขอมลรายการการประเมนผลการปฏราชการระดบบคคลใหม
*/ */
async function changRound() { async function changRound() {
formQuery.page = 1; pagination.value.page = 1;
await fetchList(); await fetchList();
} }
@ -195,22 +185,6 @@ function redirectViewDetailOnly(id: string) {
router.push(`KPI-list-detail/${id}`); router.push(`KPI-list-detail/${id}`);
} }
/** ฟังก์ชันเคลียข้อมูลค้นหาเป็นค้นหาจ้อมูลทั้งหมด*/
// function clearYear() {
// year.value = null;
// store.formQuery.round = "";
// roundOp.value = [];
// changRound();
// }
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: any) {
formQuery.pageSize = newPagination.rowsPerPage;
}
/** /**
* งกนคนหาขอมลในรายการตวเลอก * งกนคนหาขอมลในรายการตวเลอก
* @param val คำคนหา * @param val คำคนหา
@ -239,19 +213,6 @@ function filterSelector(val: string, update: Function, refData: string) {
} }
} }
/**
* การเปลยนแปลงของ formQuery.pageSize เมอมการเปลยนของแถวทงหมด
* จะกำหนด formQuery.page เปนหนาแรก
* แลวเรยกขอมลรายการการประเมนผลการปฏราชการระดบบคคลใหม
*/
watch(
() => formQuery.pageSize,
() => {
formQuery.page = 1;
fetchList();
}
);
/** Hook */ /** Hook */
onMounted(async () => { onMounted(async () => {
await fetchRoundOption(); await fetchRoundOption();
@ -374,7 +335,7 @@ onMounted(async () => {
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
outlined outlined
@update:model-value="(formQuery.page = 1), fetchList()" @update:model-value="(pagination.page = 1), fetchList()"
use-input use-input
@clear=" @clear="
(formQuery.status = ''), (statusOp = store.statusOptions) (formQuery.status = ''), (statusOp = store.statusOptions)
@ -409,7 +370,7 @@ onMounted(async () => {
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
outlined outlined
@update:model-value="(formQuery.page = 1), fetchList()" @update:model-value="(pagination.page = 1), fetchList()"
use-input use-input
@clear=" @clear="
(formQuery.results = ''), (resultOp = store.resultsOptions) (formQuery.results = ''), (resultOp = store.resultsOptions)
@ -433,7 +394,7 @@ onMounted(async () => {
</div> </div>
<div class="col-12"> <div class="col-12">
<d-table <p-table
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
@ -444,7 +405,8 @@ onMounted(async () => {
dense dense
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
@update:pagination="updatePagination" v-model:pagination="pagination"
@request="onRequest"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -490,21 +452,7 @@ onMounted(async () => {
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
<template v-slot:pagination="scope"> </p-table>
งหมด {{ totalList }} รายการ
<q-pagination
v-model="formQuery.page"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchList"
></q-pagination>
</template>
</d-table>
</div> </div>
</div> </div>
</q-card> </q-card>

View file

@ -4,6 +4,7 @@ import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/14_KPI/store"; import { useKpiDataStore } from "@/modules/14_KPI/store";
import { usePagination } from "@/composables/usePagination";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
@ -19,6 +20,7 @@ import TableIndividual from "@/modules/14_KPI/components/results/tableIndividual
const store = useKpiDataStore(); const store = useKpiDataStore();
const $q = useQuasar(); const $q = useQuasar();
const { messageError, showLoader, hideLoader } = useCounterMixin(); const { messageError, showLoader, hideLoader } = useCounterMixin();
const { pagination, params, onRequest } = usePagination("", fetcDataList);
const tab = ref<string>("COMPLETE"); const tab = ref<string>("COMPLETE");
const tabItems = ref<ItemsTab[]>([ const tabItems = ref<ItemsTab[]>([
@ -27,10 +29,6 @@ const tabItems = ref<ItemsTab[]>([
{ name: "IDP", label: "แผนพัฒนาการปฏิบัติราชการรายบุคคล" }, { name: "IDP", label: "แผนพัฒนาการปฏิบัติราชการรายบุคคล" },
]); ]);
const dataList = ref<ResResults[]>([]); // const dataList = ref<ResResults[]>([]); //
const page = ref<number>(1);
const pageSize = ref<number>(10);
const maxPage = ref<number>(1);
const total = ref<number>(1);
const keyword = ref<string>(""); const keyword = ref<string>("");
const result = ref<string>(""); const result = ref<string>("");
@ -40,17 +38,15 @@ async function fetcDataList() {
await http await http
.post(config.API.evaluationUser, { .post(config.API.evaluationUser, {
status: tab.value, status: tab.value,
page: page.value, ...params.value,
pageSize: pageSize.value,
keyword: keyword.value.trim(), keyword: keyword.value.trim(),
kpiPeriodId: store.formQuery.round ? store.formQuery.round : "", kpiPeriodId: store.formQuery.round ? store.formQuery.round : "",
results: result.value === "" ? undefined : result.value, results: result.value === "" ? undefined : result.value,
}) })
.then(async (res) => { .then(async (res) => {
const data = await res.data.result; const result = await res.data.result;
dataList.value = data.data; pagination.value.rowsNumber = result.total;
total.value = data.total; dataList.value = result.data;
maxPage.value = Math.ceil(total.value / pageSize.value);
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -62,16 +58,11 @@ async function fetcDataList() {
/** ทำงานเมื่อมีการเปลี่ยน Tab */ /** ทำงานเมื่อมีการเปลี่ยน Tab */
watch(tab, () => { watch(tab, () => {
page.value = 1; pagination.value.page = 1;
result.value = ""; result.value = "";
keyword.value = ""; keyword.value = "";
dataList.value = []; dataList.value = [];
}); });
/** ทำงานเมื่อมีการเปลี่ยนแถวต่อหน้า*/
watch(pageSize, () => {
fetcDataList();
});
</script> </script>
<template> <template>
@ -97,13 +88,11 @@ watch(pageSize, () => {
<TableResults <TableResults
:tab="tab" :tab="tab"
:row="dataList" :row="dataList"
v-model:page="page"
v-model:pageSize="pageSize"
v-model:maxPage="maxPage"
v-model:total="total"
v-model:keyword="keyword" v-model:keyword="keyword"
v-model:result="result" v-model:result="result"
v-model:pagination="pagination"
:fetchData="fetcDataList" :fetchData="fetcDataList"
:onRequest="onRequest"
/> />
</q-tab-panel> </q-tab-panel>
@ -111,13 +100,11 @@ watch(pageSize, () => {
<TableResults <TableResults
:tab="tab" :tab="tab"
:row="dataList" :row="dataList"
v-model:page="page"
v-model:pageSize="pageSize"
v-model:maxPage="maxPage"
v-model:total="total"
v-model:keyword="keyword" v-model:keyword="keyword"
v-model:result="result" v-model:result="result"
v-model:pagination="pagination"
:fetchData="fetcDataList" :fetchData="fetcDataList"
:onRequest="onRequest"
/> />
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="IDP" style="padding: 0px"> <q-tab-panel name="IDP" style="padding: 0px">