From 0d7f6cdbde63b6aeb3f59274d17c903cd3d0ee50 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Fri, 22 Mar 2024 19:26:32 +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=9B=E0=B8=A3=E0=B8=B0=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A8=E0=B9=80=E0=B8=81=E0=B8=B5=E0=B8=A2=E0=B8=A3?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=E0=B8=84=E0=B8=B8=E0=B8=93=20(refactor)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Achievement/04_DeclarationHonor.vue | 159 ++++++++---------- .../interface/request/DeclarationHonor.ts | 30 +--- 2 files changed, 68 insertions(+), 121 deletions(-) diff --git a/src/modules/04_registryNew/components/detail/Achievement/04_DeclarationHonor.vue b/src/modules/04_registryNew/components/detail/Achievement/04_DeclarationHonor.vue index 7e0796b33..93e6c99fa 100644 --- a/src/modules/04_registryNew/components/detail/Achievement/04_DeclarationHonor.vue +++ b/src/modules/04_registryNew/components/detail/Achievement/04_DeclarationHonor.vue @@ -10,7 +10,6 @@ import { useCounterMixin } from "@/stores/mixin"; import HistoryTable from "@/components/TableHistory.vue"; import DialogHeader from "@/components/DialogHeader.vue"; import type { RequestItemsObject } from "@/modules/04_registryNew/interface/request/DeclarationHonor"; -import type { FormData } from "@/modules/04_registryNew/interface/request/DeclarationHonor"; import type { ResponseObject } from "@/modules/04_registryNew/interface/response/DeclarationHonor"; const $q = useQuasar(); @@ -29,20 +28,18 @@ const profileId = ref( route.params.id ? route.params.id.toString() : "" ); -const declHonorData = reactive({ - id: "", - isActive: true, +const id = ref(""); +const issueDateYear = ref(0); +const declHonorForm = reactive({ isDate: "false", issuer: "", detail: "", issueDate: null, - issueDateYear: 0, refCommandNo: "", refCommandDate: null, }); const isEdit = ref(false); -const editRow = ref(false); const myForm = ref(); const modal = ref(false); const modelView = ref("table"); @@ -234,21 +231,17 @@ async function addEditData(editStatus: boolean = false) { if (!profileId.value) return; const url = editStatus - ? config.API.profileNewHonorById(declHonorData.id) + ? config.API.profileNewHonorById(id.value) : config.API.profileNewHonor; const method = editStatus ? "patch" : "post"; const reqBody: RequestItemsObject = { + ...declHonorForm, profileId: editStatus ? undefined : profileId.value, - isActive: declHonorData.isActive, - detail: declHonorData.detail, + isDate: declHonorForm.isDate === "true" ? true : false, issueDate: - declHonorData.isDate === "true" - ? declHonorData.issueDate - : new Date(`${declHonorData.issueDateYear}-01-01`), - issuer: declHonorData.issuer, - refCommandDate: declHonorData.refCommandDate, - refCommandNo: declHonorData.refCommandNo, - isDate: declHonorData.isDate === "true" ? true : false, + declHonorForm.isDate === true + ? declHonorForm.issueDate + : new Date(`${issueDateYear.value}-01-01`), }; try { @@ -262,57 +255,41 @@ async function addEditData(editStatus: boolean = false) { } } -async function clickDelete(dataId: string) { - try { - await http.delete(config.API.profileNewHonorById(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.profileNewHonorById(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(declHonorData, row); - declHonorData.isDate = row.isDate.toString(); - declHonorData.issueDate = row.issueDate; - declHonorData.issueDateYear = new Date(row.issueDate).getFullYear(); - declHonorData.refCommandDate = row.refCommandDate; + id.value = row.id; + + issueDateYear.value = new Date(row.issueDate).getFullYear(); + declHonorForm.issuer = row.issuer; + declHonorForm.detail = row.detail; + declHonorForm.issueDate = row.issueDate; + declHonorForm.refCommandNo = row.refCommandNo; + declHonorForm.refCommandDate = row.refCommandDate; + declHonorForm.isDate = row.isDate ? "true" : "false"; } else { - declHonorData.id = ""; - declHonorData.isActive = true; - declHonorData.issuer = ""; - declHonorData.detail = ""; - declHonorData.issueDate = null; - declHonorData.issueDateYear = 0; - declHonorData.refCommandNo = ""; - declHonorData.refCommandDate = null; - declHonorData.isDate = "false"; + 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) { @@ -334,30 +311,37 @@ function onSubmit() { dialogConfirm( $q, async () => { - myForm.value?.validate().then(async (result: boolean) => { - if (result) { - addEditData(isEdit.value); - modal.value = false; - } - }); + addEditData(isEdit.value); + modal.value = false; }, "ยืนยันการบันทึกข้อมูล", "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" ); } +function clearData() { + id.value = ""; + issueDateYear.value = 0; + declHonorForm.issuer = ""; + declHonorForm.detail = ""; + declHonorForm.issueDate = null; + declHonorForm.refCommandNo = ""; + declHonorForm.refCommandDate = null; + declHonorForm.isDate = "false"; +} + onMounted(async () => { await fetchData(); }); watch( - () => declHonorData.isDate, + () => declHonorForm.isDate, () => { - if (declHonorData.isDate === "true") { - declHonorData.issueDateYear = 0; + if (declHonorForm.isDate === "true") { + issueDateYear.value = 0; } - if (declHonorData.isDate === "false") { - declHonorData.issueDate = null; + if (declHonorForm.isDate === "false") { + declHonorForm.issueDate = null; } } ); @@ -557,14 +541,14 @@ watch( - +