From eac1642da5ef31390d3e48cbe4a687d4467fe7af Mon Sep 17 00:00:00 2001 From: oat_dev Date: Fri, 22 Mar 2024 10:53:08 +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=8F=E0=B8=B4=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=9E=E0=B8=B4=E0=B9=80=E0=B8=A8=E0=B8=A9?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/registry/api.registry.ts | 25 +- .../04_PerformSpecialWork.vue | 321 +++++++++--------- .../04_PerformSpecialWorkHistory.vue | 17 +- .../interface/index/performSpecialWork.ts | 15 +- 4 files changed, 188 insertions(+), 190 deletions(-) diff --git a/src/api/registry/api.registry.ts b/src/api/registry/api.registry.ts index 233cd1f3f..8647a7385 100644 --- a/src/api/registry/api.registry.ts +++ b/src/api/registry/api.registry.ts @@ -92,12 +92,21 @@ profileNewFamilyByFamilyId: (familyId: string) => profileNewFamilyeHisByFamilyId: (familyId: string) => `${registryNew}family/history/${familyId}`, - // ข้อมูลครอบครัว - profileNewDiscipline: `${registryNew}discipline`, - profileNewDisciplineByProfileId: (profileId: string) => - `${registryNew}discipline/${profileId}`, - profileNewDisciplineByDisciplineId: (disciplineId: string) => - `${registryNew}discipline/${disciplineId}`, - profileNewDisciplineHisByDisciplineId: (disciplineId: string) => - `${registryNew}discipline/history/${disciplineId}`, + // วินัย +profileNewDiscipline: `${registryNew}discipline`, +profileNewDisciplineByProfileId: (profileId: string) => +`${registryNew}discipline/${profileId}`, +profileNewDisciplineByDisciplineId: (disciplineId: string) => +`${registryNew}discipline/${disciplineId}`, +profileNewDisciplineHisByDisciplineId: (disciplineId: string) => +`${registryNew}discipline/history/${disciplineId}`, + + // ปฏิบัติราชการพิเศษ +profileNewDuty: `${registryNew}duty`, +profileNewDutyByProfileId: (profileId: string) => +`${registryNew}duty/${profileId}`, +profileNewDutyByDutyId: (dutyId: string) => +`${registryNew}duty/${dutyId}`, +profileNewDutyHisByDutyId: (dutyId: string) => +`${registryNew}duty/history/${dutyId}`, }; diff --git a/src/modules/04_registryNew/components/detail/GovernmentInformation/04_PerformSpecialWork.vue b/src/modules/04_registryNew/components/detail/GovernmentInformation/04_PerformSpecialWork.vue index b55530391..8ce8c9cc3 100644 --- a/src/modules/04_registryNew/components/detail/GovernmentInformation/04_PerformSpecialWork.vue +++ b/src/modules/04_registryNew/components/detail/GovernmentInformation/04_PerformSpecialWork.vue @@ -4,7 +4,6 @@ import { useQuasar, type QTableProps } from "quasar"; import type { FormFilter, RequestItemsObject, - MyObjectRef, } from "@/modules/04_registryNew/interface/index/performSpecialWork"; import http from "@/plugins/http"; @@ -29,6 +28,7 @@ const { showLoader, hideLoader, success, + dialogRemove, } = mixin; const modal = ref(false); @@ -36,24 +36,21 @@ const edit = ref(false); const modalHistory = ref(false); const id = ref(""); -const dateStart = ref(null); -const dateEnd = ref(null); -const detail = ref(); -const reference = ref(); -const refCommandNo = ref(); -const refCommandDate = ref(null); const dateStartRef = ref(null); const dateEndRef = ref(null); const detailRef = ref(null); const referenceRef = ref(null); -const objectRef: MyObjectRef = { - dateStart: dateStartRef, - dateEnd: dateEndRef, - detail: detailRef, - reference: referenceRef, -}; +const dutyData = reactive({ + profileId: profileId.value, + dateStart: new Date(), + dateEnd: null, + detail: "", + reference: "", + refCommandNo: "", + refCommandDate: null, +}); const rows = ref([]); const filterKeyword = ref(""); @@ -92,6 +89,7 @@ const columns = ref([ field: "dateStart", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => date2Thai(v), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -103,6 +101,7 @@ const columns = ref([ field: "dateEnd", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => date2Thai(v), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -147,6 +146,7 @@ const columns = ref([ field: "refCommandDate", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => date2Thai(v), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -157,15 +157,17 @@ function openDialogAdd() { modal.value = true; } +/** กดแก้ไข */ function openDialogEdit(props: RequestItemsObject) { modal.value = true; - id.value = props.id; - dateStart.value = props.dateStart; - dateEnd.value = props.dateEnd; - detail.value = props.detail; - reference.value = props.reference; - refCommandNo.value = props.refCommandNo; - refCommandDate.value = props.refCommandDate; + edit.value = true; + id.value = props.id ? props.id : ""; + dutyData.dateStart = props.dateStart; + dutyData.dateEnd = props.dateEnd; + dutyData.detail = props.detail; + dutyData.reference = props.reference; + dutyData.refCommandNo = props.refCommandNo; + dutyData.refCommandDate = props.refCommandDate; } /** @@ -182,126 +184,102 @@ function closeDialog() { modal.value = false; edit.value = false; - dateStart.value = null; - dateEnd.value = null; - detail.value = ""; - reference.value = ""; - refCommandNo.value = ""; - refCommandDate.value = null; + dutyData.dateStart = new Date(); + dutyData.dateEnd = null; + dutyData.detail = ""; + dutyData.reference = ""; + dutyData.refCommandNo = ""; + dutyData.refCommandDate = null; } -function getData() { - // showLoader() - // http - // .get(config.API.??) - // .then((res)=>{ +/** fetch ข้อมูล */ +async function fetchData(id: string) { + showLoader(); + await http + .get(config.API.profileNewDutyByProfileId(id)) + .then(async (res) => { + rows.value = res.data.result; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} - // }) - // .catch((e)=>{ - // messageError($q,e) - // }).finally(()=>{ +/** เพิ่มข้อมูล */ - // }) - const data: RequestItemsObject[] = [ - { - dateStart: new Date("2024-02-15T00:00:00"), - dateEnd: new Date("2024-02-15T00:00:00"), - detail: "111", - reference: "111", - refCommandNo: "", - refCommandDate: null, - id: "08dc2e13-1c3f-4261-8168-30018e5d953c", +async function addData() { + await http + .post(config.API.profileNewDuty, dutyData) + .then(() => { + fetchData(profileId.value); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +/** แก้ไขข้อมูล */ + +async function editData(idData: string) { + await http + .patch(config.API.profileNewDutyByDutyId(idData), { + ...dutyData, + profileId: undefined, + }) + .then(() => { + fetchData(profileId.value); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +/** ลบข้อมูล */ + +function deleteData(idData: string) { + dialogRemove($q, () => + http + .delete(config.API.profileNewDutyByDutyId(idData)) + .then(() => { + fetchData(profileId.value); + success($q, "ลบข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }) + ); +} + +/** กด Submit */ + +async function onSubmit() { + dialogConfirm( + $q, + async () => { + edit.value ? editData(id.value) : addData(); + closeDialog(); }, - ]; - - rows.value = data; + "ยืนยันการบันทึกข้อมูล", + "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" + ); } -/** validate check*/ -function validateForm() { - const hasError = []; - for (const key in objectRef) { - if (Object.prototype.hasOwnProperty.call(objectRef, key)) { - const property = objectRef[key]; - if (property.value && typeof property.value.validate === "function") { - const isValid = property.value.validate(); - hasError.push(isValid); - } - } - } - if (hasError.every((result) => result === true)) { - if ((edit.value = false)) { - saveData(); - } else { - editData(); - } - } -} - -/** - * บันทึกเพิ่มข้อมูล - */ -function saveData() { - // showLoader(); - // await http - // .post(config.API.profileDutyId(profileId.value), { - // id: id.value, - // dateStart: dateToISO(dateStart.value), - // dateEnd: dateToISO(dateEnd.value), - // detail: detail.value, - // reference: reference.value, - // refCommandNo: refCommandNo.value, - // refCommandDate: - // refCommandDate.value == null - // ? null - // : dateToISO(refCommandDate.value as Date), - // }) - // .then((res) => { - // success($q, "บันทึกข้อมูลสำเร็จ"); - // modal.value = false; - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(async () => { - // await fetchData(); - // }); - closeDialog(); -} - -/** - * บันทึกแก้ไขข้อมูล - */ -const editData = async () => { - // showLoader(); - // await http - // .put(config.API.profileDutyId(id.value), { - // id: id.value, - // dateStart: dateToISO(dateStart.value), - // dateEnd: dateToISO(dateEnd.value), - // detail: detail.value, - // reference: reference.value, - // refCommandNo: refCommandNo.value, - // refCommandDate: - // refCommandDate.value == null - // ? null - // : dateToISO(refCommandDate.value as Date), - // }) - // .then((res) => { - // success($q, "บันทึกข้อมูลสำเร็จ"); - // modal.value = false; - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(async () => { - // await fetchData(); - // }); - closeDialog(); -}; - -onMounted(() => { - getData(); +onMounted(async () => { + await fetchData(profileId.value); }); @@ -553,7 +545,7 @@ onMounted(() => { -
+ @@ -564,7 +556,7 @@ onMounted(() => {
{ class="full-width inputgreen cursor-pointer" outlined dense - :model-value="date2Thai(dateStart)" + :model-value="date2Thai(dutyData.dateStart)" :rules="[(val) => !!val || `${'กรุณาเลือกวันที่เริ่มต้น'}`]" hide-bottom-space :label="`${'วันที่เริ่มต้น'}`" @@ -604,12 +596,12 @@ onMounted(() => {
@@ -619,11 +611,11 @@ onMounted(() => {