662 lines
21 KiB
Vue
662 lines
21 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted } from "vue";
|
|
import { useQuasar } from "quasar";
|
|
import { VuePDF, usePDF } from "@tato30/vue-pdf";
|
|
import axios from "axios";
|
|
|
|
import { useRoute } from "vue-router";
|
|
import { checkPermission } from "@/utils/permissions";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
import { useStructureTree } from "@/stores/structureTree";
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
import genReport from "@/plugins/genreport";
|
|
import genReportXLSX from "@/plugins/genreportxlsx";
|
|
|
|
import type { DataStructureTree } from "@/interface/main";
|
|
import type {
|
|
OptionData,
|
|
OptionDataList,
|
|
} from "@/modules/07_insignia/interface/index/Main";
|
|
|
|
import LoadView from "@/components/LoadView.vue";
|
|
|
|
const $q = useQuasar();
|
|
const route = useRoute();
|
|
const { fetchStructureTree } = useStructureTree();
|
|
const { messageError, showLoader, hideLoader } = useCounterMixin();
|
|
|
|
const employeeClass = ref<string>("officer");
|
|
const employeeClassOption = ref<OptionData[]>([
|
|
{ id: "officer", name: "ข้าราชการ กทม. สามัญ" },
|
|
{ id: "employee", name: "ลูกจ้างประจำ กทม." },
|
|
]);
|
|
|
|
const typeReport = ref<any>();
|
|
const optionReport = ref<OptionDataList[]>([
|
|
{
|
|
id: "1",
|
|
val: "report1",
|
|
name: "บัญชีรายชื่อข้าราชการผู้ขอพระราชทานเครื่องราชอิสริยาภรณ์",
|
|
},
|
|
{
|
|
id: "2",
|
|
val: "report2",
|
|
name: "บัญชีระดับผลการประเมินผลการปฏิบัติราชการในรอบ 5 ปี",
|
|
},
|
|
{ id: "3", val: "report3", name: "บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ 5 ปี" },
|
|
{
|
|
id: "4",
|
|
val: "report4",
|
|
name: "รายชื่อข้าราชการฯ ที่ได้รับ/ไม่ได้รับการจ่ายใบกำกับฯ",
|
|
},
|
|
{
|
|
id: "5",
|
|
val: "report5",
|
|
name: "รายงานสถิติการได้รับเครื่องราชอิสริยาภรณ์ข้าราชการฯ",
|
|
},
|
|
{
|
|
id: "6",
|
|
val: "report6",
|
|
name: "รายงานผลการจ่ายประกาศนียบัตรกำกับเครื่องราชอิสริยาภรณ์ แยกรายหน่วยงาน",
|
|
},
|
|
{
|
|
id: "7",
|
|
val: "report4",
|
|
name: "รายงานแสดงรายชื่อลูกจ้างประจำที่ได้รับ/ไม่ได้รับ การจ่ายใบกำกับฯ เครื่องราชอิสริยาภรณที่ได้รับพระราชทาน (ลูกจ้าง)",
|
|
},
|
|
]);
|
|
|
|
const roundId = ref<string>("");
|
|
const roundOtionMain = ref<any[]>([]);
|
|
const roundOtion = ref<any[]>([]);
|
|
|
|
/** tree*/
|
|
const filterTree = ref<string>("");
|
|
const nodeId = ref<string>("");
|
|
const nodeLevel = ref<number>(0);
|
|
const node = ref<DataStructureTree[]>([]);
|
|
const expanded = ref<string[]>([]);
|
|
|
|
const splitterModel = ref(14);
|
|
const numOfPages = ref<number>(0);
|
|
const page = ref<number>(1);
|
|
const pdfSrc = ref<any>();
|
|
|
|
const isLoadPDF = ref<boolean>(false);
|
|
|
|
async function fetchDataTree() {
|
|
node.value = await fetchStructureTree(route.meta.Key as string, true);
|
|
}
|
|
|
|
/** ฟังก์ชันคึงข้อมูลรอบการเสนอขอ*/
|
|
async function fecthlistRound() {
|
|
showLoader();
|
|
await http
|
|
.get(config.API.listRoundInsignia(), { params: { path: "REPORT" } })
|
|
.then((res: any) => {
|
|
roundOtionMain.value = res.data.result.map((e: any) => ({
|
|
id: e.period_id,
|
|
year: e.period_year,
|
|
name: e.period_name,
|
|
}));
|
|
roundOtion.value = roundOtionMain.value;
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
const roundId2 = ref<string>("");
|
|
const roundOtionMain2 = ref<any[]>([]);
|
|
const roundOtion2 = ref<any[]>([]);
|
|
/** ฟังก์ชันคึงข้อมูลรอบการเสนอขอ note*/
|
|
async function fecthlistRound2() {
|
|
showLoader();
|
|
await http
|
|
.get(config.API.noteround(), { params: { path: "RECORD" } })
|
|
.then((res: any) => {
|
|
roundOtionMain2.value = res.data.result.map((e: any) => ({
|
|
id: e.id,
|
|
year: e.year,
|
|
name: e.name,
|
|
}));
|
|
roundOtion2.value = roundOtionMain2.value;
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* function ค้นหาข้อมูลใน option
|
|
* @param val คำค้นหา
|
|
* @param update function
|
|
* @param name ชื่อ Selec
|
|
*/
|
|
function filterSelector(val: string, update: Function, name: string) {
|
|
update(() => {
|
|
const needle = val.toLowerCase();
|
|
if (name === "round") {
|
|
roundOtion.value = roundOtionMain.value.filter(
|
|
(v: OptionData) => v.name.toLowerCase().indexOf(needle) > -1
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* function เลือกหน่วยงาน
|
|
* @param id id หน่วยงาน
|
|
* @param level ระดับหน่วยงาน
|
|
*/
|
|
function onSelectedNode(id: string, level: number) {
|
|
nodeId.value = id;
|
|
nodeLevel.value = level;
|
|
onUpdateFilter();
|
|
}
|
|
|
|
const detailReport = ref<any>();
|
|
|
|
/**
|
|
* ฟังก์ชันโหลดไฟล์
|
|
* @param type ประเภทไฟล์
|
|
* @param download
|
|
*/
|
|
async function onUpdateFilter() {
|
|
if (
|
|
(employeeClass.value == "employee" && typeReport.value.id == "4") ||
|
|
(employeeClass.value == "officer" && typeReport.value.id == "7")
|
|
) {
|
|
typeReport.value =
|
|
employeeClass.value == "officer"
|
|
? {
|
|
id: "4",
|
|
val: "report4",
|
|
name: "รายชื่อข้าราชการฯ ที่ได้รับ/ไม่ได้รับการจ่ายใบกำกับฯ",
|
|
}
|
|
: {
|
|
id: "7",
|
|
val: "report4",
|
|
name: "รายงานแสดงรายชื่อลูกจ้างประจำที่ได้รับ/ไม่ได้รับ การจ่ายใบกำกับฯ เครื่องราชอิสริยาภรณที่ได้รับพระราชทาน (ลูกจ้าง)",
|
|
};
|
|
}
|
|
if (
|
|
(typeReport.value.val === "report1" ||
|
|
typeReport.value.val === "report2" ||
|
|
typeReport.value.val === "report3") &&
|
|
(roundId.value || roundId2.value) &&
|
|
nodeId.value
|
|
) {
|
|
isLoadPDF.value = true;
|
|
pdfSrc.value = undefined;
|
|
|
|
await http
|
|
.post(
|
|
config.API.reportInsigniaNew +
|
|
`/${typeReport.value.val}/${employeeClass.value}`,
|
|
{
|
|
roundId: roundId.value,
|
|
node: nodeLevel.value,
|
|
nodeId: nodeId.value,
|
|
}
|
|
)
|
|
.then(async (res) => {
|
|
const data = await res.data.result;
|
|
detailReport.value = data;
|
|
|
|
await fetchDocumentTemplate(data, "docx");
|
|
})
|
|
.catch(async (e) => {
|
|
messageError($q, JSON.parse(await e.response.data.text()));
|
|
})
|
|
.finally(() => {
|
|
isLoadPDF.value = false;
|
|
});
|
|
} else if (roundId2.value && nodeId.value) {
|
|
isLoadPDF.value = true;
|
|
pdfSrc.value = undefined;
|
|
|
|
await http
|
|
.post(
|
|
config.API.reportInsigniaNew +
|
|
`/${typeReport.value.val}/${employeeClass.value}`,
|
|
{
|
|
roundId: roundId2.value,
|
|
node: nodeLevel.value,
|
|
nodeId: nodeId.value,
|
|
}
|
|
)
|
|
.then(async (res) => {
|
|
const data = await res.data.result;
|
|
detailReport.value = data;
|
|
|
|
await fetchDocumentTemplate(data, "xlsx");
|
|
})
|
|
.catch(async (e) => {
|
|
messageError($q, JSON.parse(await e.response.data.text()));
|
|
})
|
|
.finally(() => {
|
|
isLoadPDF.value = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* function เรียกไฟล์ PDF
|
|
* @param data ข้อมูลบัญชีวันลา
|
|
*/
|
|
async function fetchDocumentTemplate(data: any, type: string = "docx") {
|
|
await axios
|
|
.post(`${config.API.reportTemplate}/${type}`, 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 = usePDF(`${objectUrl}`);
|
|
|
|
setTimeout(() => {
|
|
pdfSrc.value = pdfData.pdf.value;
|
|
numOfPages.value = pdfData.pages.value;
|
|
}, 1500);
|
|
})
|
|
.catch(async (e) => {
|
|
messageError($q, JSON.parse(await e.response.data.text()));
|
|
});
|
|
}
|
|
|
|
/** ไปหน้าต่อไปของรายงาน */
|
|
function nextPage() {
|
|
if (page.value < numOfPages.value) {
|
|
page.value++;
|
|
}
|
|
}
|
|
|
|
/** กลับหน้าก่อนหน้าของรายงาน */
|
|
function backPage() {
|
|
if (page.value !== 1) {
|
|
page.value--;
|
|
}
|
|
}
|
|
|
|
function downloadReport(type: string, download: "docx" | "" | "xlsx" = "") {
|
|
const fileName =
|
|
optionReport.value.find((e) => e.id === typeReport.value.id)?.name || "";
|
|
|
|
if (type === "xlsx" && download === "") {
|
|
genReportXLSX(detailReport.value, fileName, type);
|
|
} else if (type === "pdf" && download === "xlsx") {
|
|
genReportXLSX(detailReport.value, fileName, "pdf");
|
|
} else {
|
|
genReport(detailReport.value, fileName, type);
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
await Promise.all([fetchDataTree(), fecthlistRound(), fecthlistRound2()]);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="toptitle text-dark col-12 row items-center">
|
|
รายงานเครื่องราชอิสริยาภรณ์
|
|
</div>
|
|
|
|
<div class="q-pa-sm q-gutter-sm">
|
|
<q-card flat bordered class="col-12">
|
|
<div class="row q-col-gutter-sm q-pa-sm">
|
|
<div class="row col-12">
|
|
<q-select
|
|
outlined
|
|
dense
|
|
v-model="employeeClass"
|
|
:options="employeeClassOption"
|
|
label="สถานภาพ"
|
|
emit-value
|
|
map-options
|
|
option-label="name"
|
|
option-value="id"
|
|
style="width: 230px"
|
|
@update:model-value="onUpdateFilter"
|
|
>
|
|
</q-select>
|
|
|
|
<q-space />
|
|
<q-btn
|
|
flat
|
|
round
|
|
:loading="isLoadPDF"
|
|
:disable="!nodeId || !employeeClass || (!roundId && !roundId2)"
|
|
color="primary"
|
|
icon="download"
|
|
v-if="checkPermission($route)?.attrIsGet"
|
|
>
|
|
<q-menu>
|
|
<q-list style="min-width: 150px">
|
|
<q-item
|
|
clickable
|
|
v-close-popup
|
|
@click="
|
|
downloadReport(
|
|
'pdf',
|
|
typeReport.val != 'report1' ||
|
|
typeReport.val != 'report2' ||
|
|
typeReport.val != 'report3'
|
|
? 'xlsx'
|
|
: 'docx'
|
|
)
|
|
"
|
|
>
|
|
<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
|
|
v-if="
|
|
typeReport.val == 'report1' ||
|
|
typeReport.val == 'report2' ||
|
|
typeReport.val == 'report3'
|
|
"
|
|
clickable
|
|
v-close-popup
|
|
@click="downloadReport('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-item
|
|
clickable
|
|
v-close-popup
|
|
@click="downloadReport('xlsx')"
|
|
v-if="typeReport.val !== 'report1'"
|
|
>
|
|
<q-item-section avatar
|
|
><q-icon color="green" name="mdi-file-excel"
|
|
/></q-item-section>
|
|
<q-item-section>ไฟล์ .xlsx</q-item-section>
|
|
</q-item>
|
|
</q-list>
|
|
</q-menu>
|
|
</q-btn>
|
|
</div>
|
|
|
|
<div class="row col-12">
|
|
<q-card bordered class="col-12 filter-card q-pa-sm">
|
|
<div class="row col-12 q-col-gutter-sm">
|
|
<div class="col-md-4 col-xs-12">
|
|
<q-select
|
|
class="bg-white"
|
|
hide-bottom-space
|
|
outlined
|
|
dense
|
|
lazy-rules
|
|
borderless
|
|
v-model="typeReport"
|
|
:label="`${'รายงาน'}`"
|
|
map-options
|
|
:options="employeeClass == 'officer' ? optionReport.filter((item:any)=>item.id !== '7'):optionReport.filter((item:any)=>item.id !== '4')"
|
|
option-value="id"
|
|
option-label="name"
|
|
@update:model-value="onUpdateFilter"
|
|
/>
|
|
</div>
|
|
|
|
<div class="col-md-4 col-xs-12">
|
|
<q-select
|
|
v-if="
|
|
typeReport &&
|
|
(typeReport.val == 'report1' ||
|
|
typeReport.val == 'report2' ||
|
|
typeReport.val == 'report3')
|
|
"
|
|
class="bg-white"
|
|
use-input
|
|
fill-input
|
|
hide-selected
|
|
dense
|
|
lazy-rules
|
|
outlined
|
|
v-model="roundId"
|
|
:options="roundOtion"
|
|
label="เลือกรอบ"
|
|
option-value="id"
|
|
option-label="name"
|
|
emit-value
|
|
map-options
|
|
@update:model-value="onUpdateFilter"
|
|
@filter="(inputValue:string,doneFn:Function) =>
|
|
filterSelector(inputValue, doneFn,'round') "
|
|
>
|
|
<template v-slot:no-option>
|
|
<q-item>
|
|
<q-item-section class="text-grey">
|
|
ไม่มีข้อมูล
|
|
</q-item-section>
|
|
</q-item>
|
|
</template>
|
|
</q-select>
|
|
|
|
<q-select
|
|
v-else
|
|
class="bg-white"
|
|
use-input
|
|
fill-input
|
|
hide-selected
|
|
dense
|
|
lazy-rules
|
|
outlined
|
|
v-model="roundId2"
|
|
:options="roundOtion2"
|
|
label="เลือกรอบ"
|
|
option-value="id"
|
|
option-label="name"
|
|
emit-value
|
|
map-options
|
|
@update:model-value="onUpdateFilter"
|
|
@filter="(inputValue:string,doneFn:Function) =>
|
|
filterSelector(inputValue, doneFn,'round') "
|
|
>
|
|
<template v-slot:no-option>
|
|
<q-item>
|
|
<q-item-section class="text-grey">
|
|
ไม่มีข้อมูล
|
|
</q-item-section>
|
|
</q-item>
|
|
</template>
|
|
</q-select>
|
|
</div>
|
|
</div>
|
|
</q-card>
|
|
</div>
|
|
</div>
|
|
</q-card>
|
|
<q-card flat bordered class="col-12">
|
|
<q-card-section :horizontal="$q.screen.gt.sm">
|
|
<q-card-section class="col-lg-3 col-md-4 col-xs-12 q-gutter-sm">
|
|
<div class="col">
|
|
<q-input dense outlined v-model="filterTree" label="ค้นหา">
|
|
<template v-slot:append>
|
|
<q-icon name="search" />
|
|
</template>
|
|
</q-input>
|
|
</div>
|
|
|
|
<div class="bg-white tree-container q-pa-xs">
|
|
<q-tree
|
|
dense
|
|
:nodes="node"
|
|
node-key="orgTreeId"
|
|
label-key="labelName"
|
|
v-model:expanded="expanded"
|
|
:filter="filterTree.trim()"
|
|
no-results-label="ไม่พบข้อมูลที่ค้นหา"
|
|
no-nodes-label="ไม่มีข้อมูล"
|
|
>
|
|
<template v-slot:default-header="prop">
|
|
<q-item
|
|
@click.stop="
|
|
onSelectedNode(prop.node.orgTreeDnaId, prop.node.orgLevel)
|
|
"
|
|
:active="nodeId === prop.node.orgTreeDnaId"
|
|
clickable
|
|
active-class="my-list-link text-primary text-weight-medium"
|
|
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
|
|
>
|
|
<div>
|
|
<div class="text-weight-medium">
|
|
{{ prop.node.orgTreeName }}
|
|
</div>
|
|
<div class="text-weight-light text-grey-8">
|
|
{{ prop.node.orgCode == null ? null : prop.node.orgCode }}
|
|
{{
|
|
prop.node.orgTreeShortName == null
|
|
? null
|
|
: prop.node.orgTreeShortName
|
|
}}
|
|
</div>
|
|
</div>
|
|
</q-item>
|
|
</template>
|
|
</q-tree>
|
|
</div>
|
|
</q-card-section>
|
|
|
|
<q-separator :vertical="$q.screen.gt.xs" />
|
|
|
|
<q-card-section class="col-lg-9 col-md-8 col-xs-12 scroll">
|
|
<q-splitter
|
|
v-model="splitterModel"
|
|
horizontal
|
|
style="
|
|
height: 65vh;
|
|
border: 1px solid rgb(210, 210, 210);
|
|
border-radius: 5px;
|
|
"
|
|
before-class="overflow-hidden disable"
|
|
separator-class="bg-white disabled"
|
|
>
|
|
<template v-slot:before>
|
|
<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>
|
|
<div class="q-pa-md">
|
|
<LoadView v-if="isLoadPDF" />
|
|
<VuePDF
|
|
v-else
|
|
ref="vuePDFRef"
|
|
:pdf="pdfSrc"
|
|
:page="page"
|
|
fit-parent
|
|
/>
|
|
</div>
|
|
</template>
|
|
<template v-slot:default>
|
|
<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-section>
|
|
</q-card>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scope>
|
|
.q-item.hover-green:hover {
|
|
background-color: #d5f1ee57;
|
|
border-radius: 2px;
|
|
}
|
|
.q-item.hover-green {
|
|
padding: 10px;
|
|
}
|
|
|
|
.tree-container {
|
|
overflow: auto;
|
|
height: 60vh;
|
|
border: 1px solid #e6e6e7;
|
|
border-radius: 10px;
|
|
}
|
|
.my-list-link {
|
|
color: rgb(118, 168, 222);
|
|
border-radius: 5px;
|
|
background: #a3d3fb48 !important;
|
|
font-weight: 600;
|
|
border: 1px solid rgba(175, 185, 196, 0.217);
|
|
}
|
|
</style>
|