From 8efa1c227ef1f4ae9a679ed29029c07e18f54187 Mon Sep 17 00:00:00 2001 From: "STW_TTTY\\stwtt" Date: Mon, 22 Apr 2024 09:28:14 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AA=E0=B8=A1=E0=B8=A3=E0=B8=A3=E0=B8=96?= =?UTF-8?q?=E0=B8=99=E0=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/14_KPI/api.KPI.ts | 3 + .../components/competency/03ListLinkGroup.vue | 230 ++++++++---------- 2 files changed, 98 insertions(+), 135 deletions(-) diff --git a/src/api/14_KPI/api.KPI.ts b/src/api/14_KPI/api.KPI.ts index 8eff14fdb..c2a3ea2c2 100644 --- a/src/api/14_KPI/api.KPI.ts +++ b/src/api/14_KPI/api.KPI.ts @@ -5,6 +5,7 @@ const kpiEvaluation = `${env.API_URI}/kpi/evaluation`; const kpiGroup = `${env.API_URI}/kpi/group`; const kpiPlan = `${env.API_URI}/kpi/plan`; const kpiCapacity = `${env.API_URI}/kpi/capacity`; +const kpiLink = `${env.API_URI}/kpi/link`; export default { KPI, /** รอบการประเมินผล*/ @@ -24,4 +25,6 @@ export default { /** สมรรถนะ */ kpiCapacity, + + kpiLink, }; diff --git a/src/modules/14_KPI/components/competency/03ListLinkGroup.vue b/src/modules/14_KPI/components/competency/03ListLinkGroup.vue index 8a2319136..bb73002a4 100644 --- a/src/modules/14_KPI/components/competency/03ListLinkGroup.vue +++ b/src/modules/14_KPI/components/competency/03ListLinkGroup.vue @@ -12,11 +12,12 @@ import type { ListGroup } from "@/modules/14_KPI/interface/request/Main"; import http from "@/plugins/http"; import config from "@/app.config"; +const id = ref(""); const modal = ref(false); const router = useRouter(); const rows = ref([]); const editStatus = ref(false); -const groupName = ref(""); +const groupName = ref(); const position = ref(null); const competency = ref(null); @@ -56,22 +57,22 @@ const columns = ref([ a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "position", + name: "positions", align: "left", label: "ตำแหน่ง", sortable: true, - field: "position", + field: "positions", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { - name: "competency", + name: "capacitys", align: "left", label: "สมรรถนะประจำกลุ่มงาน", sortable: true, - field: "competency", + field: "capacitys", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -81,131 +82,48 @@ const columns = ref([ const $q = useQuasar(); const mixin = useCounterMixin(); -const { dialogRemove, messageError, showLoader, hideLoader, success } = mixin; +const { + dialogRemove, + messageError, + showLoader, + hideLoader, + success, + dialogConfirm, +} = mixin; const competencyType = ref("ID1"); const filterKeyword = ref(""); -const visibleColumns = ref(["groupName", "position", "competency"]); +const visibleColumns = ref(["groupName", "positions", "capacitys"]); /** ดึงข้อมูล */ async function getData() { - const data = [ - { - id: "ID1", - groupName: "รายการสมรรถะ 1", - position: [ - { - id: "SUB1", - name: "นักจัดการงานทั่วไป", - }, - { - id: "SUB2", - name: "เจ้าพนักงานธุรการ", - }, - { - id: "SUB3", - name: "เจ้าพนักงานพัสดุ", - }, - { - id: "SUB4", - name: "นักวิชาการพัสดุ", - }, - ], - competency: [ - { - id: "SUB1", - name: "การจัดการและควบคุม", - }, - { - id: "SUB2", - name: "ความละเอียดรอบคอบ", - }, - { - id: "SUB3", - name: "การปรับตัวในการทำงานภายใต้ภาวะกดดัน", - }, - ], - }, - { - id: "ID2", - groupName: "รายการสมรรถะ 1", - position: [ - { - id: "SUB1", - name: "นักวิชาการสถิติ", - }, - { - id: "SUB2", - name: "เจ้าพนักงานสถิติ", - }, - { - id: "SUB3", - name: "เจ้าพนักงานเวชสถิติ", - }, - ], - competency: [ - { - id: "SUB1", - name: "การคิดวิเคราะห์", - }, - { - id: "SUB2", - name: "การสืบเสาะหาข้อมูล", - }, - { - id: "SUB3", - name: "ความละเอียดรอบคอบ", - }, - ], - }, - ]; - rows.value = data; - // showLoader(); - // await http - // .get(config.API.orgPrefix) - // .then(async (res) => { - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(() => { - // hideLoader(); - // }); -} - -async function editData(id: string) { - console.log(id); - // await http - // .put(config.API.orgPrefixId(id), { - // name: prefix.value, - // }) - // .then(() => { - // getData(); - // success($q, "บันทึกข้อมูลสำเร็จ"); - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(() => { - // hideLoader(); - // }); + showLoader(); + http + .get(config.API.kpiLink) + .then((res) => { + const data = res.data.result.data; + rows.value = data; + }) + .finally(() => { + hideLoader(); + }); } async function deleteData(id: string) { - console.log(id); - // await http - // .delete(config.API.orgPrefixId(id)) - // .then(() => { - // getData(); - // success($q, "ลบข้อมูลสำเร็จ"); - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(() => { - // hideLoader();w - // }); + await http + .delete(config.API.kpiLink + `/${id}`) + .then(() => { + success($q, "ลบข้อมูลสำเร็จ"); + close(); + getData(); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } /** ดึงข้อมูล */ @@ -256,20 +174,60 @@ function onAdd() { modal.value = true; } -function onEdit(data: any) { - getOptions(); + async function onEdit(data: any) { + id.value = data; + await getOptions(); + await getListGroup(); + await getCompetency(); + await getDataEdit(id.value); modal.value = true; editStatus.value = true; } +function getDataEdit(id: string) { + showLoader(); + http + .get(config.API.kpiLink + `/${id}`) + .then((res) => { + const data = res.data.result; + groupName.value = { + id:data.groupId, + name:data.groupName + } + position.value = data.positions.map((i:any) => i.name); + competency.value = data.capacitys.map((i:any) => i.id); + }) + .finally(() => { + hideLoader(); + }); +} + function onSubmit() { - console.log("save"); - close(); + const url = editStatus.value + ? config.API.kpiLink + `/${id.value}` + : config.API.kpiLink; + const body = { + kpiGroupId: groupName.value.id, + positions: position.value, + kpiCapacityIds: competency.value, + }; + dialogConfirm($q, () => { + http[editStatus.value ? "put" : "post"](url, body) + .then((res) => { + success($q, "บันทึกสำเร็จ"); + close(); + getData(); + }) + .finally(() => {}); + }); } function close() { modal.value = false; editStatus.value = false; + groupName.value = ""; + position.value = []; + competency.value = []; } function getOptions() { @@ -374,23 +332,24 @@ onMounted(async () => {