From c145962c72364513c285630a37076e17a9aa9ec1 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Fri, 22 Mar 2024 09:31:35 +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=A7=E0=B8=B4=E0=B8=99=E0=B8=B1?= =?UTF-8?q?=E0=B8=A2=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/registry/api.registry.ts | 11 +- .../GovernmentInformation/02_Discipline.vue | 392 +++++++++--------- .../02_DisciplineHistory.vue | 15 +- 3 files changed, 201 insertions(+), 217 deletions(-) diff --git a/src/api/registry/api.registry.ts b/src/api/registry/api.registry.ts index 185ebf009..233cd1f3f 100644 --- a/src/api/registry/api.registry.ts +++ b/src/api/registry/api.registry.ts @@ -91,4 +91,13 @@ profileNewFamilyByFamilyId: (familyId: string) => `${registryNew}family/${familyId}`, 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}`, +}; diff --git a/src/modules/04_registryNew/components/detail/GovernmentInformation/02_Discipline.vue b/src/modules/04_registryNew/components/detail/GovernmentInformation/02_Discipline.vue index cbec7399f..c94a0e8f8 100644 --- a/src/modules/04_registryNew/components/detail/GovernmentInformation/02_Discipline.vue +++ b/src/modules/04_registryNew/components/detail/GovernmentInformation/02_Discipline.vue @@ -30,8 +30,17 @@ const { messageError, success, dateToISO, + dialogRemove, } = mixin; - +const disciplineData = reactive({ + date: new Date(), + level: "", + detail: "", + unStigma: "", + refCommandNo: "", + profileId: profileId.value, + refCommandDate: null, +}); const rows = ref([]); const mode = ref("table"); const filterKeyword = ref(""); @@ -66,6 +75,7 @@ const columns = ref([ label: "วัน เดือน ปี", sortable: true, field: "date", + format: (v) => date2Thai(v), headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -121,6 +131,7 @@ const columns = ref([ label: "เอกสารอ้างอิง (ลงวันที่)", sortable: true, field: "refCommandDate", + format: (v) => date2Thai(v), headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -218,18 +229,82 @@ function filterSelector(val: string, update: Function, refData: string) { function closeDialog() { modal.value = false; edit.value = false; - - date.value = null; - detail.value = ""; - level.value = ""; - unStigma.value = ""; - refCommandNo.value = ""; - refCommandDate.value = null; + disciplineData.date = null; + disciplineData.detail = ""; + disciplineData.level = ""; + disciplineData.unStigma = ""; + disciplineData.refCommandNo = ""; + disciplineData.refCommandDate = null; } function openDialogAdd() { modal.value = true; } + +async function fetchData(id: string) { + showLoader(); + await http + .get(config.API.profileNewDisciplineByProfileId(id)) + .then(async (res) => { + console.log(res.data.result); + rows.value = res.data.result; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +async function addData() { + await http + .post(config.API.profileNewDiscipline, disciplineData) + .then(() => { + fetchData(profileId.value); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +async function editData(idData: string) { + await http + .patch(config.API.profileNewDisciplineByDisciplineId(idData), { + ...disciplineData, + 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.profileNewDisciplineByDisciplineId(idData)) + .then(() => { + fetchData(profileId.value); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }) + ); +} /** * กดเลือกข้อมูลที่จะแก้ไข * @param props ค่า props ใน row ที่เลือก @@ -240,184 +315,80 @@ function openDialogEdit(props: RequestItemsObject) { console.log(props); id.value = props.id; - date.value = props.date; - detail.value = props.detail; - level.value = props.level; - unStigma.value = props.unStigma; - refCommandNo.value = props.refCommandNo; - refCommandDate.value = props.refCommandDate; + disciplineData.date = props.date; + disciplineData.detail = props.detail; + disciplineData.level = props.level; + disciplineData.unStigma = props.unStigma; + disciplineData.refCommandNo = props.refCommandNo; + disciplineData.refCommandDate = props.refCommandDate; } -/** 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.profileDisId(profileId.value), { - // id: id.value, - // level: level.value, - // detail: detail.value, - // unStigma: unStigma.value, - // refCommandNo: refCommandNo.value, - // refCommandDate: - // refCommandDate.value == null - // ? null - // : dateToISO(refCommandDate.value as Date), - // date: dateToISO(date.value), - // }) - // .then((res) => { - // success($q, "บันทึกข้อมูลสำเร็จ"); - // closeDialog() - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(async () => { - // await fetchData(); - // }); - closeDialog(); -} - -/** - * บันทึกแก้ไขข้อมูล - */ -const editData = async () => { - // showLoader(); - // await http - // .put(config.API.profileDisId(id.value), { - // id: id.value, - // level: level.value, - // detail: detail.value, - // unStigma: unStigma.value, - // refCommandNo: refCommandNo.value, - // refCommandDate: - // refCommandDate.value == null - // ? null - // : dateToISO(refCommandDate.value as Date), - // date: dateToISO(date.value as Date), - // }) - // .then((res) => { - // success($q, "บันทึกข้อมูลสำเร็จ"); - // modal.value = false; - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(async () => { - // await fetchData(); - // }); - closeDialog(); -}; - -/** - * ฟังชั้นดูข้อมูลประวัติแก้ไขข้อมูลที่เลือก - * @param row ข้อมูล row ที่ดูประวัติการแก้ไข - */ function openDialogHistory(idOrder: string) { modalHistory.value = true; id.value = idOrder; } -function getData() { - // showLoader(); - // http - // .get(config.API.profileDisId(profileId.value)) - // .then((res) => { - // let data = res.data.result; - // console.log(data); - // rows.value = []; - // data.map((e: RequestItemsObject) => { - // rows.value.push({ - // id: e.id, - // level: e.level, - // detail: e.detail, - // unStigma: e.unStigma, - // refCommandNo: e.refCommandNo, - // refCommandDate: e.refCommandDate ? new Date(e.refCommandDate) : null, - // date: e.date, - // createdFullName: e.createdFullName, - // createdAt: e.createdAt, - // }); - // }); - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(() => {}); - - const data: RequestItemsObject[] = [ - { - level: "ภาคทัณฑ์", - detail: "1", - refCommandNo: "1", - refCommandDate: null, - date: new Date("2024-03-19T00:00:00"), - unStigma: "1", - id: "08dc2e0f-5631-4a7c-8ac4-0f7c99156c2e", - createdAt: new Date("2024-02-15T17:17:38.524861"), - createdFullName: "สาวิตรี ศรีสมัย", +async function onSubmit() { + dialogConfirm( + $q, + async () => { + edit.value ? editData(id.value) : addData(); + closeDialog(); }, - { - level: "ภาคทัณฑ์", - detail: "11", - refCommandNo: "11", - refCommandDate: new Date("2024-03-11T00:00:00"), - date: new Date("2024-02-20T00:00:00"), - unStigma: "", - id: "08dc2e11-3588-44ea-8c1a-99109a4c4fe0", - createdAt: new Date("2024-02-20T12:59:47.193103"), - createdFullName: "สาวิตรี ศรีสมัย", - }, - { - level: "ตัดเงินเดือน", - detail: "115", - refCommandNo: "1", - refCommandDate: new Date("2024-03-11T00:00:00"), - date: new Date("2024-02-20T00:00:00"), - unStigma: "11", - id: "08dc2e11-8054-416c-8299-81005d739a25", - createdAt: new Date("2024-02-20T12:59:47.193103"), - createdFullName: "สาวิตรี ศรีสมัย", - }, - { - level: "", - detail: "test", - refCommandNo: "12", - refCommandDate: new Date("2024-03-11T00:00:00"), - date: new Date("2024-02-20T00:00:00"), - unStigma: "", - id: "08dc31d9-24a0-4870-896c-4c4ea8f7b104", - createdAt: new Date("2024-02-20T12:59:47.193103"), - createdFullName: "สาวิตรี ศรีสมัย", - }, - ]; - rows.value = data; + "ยืนยันการบันทึกข้อมูล", + "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" + ); } +// const data: RequestItemsObject[] = [ +// { +// level: "ภาคทัณฑ์", +// detail: "1", +// refCommandNo: "1", +// refCommandDate: null, +// date: new Date("2024-03-19T00:00:00"), +// unStigma: "1", +// id: "08dc2e0f-5631-4a7c-8ac4-0f7c99156c2e", +// createdAt: new Date("2024-02-15T17:17:38.524861"), +// createdFullName: "สาวิตรี ศรีสมัย", +// }, +// { +// level: "ภาคทัณฑ์", +// detail: "11", +// refCommandNo: "11", +// refCommandDate: new Date("2024-03-11T00:00:00"), +// date: new Date("2024-02-20T00:00:00"), +// unStigma: "", +// id: "08dc2e11-3588-44ea-8c1a-99109a4c4fe0", +// createdAt: new Date("2024-02-20T12:59:47.193103"), +// createdFullName: "สาวิตรี ศรีสมัย", +// }, +// { +// level: "ตัดเงินเดือน", +// detail: "115", +// refCommandNo: "1", +// refCommandDate: new Date("2024-03-11T00:00:00"), +// date: new Date("2024-02-20T00:00:00"), +// unStigma: "11", +// id: "08dc2e11-8054-416c-8299-81005d739a25", +// createdAt: new Date("2024-02-20T12:59:47.193103"), +// createdFullName: "สาวิตรี ศรีสมัย", +// }, +// { +// level: "", +// detail: "test", +// refCommandNo: "12", +// refCommandDate: new Date("2024-03-11T00:00:00"), +// date: new Date("2024-02-20T00:00:00"), +// unStigma: "", +// id: "08dc31d9-24a0-4870-896c-4c4ea8f7b104", +// createdAt: new Date("2024-02-20T12:59:47.193103"), +// createdFullName: "สาวิตรี ศรีสมัย", +// }, +// ]; +// rows.value = data; -onMounted(() => { - getData(); +onMounted(async () => { + await fetchData(profileId.value); }); @@ -673,7 +660,7 @@ onMounted(() => { -
+ @@ -684,7 +671,7 @@ onMounted(() => {
{ class="full-width inputgreen cursor-pointer" outlined dense - :model-value="date2Thai(date)" + :model-value="date2Thai(disciplineData.date)" :rules="[(val:string) => !!val || `${'กรุณาเลือก วัน/เดือน/ปี'}`]" hide-bottom-space :label="`${'วัน/เดือน/ปี'}`" @@ -728,7 +715,7 @@ onMounted(() => { outlined dense lazy-rules - v-model="detail" + v-model="disciplineData.detail" :rules="[(val:string) => !!val || `${'กรุณากรอกรายละเอียด'}`]" hide-bottom-space :label="`${'รายละเอียด'}`" @@ -740,7 +727,7 @@ onMounted(() => { outlined dense lazy-rules - v-model="level" + v-model="disciplineData.level" :label="`${'ระดับการลงโทษทางวินัย'}`" emit-value map-options @@ -759,7 +746,7 @@ onMounted(() => { class="full-width inputgreen cursor-pointer" outlined dense - v-model="unStigma" + v-model="disciplineData.unStigma" hide-bottom-space :label="`${'ล้างมลทิน'}`" /> @@ -771,7 +758,7 @@ onMounted(() => { outlined dense lazy-rules - v-model="refCommandNo" + v-model="disciplineData.refCommandNo" hide-bottom-space :label="`${'เลขที่คำสั่ง'}`" :rules="[(val:string) => !!val || `${'กรุณากรอกเลขที่คำสั่ง'}`]" @@ -784,7 +771,7 @@ onMounted(() => {
{ }} @@ -844,7 +824,7 @@ onMounted(() => { บันทึกข้อมูล - + diff --git a/src/modules/04_registryNew/components/detail/GovernmentInformation/02_DisciplineHistory.vue b/src/modules/04_registryNew/components/detail/GovernmentInformation/02_DisciplineHistory.vue index ced437e0f..371a1ac17 100644 --- a/src/modules/04_registryNew/components/detail/GovernmentInformation/02_DisciplineHistory.vue +++ b/src/modules/04_registryNew/components/detail/GovernmentInformation/02_DisciplineHistory.vue @@ -55,6 +55,7 @@ const columns = ref([ field: "date", 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" }), }, @@ -107,6 +108,7 @@ const columns = ref([ align: "left", label: "เอกสารอ้างอิง (ลงวันที่)", sortable: true, + format: (v) => date2Thai(v), field: "refCommandDate", headerStyle: "font-size: 14px", style: "font-size: 14px", @@ -130,6 +132,7 @@ const columns = ref([ label: "วันที่แก้ไข", sortable: true, field: "createdAt", + format: (v) => date2Thai(v), headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -139,8 +142,9 @@ const columns = ref([ function getHistory() { showLoader(); http - .get(config.API.profileDisHisId(id.value)) + .get(config.API.profileNewDisciplineHisByDisciplineId(id.value)) .then((res) => { + console.log(res.data.result); let data = res.data.result; rows.value = []; data.map((e: RequestItemsObject) => { @@ -259,15 +263,6 @@ watch(modal, (status) => { 1 }}
-
- {{ col.value == null ? null : date2Thai(col.value) }} -
{{ col.value ? col.value : "-" }}