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

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

View file

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

View file

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