diff --git a/src/api/KPI/api.kpis.ts b/src/api/KPI/api.kpis.ts index 99633c1..7786e09 100644 --- a/src/api/KPI/api.kpis.ts +++ b/src/api/KPI/api.kpis.ts @@ -31,4 +31,5 @@ export default { kpiUserCapacity: `${KpiUser}/capacity`, KpiEvaluation, Kpiorg, + kpiEvaluationCheck:`${kpiEvaluation}/check`, }; diff --git a/src/modules/08_KPI/views/form.vue b/src/modules/08_KPI/views/form.vue index 3e9cff3..8b80236 100644 --- a/src/modules/08_KPI/views/form.vue +++ b/src/modules/08_KPI/views/form.vue @@ -21,17 +21,19 @@ const isReadonly = (route.name === "KPIEditEvaluator" ? true : false); const store = useKpiDataStore(); const $q = useQuasar(); const mixin = useCounterMixin(); -const { showLoader, hideLoader, messageError, dialogConfirm } = mixin; +const { showLoader, hideLoader, messageError, dialogConfirm, success } = mixin; const evaluatorIdOp = ref([]); const commanderIdOp = ref([]); const commanderHighOp = ref([]); -const formEva = reactive({ - evaluatorId: "", - commanderId: "", - commanderHighId: "", -}); +const evaluatorIdMainOp = ref([]); +const commanderIdMainOp = ref([]); +const commanderHighMainOp = ref([]); + +const evaluatorId = ref(); +const commanderId = ref(); +const commanderHighId = ref(); const formProfile = reactive({ fullName: "", @@ -56,7 +58,7 @@ function fetchEvaluation() { formProfile.status = store.convertStatus(data.evaluationStatus); formProfile.result = store.convertResults(data.evaluationResults); fetchProfile(data.profileId); - console.log(store.dataEvaluation) + console.log(store.dataEvaluation); }) .catch((e) => { messageError($q, e); @@ -113,22 +115,113 @@ function close() { modalEdit.value = false; } -function clearDialog() { +async function clearDialog() { modalEdit.value = false; - formEva.evaluatorId = ""; - formEva.commanderId = ""; - formEva.commanderHighId = ""; + evaluatorId.value = null; + commanderId.value = null; + commanderHighId.value = null; + await fetchEvaluation(); + await getProfile(); + await getOrgOp(); } function onSubmit() { dialogConfirm($q, () => { - clearDialog(); + showLoader(); + http + .put(config.API.kpiEvaluationCheck + `/${id.value}`, { + evaluatorId: evaluatorId.value.id, + commanderId: commanderId.value.id, + commanderHighId: commanderHighId.value.id, + }) + .then((res) => { + success($q, "บันทึกสำเร็จ"); + clearDialog(); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); }); } -onMounted(() => { - fetchEvaluation(); - getProfile(); +function getOrgOp() { + http + .get(config.API.Kpiorg) + .then((res) => { + const data = res.data.result; + evaluatorIdMainOp.value = data.caregiver.map((i: any) => ({ + id: i.id, + name: `${i.prefix}${i.firstName} ${i.lastName}`, + })); + commanderIdMainOp.value = data.commander.map((i: any) => ({ + id: i.id, + name: `${i.prefix}${i.firstName} ${i.lastName}`, + })); + commanderHighMainOp.value = data.chairman.map((i: any) => ({ + id: i.id, + name: `${i.prefix}${i.firstName} ${i.lastName}`, + })); + + evaluatorId.value = data.caregiver + .map((i: any) => ({ + id: i.id, + name: `${i.prefix}${i.firstName} ${i.lastName}`, + })) + .find((i: any) => i.id == store.dataEvaluation.evaluatorId); + commanderId.value = data.caregiver + .map((i: any) => ({ + id: i.id, + name: `${i.prefix}${i.firstName} ${i.lastName}`, + })) + .find((i: any) => i.id == store.dataEvaluation.commanderId); + commanderHighId.value = data.caregiver + .map((i: any) => ({ + id: i.id, + name: `${i.prefix}${i.firstName} ${i.lastName}`, + })) + .find((i: any) => i.id == store.dataEvaluation.commanderHighId); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => {}); +} + +function filterOption(val: any, update: Function, refData: string) { + switch (refData) { + case "evaluatorIdOp": + update(() => { + evaluatorIdOp.value = evaluatorIdMainOp.value.filter( + (v: any) => v.name.indexOf(val) > -1 + ); + }); + break; + case "commanderIdOp": + update(() => { + commanderIdOp.value = commanderIdMainOp.value.filter( + (v: any) => v.name.indexOf(val) > -1 + ); + }); + break; + case "commanderHighOp": + update(() => { + commanderHighOp.value = commanderHighMainOp.value.filter( + (v: any) => v.name.indexOf(val) > -1 + ); + }); + break; + default: + break; + } +} + +onMounted(async () => { + await fetchEvaluation(); + await getProfile(); + await getOrgOp(); }); @@ -148,7 +241,13 @@ onMounted(() => { isReadonly ? router.push(`/KPI-evaluator`) : router.push(`/KPI`) " /> - {{ id ? `แก้ไขแบบประเมิน` : `เพิ่มแบบประเมิน` }} + {{ + isReadonly + ? "รายละเอียดการประเมินผลการปฏิบัติราชการระดับบุคคล" + : id + ? `แก้ไขแบบประเมิน` + : `เพิ่มแบบประเมิน` + }}