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); + } + } +);