hrms-mgt/src/modules/14_KPI/components/Tab/Topic/02_Competency.vue

625 lines
18 KiB
Vue
Raw Normal View History

<script setup lang="ts">
2025-01-30 16:03:18 +07:00
import { onMounted, ref, computed, watch } from "vue";
import { useQuasar, type QTableProps } from "quasar";
2024-09-20 13:02:15 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
import { useRoute } from "vue-router";
2024-09-20 13:02:15 +07:00
import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/14_KPI/store";
2024-05-17 11:10:23 +07:00
import type {
FormCapacityList,
ListCriteria,
2024-08-06 15:43:41 +07:00
DataOptions,
2024-11-12 14:01:11 +07:00
} from "@/modules/14_KPI/interface/request/index";
2024-06-28 11:28:40 +07:00
import DialogListCriteria from "@/modules/14_KPI/components/Tab/Dialog/DialogListCriteria.vue";
import DialogCompetncyByRow from "@/modules/14_KPI/components/Tab/Dialog/DialogCompetncyByRow.vue";
import DialogLevel from "@/modules/14_KPI/components/Tab/Dialog/DialogLevel.vue";
2024-09-20 13:02:15 +07:00
import Dialog from "@/modules/14_KPI/components/Tab/Dialog/04_FormCompetency.vue";
import DialogEvaluate from "@/modules/14_KPI/components/Tab/DialogEvaluate/02_Competenct.vue";
import DialogProgress from "@/modules/14_KPI/components/Tab/Dialog/DialogCommentProgress.vue";
import DialogProblem from "@/modules/14_KPI/components/Tab/Dialog/DialogCommentProblem.vue";
2024-06-28 11:28:40 +07:00
const modalLevel = ref<boolean>(false);
const modalCompetncyByRow = ref<boolean>(false);
const dataCompetncyByRow = ref<any[]>([]);
const dataLevel = ref<any[]>([]);
const modalCriteria = ref<boolean>(false);
2024-05-17 11:10:23 +07:00
const dataListCriteria = defineModel<ListCriteria[]>("dataListCriteria", {
required: true,
});
const sortedDataListCriteria = computed(() => {
return dataListCriteria.value.sort((a, b) => a.level - b.level);
});
const modalEvaluate = ref<boolean>(false);
2024-05-17 11:10:23 +07:00
const store = useKpiDataStore();
const route = useRoute();
2024-08-07 17:26:54 +07:00
const checkRoutePermisson = ref<boolean>(route.name == "KPIDetailPage");
const id = ref<string>(route.params.id as string);
const idCapacity = ref<string | null>(null);
const $q = useQuasar();
const mixin = useCounterMixin();
const {
date2Thai,
messageError,
showLoader,
hideLoader,
dialogRemove,
success,
} = mixin;
const modal = ref<boolean>(false);
const columns = ref<QTableProps["columns"]>([
{
name: "name",
align: "left",
label: "รายการสมรรถนะ",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "level",
align: "left",
label: "ระดับที่คาดหวัง",
sortable: true,
field: "level",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "point",
align: "left",
label: "ระดับคะแนนตามเกณฑ์การประเมิน",
2024-06-28 11:28:40 +07:00
sortable: false,
field: "point",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "weight",
align: "left",
label: "น้ำหนัก (ร้อยละ)",
sortable: true,
field: "weight",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "summary",
align: "left",
label: "ผลการประเมิน",
sortable: true,
field: "summary",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
2024-05-17 11:10:23 +07:00
const visibleColumns = ref<string[]>(
store.tabOpen === 3 && store.tabMain === "3"
? ["name", "level", "point", "weight", "summary"]
2024-06-28 11:28:40 +07:00
: ["name", "level", "point", "weight"]
2024-05-17 11:10:23 +07:00
);
2024-09-20 13:02:15 +07:00
const rows = ref<any[]>([]);
const lists = ref<any>([]);
2024-07-01 11:40:07 +07:00
const typeCompetency = ref<any>("");
function onAdd(type: string) {
typeCompetency.value = type;
modal.value = true;
}
2024-09-20 13:02:15 +07:00
/** ดึงข้อมูล สมรรถนะ */
2024-07-01 11:40:07 +07:00
function getData(type: any) {
http
.get(config.API.kpiUserCapacity + `?id=${id.value}&type=${type}`)
.then(async (res) => {
const data = res.data.result.data;
rows.value[type] = data;
lists.value = lists.value.filter((x: any) => x.type != type);
lists.value.push({ type: type, data });
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
let result = 0;
let weight = 0;
let total = 0;
2024-08-06 15:43:41 +07:00
for (let index = 0; index < competencyType.value.length; index++) {
const element = await competencyType.value[index];
2024-05-17 11:10:23 +07:00
const dataArr = await lists.value.find(
(x: any) => x.type == element.id
);
2024-05-17 11:10:23 +07:00
if (dataArr) {
result += dataArr.data.reduce(
(sum: number, e: any) => sum + (e.point / 5) * e.weight,
0
);
weight += dataArr.data.reduce(
(sum: number, e: any) => sum + e.weight,
0
);
total++;
}
}
2024-05-17 11:10:23 +07:00
if (total > 0) {
let weightAvg = weight / total;
let resultAvg = result / total;
2024-05-17 11:10:23 +07:00
2024-06-28 11:28:40 +07:00
if (
store.dataEvaluation.posTypeName == "อำนวยการ" &&
store.dataEvaluation.posTypeName == "บริหาร"
) {
2024-05-17 11:10:23 +07:00
store.competencyScoreVal =
weightAvg != 0
? (resultAvg / weightAvg) * store.excusiveCompetencyScore
: 0;
} else {
store.competencyScoreVal =
weightAvg != 0
? (resultAvg / weightAvg) *
(store.dataEvaluation.isProbation
? store.competencyProbationScore
: store.competencyScore)
2024-05-17 11:10:23 +07:00
: 0;
}
2024-06-28 11:28:40 +07:00
if (
store.isUpdate &&
store.tabMain === "3" &&
(store.dataEvaluation.evaluationStatus === "EVALUATOR" ||
store.dataEvaluation.evaluationStatus === "EVALUATING_EVALUATOR")
) {
http
.put(config.API.updatePoint(store.dataEvaluation.id), {
totalPoint2_1: store.competencyScoreVal.toFixed(2),
summaryPoint: (
store.indicatorScoreVal +
store.competencyScoreVal +
store.devScoreVal
).toFixed(2),
})
.then((res) => {});
}
}
});
}
2024-09-20 13:02:15 +07:00
/**
* เป popup แกไข
* @param data อม row
* @param type แยกประเภท
*/
2024-05-17 11:10:23 +07:00
function onEdit(data: FormCapacityList, type: string) {
idCapacity.value = data.id;
typeCompetency.value = type;
modal.value = true;
}
2024-09-20 13:02:15 +07:00
/**
* ลบขอม
* @param id row
* @param type แยกประเภท
*/
function onDelete(id: string, type: string) {
2024-05-17 11:10:23 +07:00
dialogRemove($q, () => {
showLoader();
http
.delete(config.API.kpiUserCapacity + `/${id}`)
2024-08-27 15:28:06 +07:00
.then(async () => {
await getData(type);
await success($q, "ลบข้อมูลสำเร็จ");
2024-05-17 11:10:23 +07:00
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
2024-09-20 13:02:15 +07:00
/** เปิด popup ประเมิน */
function onEvaluate(type: string) {
typeCompetency.value = type;
modalEvaluate.value = true;
}
2024-09-20 13:02:15 +07:00
const competencyType = ref<any[]>([]);
2024-05-17 11:10:23 +07:00
const modalProgress = ref<boolean>(false);
const modalProblem = ref<boolean>(false);
const type = ref<string>("");
const idList = ref<string>("");
function openPopupProgress(id: string) {
modalProgress.value = true;
type.value = "capacity";
idList.value = id;
}
const isEditStep1 = computed(() => {
return (
(store.dataEvaluation.evaluationStatus === "NEW" &&
store.rolePerson === "USER" &&
store.tabMain === "1") ||
(store.dataEvaluation.evaluationStatus === "NEW_EVALUATOR" &&
store.rolePerson === "EVALUATOR" &&
store.tabMain === "1")
);
});
const isEditStep3 = computed(() => {
return (
(store.dataEvaluation.evaluationStatus === "EVALUATING" &&
store.rolePerson === "USER" &&
store.tabMain === "3") ||
(store.dataEvaluation.evaluationStatus === "EVALUATING_EVALUATOR" &&
store.rolePerson === "EVALUATOR" &&
store.tabMain === "3")
);
});
2024-06-28 11:28:40 +07:00
function onInfo() {
modalCriteria.value = true;
}
function onLevel(num: number, list: any) {
dataLevel.value = list.filter((i: any) => i.level == num);
modalLevel.value = true;
}
2025-01-30 16:03:18 +07:00
watch(
() => store.dataEvaluation.posTypeName, // ตรวจจับค่า posTypeName
(newValue) => {
if (!newValue) return; // ถ้ายังไม่มีค่า ไม่ต้องทำอะไร
const competencyTypeList = [
{
id: "HEAD",
name: "สมรรถนะหลัก",
},
{
id: "GROUP",
name: "สมรรถนะประจำกลุ่มงาน",
},
{
id: "EXECUTIVE",
name: "สมรรถนะประจำผู้บริหารกรุงเทพมหานคร",
},
{
id: "DIRECTOR",
name: "สมรรถนะเฉพาะสำหรับตำแหน่ง ผอ.เขต ผช.ผอ.เขต และหัวหน้าฝ่ายในสังกัด สนง.เขต",
},
{
id: "INSPECTOR",
name: "สมรรถนะเฉพาะสำหรับตำแหน่งผู้ตรวจราชการ กทม. และผู้ตรวจราชการ",
},
];
2024-08-06 15:43:41 +07:00
competencyType.value =
2025-01-30 16:03:18 +07:00
newValue === "อำนวยการ" || newValue === "บริหาร"
? competencyTypeList.filter(
2024-08-06 15:43:41 +07:00
(x: DataOptions) =>
2025-01-30 16:03:18 +07:00
x.id === "HEAD" ||
x.id === "EXECUTIVE" ||
x.id === "INSPECTOR" ||
x.id === "DIRECTOR"
2024-08-06 15:43:41 +07:00
)
2025-01-30 16:03:18 +07:00
: competencyTypeList.filter(
(x: DataOptions) => x.id === "HEAD" || x.id === "GROUP"
2024-08-06 15:43:41 +07:00
);
for (let index = 0; index < competencyType.value.length; index++) {
const element = competencyType.value[index];
getData(element.id);
}
2025-01-30 16:03:18 +07:00
},
{ immediate: true }
);
</script>
<template>
2024-08-06 15:43:41 +07:00
<div v-for="(item, index) in competencyType" :key="index">
2024-06-28 11:28:40 +07:00
<q-card bordered style="border-radius: 5px" class="no-shadow q-mt-sm">
<q-card-section class="bg-grey-2 q-py-sm">
<div class="row items-center">
<div class="col">
<span class="text-weight-medium">{{ item.name }}</span>
<q-btn
2024-08-14 17:46:41 +07:00
v-if="
!checkRoutePermisson &&
isEditStep1 &&
item.id != 'HEAD' &&
item.id != 'GROUP'
"
class="q-ml-xs"
flat
round
icon="mdi-plus"
color="primary"
size="12px"
dense
@click="onAdd(item.id)"
>
<q-tooltip>เพมขอม</q-tooltip>
</q-btn>
</div>
<q-space />
2025-01-30 11:37:47 +07:00
<!-- <q-btn
2024-08-07 17:26:54 +07:00
v-if="!checkRoutePermisson && isEditStep3"
flat
round
icon="mdi-clipboard-check-outline"
color="blue-5"
size="12px"
dense
@click="onEvaluate(item.id)"
>
<q-tooltip>ประเม</q-tooltip>
2025-01-30 11:37:47 +07:00
</q-btn> -->
</div>
</q-card-section>
<q-card-section class="q-pa-sm">
2024-06-28 11:28:40 +07:00
<d-table
ref="table"
:columns="columns"
2024-08-27 15:28:06 +07:00
:rows="
rows[item.id] && rows[item.id].length !== 0 ? rows[item.id] : []
"
row-key="id"
flat
bordered
:paging="true"
dense
hide-pagination
no-data-label="ไม่มีข้อมูล"
2024-05-17 11:10:23 +07:00
:visible-columns="visibleColumns"
>
<template v-slot:header="props">
<q-tr :props="props">
2024-06-28 11:28:40 +07:00
<q-th auto-width />
<q-th v-for="col in props.cols" :key="col.name" :props="props">
2024-06-28 11:28:40 +07:00
<span v-if="col.name == 'point'" class="text-weight-medium">
<q-btn
flat
icon="mdi-eye"
color="info"
round
class="q-ml-xs"
@click="onInfo"
>
<q-tooltip>เกณฑการประเม</q-tooltip> </q-btn
>{{ col.label }}</span
>
<span v-else class="text-weight-medium">{{ col.label }}</span>
</q-th>
2024-05-17 11:10:23 +07:00
<q-th auto-width />
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
2024-06-28 11:28:40 +07:00
<q-td auto-width>
<q-btn
2024-08-06 15:43:41 +07:00
v-if="isEditStep1"
2024-06-28 11:28:40 +07:00
flat
round
2024-08-06 15:43:41 +07:00
:icon="
item.id == 'HEAD' || item.id == 'GROUP' ? 'mdi-eye' : 'edit'
"
color="info"
2025-07-09 10:38:40 +07:00
@click.stop.prevent="onEdit(props.row, item.id)"
2024-06-28 11:28:40 +07:00
>
2024-08-06 15:43:41 +07:00
<q-tooltip v-if="item.id == 'HEAD' || item.id == 'GROUP'"
>รายละเอยด</q-tooltip
>
<q-tooltip v-else>แก้ไข</q-tooltip>
2024-06-28 11:28:40 +07:00
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.id">
<div v-if="col.name == 'createDate'">
{{ col.value ? date2Thai(col.value) : "-" }}
</div>
<div v-else-if="col.name == 'point'">
<div>
2024-05-17 11:10:23 +07:00
<q-btn-group outline>
<q-btn
v-for="(i, index) in sortedDataListCriteria"
:key="index"
:class="props.row.point == i.level && 'active'"
outline
color="grey-6"
:label="i.level"
>
<q-tooltip>
<div class="text-body2">
<span v-html="i.description"></span>
</div>
</q-tooltip>
</q-btn>
</q-btn-group>
</div>
</div>
<div v-else-if="col.name == 'summary'">
{{
props.row.point !== 0
? (props.row.point / 5) * props.row.weight
: "-"
}}
</div>
2024-06-28 11:28:40 +07:00
<div v-else-if="col.name == 'level'">
<div
@click="onLevel(props.row.level, props.row.achievement)"
class="text-teal"
>
{{ props.row.level }}
</div>
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
2024-05-17 11:10:23 +07:00
<q-td>
<div
2024-08-06 15:43:41 +07:00
v-if="
2024-07-12 13:22:35 +07:00
(store.dataEvaluation.evaluationStatus == 'APPROVE' &&
store.tabMain === '2') ||
store.tabMain === '3'
2024-05-17 11:10:23 +07:00
"
2024-06-28 11:28:40 +07:00
>
<q-btn
flat
round
icon="mdi-account-details"
color="blue-6"
size="12px"
dense
@click="openPopupProgress(props.row.id)"
>
2025-01-30 16:03:18 +07:00
<q-tooltip>{{
store.tabMain == "3"
? "บันทึกเหตุการณ์/พฤติกรรม/เหตุผล"
: "บันทึกเหตุการณ์/พฤติกรรม"
}}</q-tooltip>
2024-06-28 11:28:40 +07:00
</q-btn>
</div>
2024-08-07 17:26:54 +07:00
<div v-if="isEditStep1 && !checkRoutePermisson">
2024-06-28 11:28:40 +07:00
<q-btn
flat
round
icon="delete"
color="red"
2025-07-09 10:38:40 +07:00
@click.stop.prevent="onDelete(props.row.id, item.id)"
2024-06-28 11:28:40 +07:00
>
<q-tooltip>ลบขอม </q-tooltip>
</q-btn>
</div>
</q-td>
</q-tr>
</template>
</d-table>
</q-card-section>
</q-card>
</div>
<Dialog
v-model:modal="modal"
v-model:competency-type="typeCompetency"
v-model:id="idCapacity"
:get-data-list="getData"
/>
<DialogEvaluate
v-model:modal="modalEvaluate"
v-model:data="rows[typeCompetency]"
v-model:type="typeCompetency"
v-model:dataListCriteria="dataListCriteria"
:get-data="getData"
/>
2024-05-17 11:10:23 +07:00
<DialogProgress
v-model:modal="modalProgress"
v-model:type="type"
:idList="idList"
/>
<DialogProblem
v-model:modal="modalProblem"
v-model:type="type"
:idList="idList"
/>
2024-06-28 11:28:40 +07:00
<DialogListCriteria
v-model:modal="modalCriteria"
v-model:dataListCriteria="dataListCriteria"
/>
<DialogCompetncyByRow
v-model:modal="modalCompetncyByRow"
v-model:rows="dataCompetncyByRow"
/>
<DialogLevel v-model:modal="modalLevel" v-model:rows="dataLevel" />
</template>
<style scoped>
.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;
}
}
2024-05-17 11:10:23 +07:00
.q-btn-group--outline > .q-btn-item:not(:last-child):before {
border-right: 1px solid #c4c4c4;
}
.q-btn-group--outline > .q-btn-item.active {
color: #2196f3 !important;
background-color: #cde6fb !important;
}
.q-btn-group--outline > .q-btn-item + .q-btn-item.active:before {
border-left: 1px solid #2196f3 !important;
background-color: #cde6fb;
}
.q-btn-group--outline > .q-btn-item.active:not(:last-child):before {
border: 1px solid #2196f3;
background-color: #cde6fb;
}
</style>