hrms-mgt/src/modules/14_KPI/views/report.vue

694 lines
20 KiB
Vue
Raw Normal View History

2024-06-13 11:43:38 +07:00
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
import { VuePDF, usePDF } from "@tato30/vue-pdf";
import config from "@/app.config";
import http from "@/plugins/http";
import axios from "axios";
import genReport from "@/plugins/genreport";
2024-06-13 11:43:38 +07:00
2024-06-25 16:28:33 +07:00
import type { DataOption } from "@/modules/14_KPI/interface/index/Main";
import type { QTableProps } from "quasar";
2024-06-13 11:43:38 +07:00
import { useCounterMixin } from "@/stores/mixin";
2024-06-25 16:28:33 +07:00
import DialogHeader from "@/components/DialogHeader.vue";
2024-06-13 11:43:38 +07:00
const $q = useQuasar();
const { showLoader, hideLoader, messageError, date2Thai, dialogConfirm } =
useCounterMixin();
const year = ref<number | null>(new Date().getFullYear());
const round = ref<string>("");
const organization = ref<string>("");
const roundOp = ref<DataOption[]>([]);
const organizationOpsMain = ref<DataOption[]>([]);
const organizationOps = ref<DataOption[]>([]);
2024-06-19 15:51:15 +07:00
const typeReport = ref<string>("");
const listReportMain = ref<DataOption[]>([
{
2024-06-25 16:28:33 +07:00
id: "KPI1",
2024-06-20 09:45:58 +07:00
name: "รายงานสรุปผลการประเมินผลการปฏิบัติราชการระดับบุคคล แสดงจำนวนผู้มีผลการประเมินระดับต่างๆ ในแต่ละรอบการประเมินรายหน่วยงาน/ส่วนราชการ",
2024-06-19 15:51:15 +07:00
},
{
2024-06-25 16:28:33 +07:00
id: "KPI2",
2024-06-20 09:45:58 +07:00
name: "รายงานสรุปผลการประเมินผลการปฏิบัติราชการระดับบุคคล แสดงรายละเอียดผู้มีผลการประเมินระดับต่างๆ รายหน่วยงาน/ส่วนราชการ ",
2024-06-19 15:51:15 +07:00
},
{
2024-06-25 16:28:33 +07:00
id: "KPI3",
2024-06-20 09:45:58 +07:00
name: "รายงานสรุปผลการประเมินผลการปฏิบัติราชการระดับบุคคล แสดงรายละเอียดผลการประเมินของผู้ใต้บังคับบัญชา",
2024-06-19 15:51:15 +07:00
},
{
2024-06-25 16:28:33 +07:00
id: "KPI4",
2024-06-19 15:51:15 +07:00
name: "แบบสรุปผลการประเมินผลการปฏิบัติราชการระดับบุคคล (รายบุคคล)",
},
{
2024-06-25 16:28:33 +07:00
id: "KPI5",
2024-06-19 15:51:15 +07:00
name: "รายงานผลการประเมินผลการปฏิบัติราชการย้อนหลัง ๕ ปี",
},
{
2024-06-25 16:28:33 +07:00
id: "KPI6",
2024-06-19 15:51:15 +07:00
name: "รายงานผลการประเมินผลการปฏิบัติราชการย้อนหลัง ๓ ปี",
},
{
2024-06-25 16:28:33 +07:00
id: "KPI7",
2024-06-19 15:51:15 +07:00
name: "รายงานสรุปแผนพัฒนาการปฏิบัติราชการรายบุคคล",
},
{
2024-06-25 16:28:33 +07:00
id: "KPI8",
2024-06-19 15:51:15 +07:00
name: "รายงานแผนพัฒนาการปฏิบัติราชการรายบุคคล",
},
2024-06-20 09:45:58 +07:00
{
2024-06-25 16:28:33 +07:00
id: "KPI9",
2024-06-20 09:45:58 +07:00
name: "จัดทำประกาศผู้มีผลการปฏิบัติราชการระดับดีเด่นและดีมาก",
},
2024-06-19 15:51:15 +07:00
]);
const listReport = ref<DataOption[]>([]);
2024-06-13 11:43:38 +07:00
function fetchRoundOption() {
http
.get(
config.API.kpiPeriod +
`?page=${1}&pageSize=${10}&keyword=${""}&year=${year.value}`
)
.then(async (res) => {
const data = await res.data.result.data;
if (res.data.result.data.length > 0) {
const list = await data.map((e: any) => ({
id: e.id,
name:
e.durationKPI === "OCT"
? "รอบตุลาคม"
: e.durationKPI === "APR"
? "รอบเมษายน"
: "",
}));
roundOp.value = list;
} else {
roundOp.value = [];
round.value = "";
organization.value = "";
dataDownload.value = null;
pdfSrc.value = null;
2024-06-13 11:43:38 +07:00
}
})
.catch((err) => {
messageError($q, err);
});
}
function fetchActiveId() {
showLoader();
http
.get(config.API.activeOrganization)
.then((res) => {
const data = res.data.result;
fetchListOrg(data.activeId);
})
.catch((err) => {
messageError($q, err);
hideLoader();
});
}
function fetchListOrg(id: string) {
showLoader();
http
.get(config.API.orgByid(id))
.then(async (res) => {
const data = await res.data.result.map((item: any) => ({
id: item.orgTreeId,
name: item.orgName,
}));
organizationOpsMain.value = data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function fetchReport() {
2024-06-25 16:28:33 +07:00
showLoader();
const body = {
type: typeReport.value,
periodId: round.value,
root: organization.value,
// persanalId: persanalId.value,
};
http
.post(config.API.kpiReport(), body)
.then((res) => {
dataDownload.value = res.data.result;
page.value = 1;
genPDf(res.data.result);
})
.catch((err) => {
messageError($q, err);
hideLoader();
});
}
/**
* function เรยกไฟล PDF
* @param data อมลบญชนลา
*/
2024-06-19 15:51:15 +07:00
function genPDf(data: any) {
showLoader();
2024-06-19 15:51:15 +07:00
axios
.post(config.API.reportTemplate + `/docx`, data, {
headers: {
accept: "application/pdf",
"content-Type": "application/json",
},
responseType: "blob",
})
.then(async (res) => {
const blob = new Blob([res.data]);
const objectUrl = URL.createObjectURL(blob);
const pdfData = await usePDF(`${objectUrl}`);
showLoader();
setTimeout(() => {
pdfSrc.value = pdfData.pdf.value;
numOfPages.value = pdfData.pages.value;
hideLoader();
}, 1500);
})
.catch(async (e) => {
messageError($q, JSON.parse(await e.response.data.text()));
hideLoader();
});
}
2024-06-25 16:28:33 +07:00
function changOption(val: string) {
if (
val === "KPI1" ||
val === "KPI2" ||
val === "KPI3" ||
val === "KPI7" ||
val === "KPI9"
) {
persanalId.value = "";
if (round.value !== "" && organization.value !== "") {
fetchReport();
}
} else {
round.value = "";
organization.value = "";
}
}
2024-06-13 11:43:38 +07:00
2024-06-19 15:51:15 +07:00
function filterSelector(val: string, update: Function, type: string) {
switch (type) {
case "typereport":
update(() => {
listReport.value = listReportMain.value.filter(
(v: DataOption) => v.name.toLowerCase().indexOf(val) > -1
);
});
break;
case "organization":
update(() => {
organizationOps.value = organizationOpsMain.value.filter(
(v: DataOption) => v.name.toLowerCase().indexOf(val) > -1
);
});
break;
default:
break;
}
2024-06-13 11:43:38 +07:00
}
const splitterModel = ref(14);
const numOfPages = ref<number>(0);
const page = ref<number>(1);
const pdfSrc = ref<any>();
const dataDownload = ref<any>();
2024-06-13 11:43:38 +07:00
async function downloadReport(data: any, type: string) {
2024-06-20 09:45:58 +07:00
const name =
listReportMain.value.find((e) => e.id === typeReport.value)?.name ?? "";
var fileName = name;
genReport(data, fileName, type);
2024-06-13 11:43:38 +07:00
}
/** ไปหน้าต่อไปของรายงาน */
function nextPage() {
if (page.value < numOfPages.value) {
page.value++;
}
}
/** กลับหน้าก่อนหน้าของรายงาน */
function backPage() {
if (page.value !== 1) {
page.value--;
}
}
2024-06-25 16:28:33 +07:00
/*******/
const modal = ref<boolean>(false);
const persanalId = ref<string>("");
const filter = ref<string>("");
const rowsPerson = ref<any[]>([
{
id: "1",
citizenId: "12345678910123",
name: "tset,",
posNo: "1",
position: "ตำแหน่งในสายงาน",
posType: "ตำแหน่งประเภท",
posLevel: "ระดับ",
},
]);
const columns = ref<QTableProps["columns"]>([
{
name: "citizenId",
align: "left",
label: "เลขประจำตัวประชาชน",
sortable: false,
field: "citizenId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ-นามสกุล",
field: "name",
sortable: false,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posNo",
align: "left",
label: "ตำแหน่งเลขที่",
sortable: false,
field: "posNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: false,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posType",
align: "left",
label: "ตำแหน่งประเภท",
sortable: false,
field: "posType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevel",
align: "left",
label: "ระดับ",
sortable: false,
field: "posLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
function onClickModal() {
modal.value = !modal.value;
if ((modal.value = true)) {
fetchListPerson();
}
}
function fetchListPerson() {}
function onSelectPerson(id: string) {
persanalId.value = id;
modal.value = false;
fetchReport();
}
2024-06-13 11:43:38 +07:00
onMounted(() => {
fetchRoundOption();
fetchActiveId();
});
</script>
<template>
2024-06-19 15:51:15 +07:00
<div class="toptitle text-dark col-12 row items-center">รายงาน</div>
2024-06-13 11:43:38 +07:00
<q-card flat bordered>
2024-06-19 15:51:15 +07:00
<q-card-section class="q-gutter-y-sm">
2024-06-13 11:43:38 +07:00
<q-toolbar style="padding: 0">
<div class="row q-gutter-sm">
2024-06-19 15:51:15 +07:00
<q-select
style="min-width: 100px"
dense
hide-bottom-space
outlined
option-label="name"
option-value="id"
emit-value
map-options
v-model="typeReport"
:options="listReport"
label="รายงาน"
use-input
2024-06-25 16:28:33 +07:00
@update:model-value="changOption"
2024-06-19 15:51:15 +07:00
@filter="(inputValue: string,
doneFn: Function) => filterSelector(inputValue, doneFn ,'typereport')"
/>
</div>
<q-space />
<q-btn
flat
round
color="primary"
icon="download"
:disable="!dataDownload"
>
<q-menu>
<q-list style="min-width: 150px">
<q-item
clickable
v-close-popup
@click="downloadReport(dataDownload, 'pdf')"
>
<q-item-section avatar
><q-icon color="red" name="mdi-file-pdf"
/></q-item-section>
<q-item-section>ไฟล .PDF</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click="downloadReport(dataDownload, 'docx')"
>
<q-item-section avatar
><q-icon color="blue" name="mdi-file-word"
/></q-item-section>
<q-item-section>ไฟล .docx</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-toolbar>
<q-toolbar
class="q-pa-sm bg-grey-2"
style="padding: 0; border-radius: 5px"
v-if="typeReport"
>
<div
class="row q-gutter-sm"
v-if="
2024-06-25 16:28:33 +07:00
typeReport === 'KPI1' ||
typeReport === 'KPI2' ||
typeReport === 'KPI3' ||
typeReport === 'KPI7' ||
typeReport === 'KPI9'
2024-06-19 15:51:15 +07:00
"
>
2024-06-13 11:43:38 +07:00
<datepicker
menu-class-name="modalfix"
v-model="year"
style="width: 150px"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
@update:model-value="fetchRoundOption()"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
outlined
hide-bottom-space
:model-value="!!year ? year + 543 : null"
:label="`${'ปีงบประมาณ'}`"
2024-06-19 15:51:15 +07:00
class="bg-white"
2024-06-13 11:43:38 +07:00
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
<q-select
2024-06-19 15:51:15 +07:00
class="bg-white"
2024-06-13 11:43:38 +07:00
v-model="round"
outlined
label="รอบการประเมิน"
dense
option-label="name"
option-value="id"
:options="roundOp"
style="min-width: 150px"
emit-value
map-options
:disable="roundOp.length === 0"
2024-06-25 16:28:33 +07:00
@update:model-value="changOption(typeReport)"
2024-06-13 11:43:38 +07:00
/>
<q-select
2024-06-19 15:51:15 +07:00
class="bg-white"
2024-06-13 11:43:38 +07:00
:disable="roundOp.length === 0"
style="min-width: 100px"
dense
hide-bottom-space
outlined
option-label="name"
option-value="id"
emit-value
2024-06-13 11:43:38 +07:00
map-options
v-model="organization"
:options="organizationOps"
label="หน่วยงาน"
use-input
2024-06-25 16:28:33 +07:00
@update:model-value="changOption(typeReport)"
2024-06-13 11:43:38 +07:00
@filter="(inputValue: string,
2024-06-19 15:51:15 +07:00
doneFn: Function) => filterSelector(inputValue, doneFn,'organization' )"
2024-06-13 11:43:38 +07:00
/>
</div>
2024-06-25 16:28:33 +07:00
<div class="q-pa-sm" v-else>
<q-btn color="primary" label="เลือกรายชื่อ" @click="onClickModal" />
<!-- <q-select
2024-06-19 15:51:15 +07:00
class="bg-white"
style="width: 200px"
dense
hide-bottom-space
outlined
option-label="name"
option-value="id"
emit-value
map-options
v-model="searchField"
:options="typeFilter"
label="ค้นหาจาก"
/>
2024-06-13 11:43:38 +07:00
2024-06-19 15:51:15 +07:00
<q-input
class="bg-white"
v-model="search"
outlined
clearable
hide-bottom-space
dense
label="คำค้น"
style="width: 350px"
>
<template v-slot:after>
<q-btn
color="primary"
icon="search"
label="ค้นหา"
class="full-width q-py-sm q-px-md"
2024-06-25 16:28:33 +07:00
@click="fetchReport"
2024-06-13 11:43:38 +07:00
>
2024-06-19 15:51:15 +07:00
</q-btn>
</template>
2024-06-25 16:28:33 +07:00
</q-input> -->
2024-06-19 15:51:15 +07:00
</div>
2024-06-13 11:43:38 +07:00
</q-toolbar>
<q-splitter
v-model="splitterModel"
horizontal
style="
2024-06-19 15:51:15 +07:00
height: 70vh;
2024-06-13 11:43:38 +07:00
border: 1px solid rgb(210, 210, 210);
border-radius: 5px;
"
before-class="overflow-hidden disable"
separator-class="bg-white disabled"
>
<template v-slot:before v-if="pdfSrc">
2024-06-13 11:43:38 +07:00
<div class="q-px-sm">
<div class="row items-start items-center">
<div class="col">
<q-btn
padding="xs"
icon="mdi-chevron-left"
color="grey-2"
text-color="grey-5"
size="md"
class="my-auto"
@click="backPage"
:disable="page == 1"
/>
</div>
<div class="col-12 col-md-auto">
<div class="q-pa-md flex">
หนาท {{ page }} จาก {{ numOfPages }}
</div>
</div>
<div class="col text-right">
<q-btn
padding="xs"
icon="mdi-chevron-right"
color="grey-2"
text-color="grey-5"
size="md"
@click="nextPage"
:disable="page === numOfPages"
/>
</div>
</div>
</div>
</template>
<template v-slot:after v-if="pdfSrc">
2024-06-13 11:43:38 +07:00
<div class="q-pa-md">
<VuePDF ref="vuePDFRef" :pdf="pdfSrc" :page="page" fit-parent />
</div>
</template>
<template v-slot:default v-if="pdfSrc">
2024-06-13 11:43:38 +07:00
<div class="q-pa-md">
<div class="row items-start items-center">
<div class="col">
<q-btn
padding="xs"
icon="mdi-chevron-left"
color="grey-2"
text-color="grey-5"
size="md"
class="my-auto"
@click="backPage"
:disable="page == 1"
/>
</div>
<div class="col-12 col-md-auto">
<div class="q-pa-md flex">
หนาท {{ page }} จาก {{ numOfPages }}
</div>
</div>
<div class="col text-right">
<q-btn
padding="xs"
icon="mdi-chevron-right"
color="grey-2"
text-color="grey-5"
size="md"
@click="nextPage"
:disable="page === numOfPages"
/>
</div>
</div>
</div>
</template>
</q-splitter>
</q-card-section>
</q-card>
2024-06-25 16:28:33 +07:00
<q-dialog v-model="modal" persistent>
<q-card style="width: 900px; max-width: 80vw">
<DialogHeader :tittle="'เลือกราชชื่อ'" :close="onClickModal" />
<q-separator />
<q-card-section class="q-col-gutter-sm">
<div class="col-12">
<q-input outlined dense v-model="filter" label="ค้นหา">
<template v-slot:append>
<q-icon name="search" color="grey-5" />
</template>
</q-input>
</div>
<div class="col-12">
<d-table
ref="table"
:columns="columns"
:rows="rowsPerson"
:paging="true"
row-key="id"
flat
bordered
dense
:rows-per-page-options="[10, 25, 50, 100]"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-tr auto-width />
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
<q-td>
<q-btn
outline
color="primary"
label="เลือก"
@click="onSelectPerson(props.row.id)"
/>
</q-td>
</q-tr>
</template>
<!-- <template v-slot:pagination="scope">
<q-pagination
v-model="reqMaster.page"
active-color="primary"
color="dark"
:max="totalPage"
:max-pages="5"
size="sm"
boundary-links
direction-links
></q-pagination>
</template> -->
</d-table>
</div>
</q-card-section>
</q-card>
</q-dialog>
</template>
2024-06-13 11:43:38 +07:00
<style scoped></style>