From 0530b48406f5875d2f35e6f0ee83566464393707 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Fri, 29 Mar 2024 10:17:44 +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=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1field=E0=B8=A2=E0=B8=A8+=E0=B8=A7=E0=B8=B1=E0=B8=99?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99=E0=B8=9B=E0=B8=B5?= =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B8=B4=E0=B8=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/DialogAddData.vue | 175 ++++++++++++++---- .../04_registryNew/interface/request/Main.ts | 2 + 2 files changed, 145 insertions(+), 32 deletions(-) diff --git a/src/modules/04_registryNew/components/DialogAddData.vue b/src/modules/04_registryNew/components/DialogAddData.vue index 744c3c15b..909e18506 100644 --- a/src/modules/04_registryNew/components/DialogAddData.vue +++ b/src/modules/04_registryNew/components/DialogAddData.vue @@ -10,13 +10,14 @@ import type { FormAddPerson, MyObjectRef, } from "@/modules/04_registryNew/interface/request/Main"; - +import { useProfileDataStore } from "@/modules/04_registryNew/stores/profile"; import DialogHeader from "@/components/DialogHeader.vue"; /** importStore*/ import { useRegistryNewDataStore } from "@/modules/04_registryNew/store"; import { useCounterMixin } from "@/stores/mixin"; +const profileStore = useProfileDataStore(); const $q = useQuasar(); const store = useRegistryNewDataStore(); const { @@ -27,8 +28,9 @@ const { showLoader, hideLoader, dialogMessageNotify, + date2Thai, } = useCounterMixin(); - +const { calculateAge } = profileStore; const modal = defineModel("modal", { required: true }); const props = defineProps({ @@ -37,8 +39,9 @@ const props = defineProps({ }); const prefixOps = ref([]); +const rankOps = ref([]); const levelOps = ref([]); - +const age = ref(""); const formData = reactive({ prefix: "", firstName: "", @@ -47,6 +50,8 @@ const formData = reactive({ position: "", posTypeId: "", posLevelId: "", + rank: "", + birthDate: null, }); const prefixRef = ref(null); @@ -80,6 +85,19 @@ function fetchPrefix() { messageError($q, err); }); } +function fetchRank() { + http + .get(config.API.orgRank) + .then((res) => { + rankOps.value = res.data.result.map((v: any) => ({ + id: v.name, + name: v.name, + })); + }) + .catch((err) => { + messageError($q, err); + }); +} /** * function ตรวจสอบเลขประจำตัวประชาชน @@ -129,6 +147,9 @@ function clearFormData() { formData.position = ""; formData.posTypeId = ""; formData.posLevelId = ""; + formData.rank = ""; + age.value = ""; + formData.birthDate = null; } function validateForm() { @@ -148,20 +169,21 @@ function validateForm() { } async function onSubmit() { - showLoader(); - await http - .post(config.API.registryNew, formData) - .then(() => { - success($q, "บันทึกข้อมูลสำเร็จ"); - props.fetchData?.(); - closeDialog(); - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); + dialogConfirm($q, async () => { + await http + .post(config.API.registryNew, formData) + .then(() => { + success($q, "บันทึกข้อมูลสำเร็จ"); + props.fetchData?.(); + closeDialog(); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); + }); } watch( @@ -169,10 +191,20 @@ watch( () => { if (modal.value) { fetchPrefix(); + fetchRank(); props.fetchType?.(); } } ); + +watch( + () => formData.birthDate, + (v) => { + if (v) { + age.value = calculateAge(v); + } + } +);