From f3f7bbf5c8ebd79a08fad2947a65e8e6fcaf187a Mon Sep 17 00:00:00 2001 From: puriphatt Date: Fri, 22 Mar 2024 12:49:50 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5?= =?UTF-8?q?=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=B4:=20=E0=B8=9C=E0=B8=A5=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B9=80=E0=B8=A1=E0=B8=B4?= =?UTF-8?q?=E0=B8=99=E0=B8=9B=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Achievement/05_ResultsPerformance.vue | 164 +++++++----------- .../interface/request/ResultsPerformance.ts | 16 +- .../stores/ResultsPerformance.ts | 27 +++ 3 files changed, 92 insertions(+), 115 deletions(-) create mode 100644 src/modules/04_registryNew/stores/ResultsPerformance.ts diff --git a/src/modules/04_registryNew/components/detail/Achievement/05_ResultsPerformance.vue b/src/modules/04_registryNew/components/detail/Achievement/05_ResultsPerformance.vue index 60fe26374..7f86cb3b2 100644 --- a/src/modules/04_registryNew/components/detail/Achievement/05_ResultsPerformance.vue +++ b/src/modules/04_registryNew/components/detail/Achievement/05_ResultsPerformance.vue @@ -7,17 +7,17 @@ import config from "@/app.config"; import type { QTableProps, QForm } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; +import { useResultsPerformDataStore } from "@/modules/04_registryNew/stores/ResultsPerformance"; import HistoryTable from "@/components/TableHistory.vue"; import DialogHeader from "@/components/DialogHeader.vue"; -import type { - RequestItemsObject, - FormData, -} from "@/modules/04_registryNew/interface/request/ResultsPerformance"; -import type { ResponseObject } from "@/modules/04_registry/interface/response/Assessment"; +import type { RequestItemsObject } from "@/modules/04_registryNew/interface/request/ResultsPerformance"; +import type { ResponseObject } from "@/modules/04_registryNew/interface/response/ResultsPerformance"; const $q = useQuasar(); const route = useRoute(); +const store = useResultsPerformDataStore(); +const { textRangePoint, textPoint } = store; const mixin = useCounterMixin(); const { date2Thai, @@ -32,9 +32,8 @@ const profileId = ref( route.params.id ? route.params.id.toString() : "" ); -const resPerformData = reactive({ - id: "", - isActive: true, +const id = ref(""); +const resPerformForm = reactive({ name: "", point1Total: 0, point1: 0, @@ -46,7 +45,6 @@ const resPerformData = reactive({ }); const isEdit = ref(false); -const editRow = ref(false); const myForm = ref(); const modal = ref(false); const modelView = ref("table"); @@ -291,20 +289,12 @@ async function addEditData(editStatus: boolean = false) { if (!profileId.value) return; const url = editStatus - ? config.API.profileNewAssessmentsById(resPerformData.id) + ? config.API.profileNewAssessmentsById(id.value) : config.API.profileNewAssessments; const method = editStatus ? "patch" : "post"; const reqBody: RequestItemsObject = { + ...resPerformForm, profileId: editStatus ? undefined : profileId.value, - isActive: resPerformData.isActive, - name: resPerformData.name, - date: resPerformData.date, - point1: resPerformData.point1, - point1Total: resPerformData.point1Total, - point2: resPerformData.point2, - point2Total: resPerformData.point2Total, - pointSum: resPerformData.pointSum, - pointSumTotal: resPerformData.pointSumTotal, }; try { @@ -318,54 +308,41 @@ async function addEditData(editStatus: boolean = false) { } } -async function clickDelete(dataId: string) { - try { - await http.delete(config.API.profileNewAssessmentsById(dataId)); - success($q, "ลบข้อมูลสำเร็จ"); - await fetchData(); - modal.value = false; - } catch (error) { - messageError($q, error); - } finally { - hideLoader(); - } -} +// async function clickDelete(dataId: string) { +// try { +// await http.delete(config.API.profileNewAssessmentsById(dataId)); +// success($q, "ลบข้อมูลสำเร็จ"); +// await fetchData(); +// modal.value = false; +// } catch (error) { +// messageError($q, error); +// } finally { +// hideLoader(); +// } +// } function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) { modal.value = true; - editRow.value = false; isEdit.value = editStatus; if (editStatus && row) { - Object.assign(resPerformData, row); + id.value = row.id; + resPerformForm.name = row.name; + resPerformForm.point1Total = row.point1Total; + resPerformForm.point1 = row.point1; + resPerformForm.point2Total = row.point2Total; + resPerformForm.point2 = row.point2; + resPerformForm.pointSumTotal = row.pointSumTotal; + resPerformForm.pointSum = row.pointSum; + resPerformForm.date = row.date; } else { - (resPerformData.id = ""), - (resPerformData.isActive = true), - (resPerformData.name = ""), - (resPerformData.point1Total = 0), - (resPerformData.point1 = 0), - (resPerformData.point2Total = 0), - (resPerformData.point2 = 0), - (resPerformData.pointSumTotal = 0), - (resPerformData.pointSum = 0), - (resPerformData.date = null); + clearData(); } } async function clickClose() { - if (editRow.value == true) { - dialogConfirm( - $q, - async () => { - modal.value = false; - editRow.value = false; - }, - "ข้อมูลมีการแก้ไข", - "ยืนยันที่จะปิดโดยไม่บันทึกใช่หรือไม่?" - ); - } else { - modal.value = false; - } + clearData(); + modal.value = false; } async function clickHistory(row: ResponseObject) { @@ -375,8 +352,7 @@ async function clickHistory(row: ResponseObject) { showLoader(); try { const res = await http.get(config.API.profileNewAssessmentsHisById(row.id)); - console.log(res.data); - + rowsHistory.value = res.data.result; } catch (e) { messageError($q, e); @@ -401,24 +377,16 @@ function onSubmit() { ); } -function textRangePoint(val: number | undefined) { - if (val == undefined) val = -1; - if (val >= 0 && val <= 60) return "(ต่ำกว่าร้อยละ 60)"; - if (val >= 60 && val <= 69) return "(ร้อยละ 60 – 69)"; - if (val >= 70 && val <= 79) return "(ร้อยละ 70 – 79)"; - if (val >= 80 && val <= 89) return "(ร้อยละ 80 – 89)"; - if (val >= 90 && val <= 100) return "(ร้อยละ 90 - 100)"; - else return ""; -} - -function textPoint(val: number | undefined) { - if (val == undefined) val = -1; - if (val >= 0 && val <= 60) return "ต้องปรับปรุง"; - if (val >= 60 && val <= 69) return "พอใช้"; - if (val >= 70 && val <= 79) return "ดี"; - if (val >= 80 && val <= 89) return "ดีมาก"; - if (val >= 90 && val <= 100) return "ดีเด่น"; - else return "-"; +function clearData() { + (id.value = ""), + (resPerformForm.name = ""), + (resPerformForm.point1Total = 0), + (resPerformForm.point1 = 0), + (resPerformForm.point2Total = 0), + (resPerformForm.point2 = 0), + (resPerformForm.pointSumTotal = 0), + (resPerformForm.pointSum = 0), + (resPerformForm.date = null); } onMounted(async () => { @@ -621,7 +589,10 @@ onMounted(async () => { - +
@@ -631,7 +602,7 @@ onMounted(async () => { borderless week-start="0" menu-class-name="modalfix" - v-model="resPerformData.date" + v-model="resPerformForm.date" :locale="'th'" :enableTimePicker="false" > @@ -649,10 +620,9 @@ onMounted(async () => { ref="dateReceivedRef" class="inputgreen" hide-bottom-space - :model-value="date2Thai(resPerformData.date as Date)" + :model-value="date2Thai(resPerformForm.date as Date)" :label="`${'วันที่ได้รับ'}`" :rules="[(val) => !!val || `${'กรุณาเลือกวันที่ได้รับ'}`]" - @update:modelValue="() => (editRow = true)" >