hrms-mgt/src/modules/15_development/views/Scholarship.vue
2024-04-26 10:21:36 +07:00

380 lines
10 KiB
Vue

<script setup lang="ts">
import { ref, reactive, onMounted, watch } from "vue";
import { useQuasar, type QTableProps } from "quasar";
import { useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import genReportXLSX from "@/plugins/genreportxlsx";
import type {
DataOption,
ItemsDownload,
NewPagination,
} from "@/modules/15_development/interface/index/Main";
import type { ListSholarship } from "@/modules/15_development/interface/response/Scholarship";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const router = useRouter();
const { showLoader, hideLoader, messageError } = useCounterMixin();
/** หัวตาราง */
const rows = ref<ListSholarship[]>([]);
const columns = ref<QTableProps["columns"]>([
{
name: "citizenId",
align: "left",
label: "เลขประจำตัวประชาชน ",
sortable: true,
field: "citizenId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "fullName",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "fullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่ง",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posType",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: true,
field: "posType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevel",
align: "left",
label: "ระดับตำแหน่ง",
sortable: true,
field: "posLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posExecutive",
align: "left",
label: "ตำแหน่งทางการบริหาร",
sortable: true,
field: "posExecutive",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const visibleColumns = ref<string[]>([
"citizenId",
"fullName",
"position",
"posType",
"posLevel",
"posExecutive",
]);
const scholarshipTypeOp = ref<DataOption[]>([
{ id: "DOMESTICE", name: "การศึกษาในประเทศ" },
{
id: "NOABROAD",
name: "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)",
},
{
id: "ABROAD",
name: "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)",
},
{
id: "EXECUTIVE",
name: " ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร)",
},
{
id: "RESEARCH",
name: "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ",
},
]);
const formQuery = reactive({
page: 1,
pageSize: 10,
year: new Date().getFullYear(),
type: "DOMESTICE",
keyword: "",
});
const totalList = ref<number>(1); //จำนวนข้อมูลรายการ
const maxPage = ref<number>(1);
function fetchList() {
showLoader();
http
.get(
config.API.devScholarship +
`?page=${formQuery.page}&pageSize=${formQuery.pageSize}&keyword=${formQuery.keyword}&year=${formQuery.year}&scholarshipType=${formQuery.type}`
)
.then((res) => {
const data = res.data.result.data;
maxPage.value = Math.ceil(res.data.result.total / formQuery.pageSize);
totalList.value = res.data.result.total;
rows.value = data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function fetchNewList() {
formQuery.page = 1;
fetchList();
}
function onClickAddOrView(status: boolean = false, id: string = "") {
status
? router.push(`/development/scholarship/${id}`)
: router.push("/development/scholarship/add");
}
/**
* function updatePagination
* @param newPagination ข้อมูล Pagination ใหม่
*/
function updatePagination(newPagination: NewPagination) {
formQuery.page = 1;
formQuery.pageSize = newPagination.rowsPerPage;
}
watch(
() => formQuery.pageSize,
() => {
fetchNewList();
}
);
function onDownload() {
showLoader();
http
.get(config.API.developmentReportScholarship())
.then((res) => {
const dataList = res.data.result;
genReportXLSX(dataList, "รายการข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรม");
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
onMounted(() => {
fetchList();
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
รายการขาราชการฯทไดบทนการศกษา/กอบรม
</div>
<q-card flat bordered class="q-pa-md">
<q-toolbar class="q-pa-none">
<div class="row q-gutter-sm">
<datepicker
style="width: 150px"
menu-class-name="modalfix"
v-model="formQuery.year"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
@update:model-value="fetchNewList"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
:model-value="
formQuery.year === 0 ? 'ทั้งหมด' : Number(formQuery.year) + 543
"
:label="`${'ปีงบประมาณ'}`"
>
<template v-if="formQuery.year" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="(formQuery.year = 0), fetchNewList()"
class="cursor-pointer"
/>
</template>
<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
dense
outlined
v-model="formQuery.type"
:options="scholarshipTypeOp"
emit-value
map-options
option-value="id"
option-label="name"
label="เลือกประเภททุน"
@update:model-value="fetchNewList"
class="type"
/>
</div>
<q-btn
flat
round
dense
icon="add"
color="primary"
@click="onClickAddOrView()"
>
<q-tooltip>เพิ่ม</q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-btn
flat
round
dense
icon="mdi-arrow-down-bold-circle-outline"
color="blue"
@click="onDownload"
>
<q-tooltip>ดาวน์โหลด</q-tooltip>
</q-btn>
<q-input
standout
dense
v-model="formQuery.keyword"
ref="filterRef"
outlined
placeholder="ค้นหา"
@keyup.enter="fetchNewList()"
>
<template v-slot:append>
<q-icon v-if="formQuery.keyword == ''" name="search" />
<q-icon
v-if="formQuery.keyword !== ''"
name="clear"
class="cursor-pointer"
@click="(formQuery.keyword = ''), fetchNewList()"
/>
</template>
</q-input>
<q-select
v-model="visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="columns"
option-value="name"
options-cover
style="min-width: 150px"
/>
</div>
</q-toolbar>
<div class="col-12">
<d-table
for="table"
ref="table"
:columns="columns"
:rows="rows"
row-key="subject"
flat
bordered
dense
class="custom-header-table"
:visible-columns="visibleColumns"
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
>
<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>
</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"
@click="onClickAddOrView(true, props.row.id)"
>
<div class="table_ellipsis">
{{ col.value ? col.value : "-" }}
</div>
</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>
</div>
</q-card>
</template>
<style scoped>
.q-select.type >>> .q-field__native > span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 200px;
}
</style>