From 4dfd5a139b8b1d78cfa8d6b6d587dec0d68922ce Mon Sep 17 00:00:00 2001 From: oat_dev Date: Fri, 19 Apr 2024 11:36:48 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=95=E0=B9=88=E0=B8=ADAPI=20=E0=B8=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/14_KPI/api.KPI.ts | 6 +- .../competency/02ListLinkPosition.vue | 191 +++++++++--------- .../14_KPI/interface/response/KpiGroup.ts | 7 + 3 files changed, 103 insertions(+), 101 deletions(-) create mode 100644 src/modules/14_KPI/interface/response/KpiGroup.ts diff --git a/src/api/14_KPI/api.KPI.ts b/src/api/14_KPI/api.KPI.ts index 2de431732..3e4aa0bdb 100644 --- a/src/api/14_KPI/api.KPI.ts +++ b/src/api/14_KPI/api.KPI.ts @@ -2,11 +2,13 @@ import env from "../index"; const KPI = `${env.API_URI}/kpi`; const kpiPeriod = `${env.API_URI}/kpi/period`; const kpiEvaluation = `${env.API_URI}/kpi/evaluation`; - +const kpiGroup = `${env.API_URI}/kpi/group`; export default { KPI, /** รอบการประเมินผล*/ kpiPeriod: `${kpiPeriod}`, kpiPeriodById: (id: string) => `${kpiPeriod}/${id}`, - kpiEvaluation + kpiEvaluation, + kpiGroup, + kpiGroupById: (id: string) => `${kpiGroup}/${id}` }; diff --git a/src/modules/14_KPI/components/competency/02ListLinkPosition.vue b/src/modules/14_KPI/components/competency/02ListLinkPosition.vue index 6d9c2e4f6..9deefd0b0 100644 --- a/src/modules/14_KPI/components/competency/02ListLinkPosition.vue +++ b/src/modules/14_KPI/components/competency/02ListLinkPosition.vue @@ -3,21 +3,19 @@ import { ref, onMounted } from "vue"; import type { QTableProps } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; import { useQuasar } from "quasar"; -import { useRouter } from "vue-router"; -import Header from "@/components/DialogHeader.vue"; +import dialogHeader from "@/components/DialogHeader.vue"; import type { DataOption } from "@/modules/14_KPI/interface/index/Main"; - +import type { ResponseObject } from "@/modules/14_KPI/interface/response/KpiGroup"; import http from "@/plugins/http"; import config from "@/app.config"; const modal = ref(false); -const router = useRouter(); -const rows = ref(); +const rows = ref([]); const groupName = ref(""); const editStatus = ref(false); - +const editId = ref(""); const competencyTypeOp = ref([ { id: "ID1", @@ -42,11 +40,11 @@ const competencyTypeOp = ref([ ]); const columns = ref([ { - name: "groupName", + name: "nameGroupKPI", align: "left", label: "รายการกลุ่มงาน", sortable: true, - field: "groupName", + field: "nameGroupKPI", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -56,71 +54,81 @@ const columns = ref([ const $q = useQuasar(); const mixin = useCounterMixin(); -const { dialogRemove, messageError, showLoader, hideLoader, success } = mixin; - -const competencyType = ref("ID1"); +const { + dialogRemove, + dialogConfirm, + showLoader, + hideLoader, + messageError, + success, +} = mixin; const filterKeyword = ref(""); -const visibleColumns = ref(["groupName"]); +const visibleColumns = ref(["nameGroupKPI"]); /** ดึงข้อมูล */ -async function getData() { - const data = [ - { - id: "ID1", - groupName: "กลุ่มงาน 1", - }, - { - id: "ID2", - groupName: "กลุ่มงาน 2", - }, - ]; - rows.value = data; - // showLoader(); - // await http - // .get(config.API.orgPrefix) - // .then(async (res) => { - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(() => { - // hideLoader(); - // }); +async function fetchData() { + showLoader(); + await http + .get(config.API.kpiGroup) + .then(async (res) => { + rows.value = res.data.result.data; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +async function addData() { + await http + .post(config.API.kpiGroup, { + nameGroupKPI: groupName.value, + }) + .then(() => { + fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .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(); - // }); + await http + .put(config.API.kpiGroupById(id), { + nameGroupKPI: groupName.value, + }) + .then(() => { + fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .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.kpiGroupById(id)) + .then(() => { + fetchData(); + success($q, "ลบข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } /** เปลี่ยนเป็นหน้าเพิ่มข้อมูล */ @@ -128,42 +136,38 @@ function onAdd() { modal.value = true; } -function close() { +function closeDialog() { modal.value = false; editStatus.value = false; - groupName.value = '' + groupName.value = ""; } function onEdit(data: any) { modal.value = true; editStatus.value = true; - groupName.value = data.groupName + groupName.value = data.nameGroupKPI; + editId.value = data.id; } -function onSubmit() { - console.log("save"); - close() +async function onSubmit() { + dialogConfirm( + $q, + async () => { + editStatus.value ? editData(editId.value) : addData(); + closeDialog(); + }, + "ยืนยันการบันทึกข้อมูล", + "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" + ); } onMounted(async () => { - getData(); + fetchData(); });