hrms-user/src/modules/08_KPI/views/main.vue
STW_TTTY\stwtt 0f8dc5229d no message
2024-04-26 15:18:28 +07:00

602 lines
17 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, reactive, watch } from "vue";
import { useRouter } from "vue-router";
import { useQuasar } from "quasar";
import config from "@/app.config";
import http from "@/plugins/http";
import type { DataOptions } from "@/modules/08_KPI/interface/index/Main";
import type { QTableProps } from "quasar";
import DialogHeader from "@/components/DialogHeader.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/08_KPI/store";
const $q = useQuasar();
const mixin = useCounterMixin();
const store = useKpiDataStore();
const router = useRouter();
const { showLoader, hideLoader, messageError, date2Thai, dialogConfirm } =
mixin;
/** Table*/
const rows = ref<any>();
const visibleColumns = ref<string[]>([
"createdAt",
"evaluationStatus",
"evaluationResults",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "createdAt",
align: "left",
label: "วันที่สร้างแบบประเมิน",
sortable: true,
field: "createdAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "evaluationStatus",
align: "left",
label: "สถานะการประเมิน",
sortable: true,
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,
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" }),
},
]);
/** List*/
const year = ref<number>(new Date().getFullYear());
const round = ref<string>("");
const filterKeyword = ref<string>("");
const roundMainOp = ref<DataOptions[]>([]);
const roundDialgOp = ref<DataOptions[]>([]);
const evaluatorIdOp = ref<DataOptions[]>([]);
const commanderIdOp = ref<DataOptions[]>([]);
const commanderHighOp = ref<DataOptions[]>([]);
/** Dialog*/
const modalDialog = ref<boolean>(false);
const yearDialog = ref<number | null>(null);
const formRound = reactive({
kpiPeriodId: "",
profileId: "",
prefix: "",
firstName: "",
lastName: "",
evaluatorId: "",
commanderId: "",
commanderHighId: "",
});
/** pagetion*/
const formQuery = reactive({
page: 1,
pageSize: 10,
});
const totalList = ref<number>(1);
function fetchRoundOption(type: string) {
const y = type === "main" ? year.value : yearDialog.value;
showLoader();
http
.get(
config.API.kpiPeriod + `?page=${1}&pageSize=${10}&keyword=${""}&year=${y}`
)
.then((res) => {
const data = res.data.result.data;
const list = data.map((e: any) => ({
id: e.id,
name:
e.durationKPI === "OCT"
? "รอบตุลาคม"
: e.durationKPI === "APR"
? "รอบเมษายน"
: "",
}));
if (type === "main") {
roundMainOp.value = list;
round.value = "";
fetchList();
} else {
roundDialgOp.value = list;
formRound.kpiPeriodId = "";
}
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/** ดึงข้อมูล */
function fetchList() {
showLoader();
http
.get(
config.API.kpiEvaluation +
`?page=${formQuery.page}&pageSize=${formQuery.pageSize}&kpiPeriodId=${round.value}`
)
.then((res) => {
const data = res.data.result;
totalList.value = Math.ceil(data.total / formQuery.pageSize);
rows.value = data.data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function changRound() {
formQuery.page = 1;
fetchList();
}
function redirectViewDetail(id: string) {
router.push(`/KPI/${id}`);
}
function onClickAddList() {
modalDialog.value = true;
}
function onCloseDialog() {
modalDialog.value = false;
formRound.kpiPeriodId = "";
yearDialog.value = null;
}
function onSubmit() {
dialogConfirm($q, () => {
showLoader();
http
.post(config.API.kpiEvaluation, formRound)
.then((res) => {
console.log(res);
const id = res.data.result;
redirectViewDetail(id);
onCloseDialog();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
}
function getProfile() {
showLoader();
http
.get(config.API.profileBykeycloak())
.then((res) => {
const data = res.data.result;
formRound.profileId = data.id;
formRound.prefix = data.prefix;
formRound.firstName = data.firstName;
formRound.lastName = data.lastName;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
const pagination = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
/**
* function updatePagination
* @param newPagination ข้อมูล Pagination ใหม่
*/
function updatePagination(newPagination: any) {
formQuery.page = 1;
formQuery.pageSize = newPagination.rowsPerPage;
}
watch(
() => formQuery.pageSize,
() => {
fetchList();
}
);
function getOrgOp(){
http
.get(config.API.Kpiorg)
.then((res)=>{
console.log(res)
})
}
onMounted(() => {
getProfile();
fetchRoundOption("main");
getOrgOp()
});
</script>
<template>
<div class="col-12 row justify-center">
<div class="col-xs-12 col-sm-12 col-md-11">
<div class="toptitle text-white col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.push(`/`)"
/>
รายการขอรบประเมนผลการปฏราชการระดบบคคล
</div>
<div class="col-12">
<q-card bordered class="q-pa-md">
<q-toolbar style="padding: 0">
<div class="row q-gutter-sm">
<datepicker
menu-class-name="modalfix"
v-model="year"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
@update:model-value="fetchRoundOption('main')"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
class="inputgreen"
hide-bottom-space
:model-value="!!year ? year + 543 : null"
:label="`${'ปีงบประมาณ'}`"
>
<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
v-model="round"
outlined
label="รอบการประเมิน"
dense
option-label="name"
option-value="id"
:options="roundMainOp"
style="min-width: 200px"
emit-value
map-options
@update:model-value="changRound"
/>
<q-btn
flat
round
color="primary"
icon="add"
@click="onClickAddList"
>
<q-tooltip> เพิ่มข้อมูล </q-tooltip>
</q-btn>
</div>
<q-space />
<div class="row q-gutter-sm">
<!-- <q-input
outlined
dense
v-model="filterKeyword"
label="ค้นหา"
></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">
<q-table
ref="table"
:columns="columns"
:rows="rows"
:filter="filterKeyword"
row-key="id"
flat
bordered
:paging="true"
dense
class="custom-table2"
:rows-per-page-options="[10, 25, 50, 100]"
:visible-columns="visibleColumns"
v-model:pagination="pagination"
@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.id"
@click="redirectViewDetail(props.row.id)"
>
<div>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
<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>
</q-table>
</div>
</q-card>
</div>
</div>
</div>
<q-dialog v-model="modalDialog" persistent>
<q-card class="col-12" style="width: 18%">
<q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="'สร้างแบบประเมินผลฯ'" :close="onCloseDialog" />
<q-separator />
<q-card-section class="q-pa-none scroll" style="max-height: 80vh">
<div class="row q-pa-md q-col-gutter-md">
<div class="col-12">
<datepicker
menu-class-name="modalfix"
v-model="yearDialog"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
@update:model-value="fetchRoundOption('dialog')"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
class="inputgreen"
hide-bottom-space
:model-value="!!yearDialog ? yearDialog + 543 : null"
:label="`${'ปีงบประมาณ'}`"
:rules="[
(val:string) =>
!!val || `${'กรุณาเลือกปีงบประมาณ'}`,
]"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<div class="col-12">
<q-select
v-model="formRound.kpiPeriodId"
outlined
label="รอบการประเมิน"
dense
option-label="name"
option-value="id"
:options="roundDialgOp"
emit-value
map-options
hide-bottom-space
lazy-rules
:rules="[
(val:string) =>
!!val || `${'กรุณาเลือกรอบการประเมิน'}`,
]"
/>
</div>
<div class="col-12">
<q-select
v-model="formRound.evaluatorId"
outlined
label="ผู้ประเมิน"
dense
option-label="name"
option-value="id"
:options="evaluatorIdOp"
emit-value
map-options
hide-bottom-space
lazy-rules
:rules="[
(val:string) =>
!!val || `${'กรุณาเลือกผู้ประเมิน'}`,
]"
/>
</div>
<div class="col-12">
<q-select
v-model="formRound.commanderId"
outlined
label="ผู้บังคับบัญชาเหนือขึ้นไป"
dense
option-label="name"
option-value="id"
:options="commanderIdOp"
emit-value
map-options
>
<template v-if="formRound.commanderId" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="formRound.commanderId = ''"
class="cursor-pointer"
/>
</template>
</q-select>
</div>
<div class="col-12">
<q-select
v-model="formRound.commanderHighId"
outlined
label="ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง"
dense
option-label="name"
option-value="id"
:options="commanderHighOp"
emit-value
map-options
>
<template v-if="formRound.commanderHighId" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="formRound.commanderHighId = ''"
class="cursor-pointer"
/>
</template>
</q-select>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn label="บันทึก" color="secondary" type="submit"
><q-tooltip>นทกขอม</q-tooltip></q-btn
>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>
<style scoped lang="scss">
.icon-color {
color: #4154b3;
}
.custom-table2 {
max-height: 64vh;
.q-table tr:nth-child(odd) td {
background: white;
}
.q-table tr:nth-child(even) td {
background: #f8f8f8;
}
.q-table thead tr {
background: #ecebeb;
}
.q-table thead tr th {
position: sticky;
}
.q-table td:nth-of-type(2) {
z-index: 3 !important;
}
.q-table th:nth-of-type(2),
.q-table td:nth-of-type(2) {
position: sticky;
left: 0;
z-index: 1;
}
/* this will be the loading indicator */
.q-table thead tr:last-child th {
/* height of all previous header rows */
top: 48px;
}
.q-table thead tr:first-child th {
top: 0;
}
}
</style>