import { defineStore } from "pinia"; import { ref, reactive, watch } from "vue"; import type { DataOptions } from "./interface/index/Main"; import type { FormQuery } from "@/modules/08_KPI/interface/request/index"; import { useCounterMixin } from "@/stores/mixin"; import http from "@/plugins/http"; import config from "@/app.config"; import { useQuasar } from "quasar"; export const useKpiDataStore = defineStore("KPIDate", () => { const $q = useQuasar(); const mixin = useCounterMixin(); const { dialogConfirm, success, showLoader, hideLoader, messageError, findPosMasterNoOld, findOrgNameOld, date2Thai, } = mixin; const tabMainevaluator = ref("1"); const yearRound = ref(new Date().getFullYear()); const formQuery = reactive({ page: 1, pageSize: 10, round: "", keyword: "", }); const selected = ref([]); const work = ref(false); const tabMain = ref("1"); const dataProfile = ref({ profileId: null, prefix: "", rank: "", firstName: "", lastName: "", citizenId: "", position: "", posMaster: null, posLevelName: null, posLevelRank: null, posLevelId: null, posTypeName: null, posTypeRank: null, posTypeId: null, posExecutiveName: "", posExecutivePriority: null, posExecutiveId: null, rootId: null, root: "", child1Id: null, child1: null, child2Id: null, child2: null, child3Id: null, child3: null, child4Id: null, child4: null, node: null, nodeId: null, }); const dataEvaluation = ref({ evaluationReqEdit: null, evaluationStatus: null, profileId: null, evaluatorId: null, commanderId: null, commanderHighId: null, plannedPoint: 0, rolePoint: 0, specialPoint: 0, }); const competencyType = ref([ { id: "HEAD", name: "สมรรถนะหลัก", }, { id: "GROUP", name: "สมรรถนะประจำกลุ่มงาน", }, { id: "EXECUTIVE", name: "สมรรถนะประจำผู้บริหารกรุงเทพมหานคร", }, { id: "DIRECTOR", name: "สมรรถนะเฉพาะสำหรับตำแหน่ง ผอ.เขต ผช.ผอ.เขต และหัวหน้าฝ่ายในสังกัด สนง.เขต", }, { id: "INSPECTOR", name: "สมรรถนะเฉพาะสำหรับตำแหน่งผู้ตรวจราชการ กทม. และผู้ตรวจราชการ", }, ]); function convertCompetencyType(val: string) { const competency = competencyType.value.find( (x: DataOptions) => x.id == val ); return competency?.name; } function convertStatus(val: string) { switch (val) { case "NEW": return "จัดทำข้อตกลง"; case "NEW_EVALUATOR": return "รอผู้ประเมินตรวจสอบข้อตกลง"; case "NEW_COMMANDER": return "รอผู้บังคับบัญชาเหนือขึ้นไปตรวจสอบข้อตกลง"; case "NEW_COMMANDER_HIGH": return "รอผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่งตรวจสอบข้อตกลง"; case "APPROVE": return "รายงานความก้าวหน้า"; case "EVALUATING": return "รายงานผลสำเร็จของงาน"; case "EVALUATING_EVALUATOR": return "รอผู้ประเมินตรวจสอบผล"; case "EVALUATING_COMMANDER": return "รอผู้บังคับบัญชาเหนือขึ้นไปตรวจสอบผล"; case "EVALUATING_COMMANDER_HIGH": return "รอผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่งตรวจสอบผล"; case "COMPLETE": return "เสร็จสิ้น"; default: break; } } function convertResults(val: string) { switch (val) { case "PENDING": return "รอดำเนินการ"; case "PASSED": return "ผ่านการประเมิน"; case "NOTPASSED": return "ไม่ผ่านการประเมิน"; default: break; } } async function checkCompetency() { // const position = await dataEvaluation.value.position; // const executiveName = await dataEvaluation.value.posExecutiveName; const posTypeName = dataEvaluation.value.posTypeName; const posLevelName = dataEvaluation.value.posLevelName; // if ( // position == "ผู้ตรวจราชการกรุงเทพมหานคร" || // position == "ผู้ตรวจราชการ" // ) { // competencyType.value = competencyType.value.filter( // (x: DataOptions) => x.id == "HEAD" || x.id == "INSPECTOR" // ); // } else if (position == "ผู้อำนวยการเขต") { // competencyType.value = competencyType.value.filter( // (x: DataOptions) => x.id == "HEAD" || x.id == "DIRECTOR" // ); // } else { if (posTypeName == "อำนวยการ" || posTypeName == "บริหาร") { competencyType.value = competencyType.value.filter( (x: DataOptions) => x.id == "HEAD" || x.id == "EXECUTIVE" || x.id == "INSPECTOR" || x.id == "DIRECTOR" ); } else { competencyType.value = competencyType.value.filter( (x: DataOptions) => x.id == "HEAD" || x.id == "GROUP" ); } // } } const defaultCompetencyCoreLevel = ref(); const defaultCompetencyGroupLevel = ref(null); function checkCompetencyDefaultCompetencyLevel() { const posTypeName = dataEvaluation.value.posTypeName; const posLevelName = dataEvaluation.value.posLevelName; switch (posTypeName + " " + posLevelName) { case "บริหาร สูง": defaultCompetencyCoreLevel.value = 5; break; case "บริหาร ต้น": defaultCompetencyCoreLevel.value = 4; break; case "อำนวยการ สูง": defaultCompetencyCoreLevel.value = 4; break; case "อำนวยการ ต้น": defaultCompetencyCoreLevel.value = 3; break; case "วิชาการ ทรงคุณวุฒิ": defaultCompetencyCoreLevel.value = 5; defaultCompetencyGroupLevel.value = 5; break; case "วิชาการ เชี่ยวชาญ": defaultCompetencyCoreLevel.value = 4; defaultCompetencyGroupLevel.value = 4; break; case "วิชาการ ชำนาญการพิเศษ": defaultCompetencyCoreLevel.value = 3; defaultCompetencyGroupLevel.value = 4; break; case "วิชาการ ชำนาญการ": defaultCompetencyCoreLevel.value = 2; defaultCompetencyGroupLevel.value = 3; break; case "วิชาการ ปฏิบัติการ": defaultCompetencyCoreLevel.value = 1; defaultCompetencyGroupLevel.value = 2; break; case "ทั่วไป ทักษะพิเศษ": defaultCompetencyCoreLevel.value = 4; defaultCompetencyGroupLevel.value = 4; break; case "ทั่วไป อาวุโส": defaultCompetencyCoreLevel.value = 3; defaultCompetencyGroupLevel.value = 3; break; case "ทั่วไป ชำนาญงาน": defaultCompetencyCoreLevel.value = 2; defaultCompetencyGroupLevel.value = 2; break; case "ทั่วไป ปฏิบัติงาน": defaultCompetencyCoreLevel.value = 1; defaultCompetencyGroupLevel.value = 1; break; default: defaultCompetencyCoreLevel.value = 1; defaultCompetencyGroupLevel.value = 1; break; } } const ratingColors = ref([ "light-blue-3", "light-blue-6", "blue", "blue-9", "blue-10", ]); // ROLE & TAB const rolePerson = ref("USER"); //"USER" | "EVALUATOR" | "COMMANDER", "COMMANDERHIGH" const tabOpen = ref(1); async function checkStep() { const role = await (dataEvaluation.value.profileId == dataProfile.value.profileId ? "USER" : dataEvaluation.value.evaluatorId == (await dataProfile.value.profileId) ? "EVALUATOR" : dataEvaluation.value.commanderId == (await dataProfile.value.profileId) ? "COMMANDER" : dataEvaluation.value.commanderHighId == (await dataProfile.value.profileId) ? "COMMANDERHIGH" : ""); // console.log("🚀 ~ checkStep ~ role:", role); rolePerson.value = role; switch (dataEvaluation.value.evaluationStatus) { case "NEW": tabOpen.value = 1; break; case "NEW_EVALUATOR": tabOpen.value = 1; break; case "NEW_COMMANDER": tabOpen.value = 1; break; case "NEW_COMMANDER_HIGH": tabOpen.value = 1; break; case "APPROVE": tabOpen.value = 2; break; case "EVALUATING": tabOpen.value = 3; break; case "EVALUATING_EVALUATOR": tabOpen.value = 3; break; case "EVALUATING_COMMANDER": tabOpen.value = 3; break; case "EVALUATING_COMMANDER_HIGH": tabOpen.value = 3; break; case "SUMMARY": tabOpen.value = 4; break; case "COMPLETE": tabOpen.value = 4; break; default: tabOpen.value = 1; break; } } // SUMMARY GENERAL CASE const indicatorWeightTotal = ref(0); // น้ำหนักรวมกรณีทั่วไป const indicatorWeight1Total = ref(0); // น้ำหนักรวมมิติที่ 1 ต้องไม่เกิน 100% const indicatorWeight2Total = ref(0); // น้ำหนักรวมมิติที่ 2 ต้องไม่เกิน 20 const indicatorPercentVal = ref(0); // รวมผลการประเมิน (ร้อยละ) ที่ได้จริง const indicatorScore = ref(70); // สรุปผลการประเมินผลสัมฤทธิ์ของงาน ( คะแนนเต็ม indicatorScore คะแนน) const competencyScore = ref(20); // ผลการประเมินสมรรถนะ (competencyScore คะแนน) const devScoreVal = ref(0); // ผลการประเมินการพัฒนาตนเองที่ได้กี่คะแนน const competencyDevScore = ref(30); // สรุปผลการประเมินพฤติกรรมการปฏิบัติราชการ (สมรรถนะ+การพัฒนาตนเอง) (คะแนนเต็ม competencyDevScore คะแนน) const devScore = ref(10); // ผลการประเมินการพัฒนาตนเอง (devScore คะแนน) // SUMMARY EXCLUSIVE CASE const excusiveIndicator1PercentVal = ref(0); // รวมผลการประเมิน (ร้อยละ) มิติที่ 1 ที่ได้จริง const excusiveIndicator1Weight = ref(60); // น้ำหนักของมิติที่ 1 const excusiveIndicator1ScoreVal = ref(0); // คะแนนมิติที่ 1 ที่ได้จริง const excusiveIndicator2Weight = ref(20); // น้ำหนักของมิติที่ 2 const excusiveIndicator2PercentVal = ref(0); // รวมผลการประเมิน (ร้อยละ) มิติที่ 2 ที่ได้จริง const excusiveIndicator2ScoreVal = ref(0); // คะแนนมิติที่ 2 ที่ได้จริง const excusiveIndicatorScore = ref(80); // สรุปผลการประเมินผลสัมฤทธิ์ของงาน (มิติที่ 1 + มิติที่ 2) ( คะแนนเต็ม excusiveIndicatorScore คะแนน) const excusiveCompetencyScore = ref(20); // ผลการประเมินสมรรถนะ (competencyScore คะแนน) const indicatorScoreVal = ref(0); // สรุปผลการประเมินผลสัมฤทธิ์ของงานที่ได้ const competencyScoreVal = ref(0); // ผลการประเมินสมรรถนะที่ได้กี่คะแนน function getDataWork() { showLoader(); http .get(config.API.orgPosition + `/${dataProfile.value.profileId}`) .then((res) => { const data = res.data.result.isProbation; work.value = data; if (data) { indicatorScore.value = 50; competencyScore.value = 40; excusiveCompetencyScore.value = 40; competencyDevScore.value = 10; } else { indicatorScore.value = 70; competencyScore.value = 20; excusiveCompetencyScore.value = 20; competencyDevScore.value = 30; } }) .catch((e) => { messageError($q, e); }) .finally(() => { hideLoader(); }); } watch( () => tabMain.value, () => { if (tabMain.value == "3" && tabOpen.value == 3) { getDataWork(); } else { indicatorScore.value = 70; competencyScore.value = 20; excusiveCompetencyScore.value = 20; competencyDevScore.value = 30; } } ); return { tabMain, dataProfile, dataEvaluation, competencyType, convertCompetencyType, convertStatus, convertResults, checkCompetency, checkCompetencyDefaultCompetencyLevel, defaultCompetencyCoreLevel, defaultCompetencyGroupLevel, ratingColors, checkStep, tabOpen, rolePerson, // score indicatorWeightTotal, indicatorWeight1Total, indicatorWeight2Total, indicatorPercentVal, indicatorScore, indicatorScoreVal, competencyScore, competencyScoreVal, devScore, devScoreVal, competencyDevScore, excusiveCompetencyScore, excusiveIndicator1PercentVal, excusiveIndicator1Weight, excusiveIndicator1ScoreVal, excusiveIndicator2Weight, excusiveIndicator2PercentVal, excusiveIndicator2ScoreVal, excusiveIndicatorScore, //รายการการประเมินผลการปฏิบัติราชการระดับบุคคล tabMainevaluator, formQuery, yearRound, selected, work, }; });