From 0d769363a460c76fd64307f1126dbbc7d51cbeaa Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 11 Nov 2024 16:12:58 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=82=E0=B8=AD=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B9=84=E0=B8=82=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=20mapping=20=E0=B9=81=E0=B8=A5=E0=B8=B0?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20format=20=E0=B8=82?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Dialog/DialogUpdate.vue | 123 ++++++++++++++---- .../interface/request/Profile.ts | 2 +- 2 files changed, 97 insertions(+), 28 deletions(-) diff --git a/src/modules/04_registryPerson/components/Dialog/DialogUpdate.vue b/src/modules/04_registryPerson/components/Dialog/DialogUpdate.vue index 45a403489..4d8b9bd18 100644 --- a/src/modules/04_registryPerson/components/Dialog/DialogUpdate.vue +++ b/src/modules/04_registryPerson/components/Dialog/DialogUpdate.vue @@ -10,6 +10,7 @@ import { useLinkageStore } from "@/stores/linkage"; import { useDataLinkCenter } from "@/modules/04_registryPerson/stores/LinkCenter"; import { useRequestEditStore } from "@/modules/04_registryPerson/stores/RequestEdit"; +import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main"; import type { RequestregistrationAddressObject } from "@/modules/04_registryPerson/interface/request/Address"; import type { RequestObject } from "@/modules/04_registryPerson/interface/request/Profile"; import type { @@ -256,7 +257,7 @@ async function amiRequest() { formInformations.nationality = data.value.nationalityDesc; // แปลง dateOfBirth เป็น format 1989-01-01 - formInformations.birthDate = data.value.dateOfBirth; + formInformations.birthDate = conventDateOfBirth(`${data.value.dateOfBirth}`); age.value = storeLinkCenter.calculateAge(data.value.age); formInformations.gender = data.value.genderDesc; @@ -273,15 +274,75 @@ async function amiRequest() { formDataAddress.registrationAddress = registrationAddress; // ค้นหา จังหวัด อำเภอ ตำบล และรหัสไปรษณื - // formDataAddress.registrationProvinceId = data.value.registrationProvinceId; - // formDataAddress.registrationDistrictId = data.value.registrationDistrictId; - // formDataAddress.registrationSubDistrictId = - // data.value.registrationSubDistrictId; + formDataAddress.registrationProvinceId = await convertProvince( + data.value.provinceDesc + ); + formDataAddress.registrationDistrictId = await convertDistrict( + data.value.districtDesc + ); + formDataAddress.registrationSubDistrictId = await convertSubdistrict( + data.value.subdistrictDesc + ); // formDataAddress.registrationZipCode = data.value.registrationZipCode; - console.log("province===>", data.value.provinceDesc); - console.log("district===>", data.value.districtDesc); - console.log("subdistrict===>", data.value.subdistrictDesc); + // console.log("province===>", data.value.provinceDesc); + // console.log("district===>", data.value.districtDesc); + // console.log("subdistrict===>", data.value.subdistrictDesc); +} + +/** + * ฟังก์ชันแปลง dateOfBirth เป็น format 1989-01-01 + * @param val dateOfBirth '25211228' + */ +function conventDateOfBirth(val: string) { + // Extract year, month, and day + const year = parseInt(val.slice(0, 4), 10) - 543; + const month = val.slice(4, 6); + const day = val.slice(6, 8); + + // Format as YYYY-MM-DD + return `${year}-${month}-${day}`; +} + +/** + * ฟังก์ชันแปลงชื่อจังหวัดเป็น ID + * @param val ชื่อจังหวัด + */ +async function convertProvince(val: string) { + const id = storeLinkCenter.OpsAddress.provinceOps.find( + (e: DataOption) => e.name === val + )?.id; + + // เรียกฟังก์ชันดึงข้อมูล เขต / อำเภอ + await storeLinkCenter.fetchDistrict(id ? id : null, "1", false); + + return id ? id : null; +} + +/** + * ฟังก์ชันแปลงชื่อเขต / อำเภอ เป็น ID + * @param val ชื่อเขต / อำเภอ + */ +async function convertDistrict(val: string) { + const id = storeLinkCenter.OpsAddress.districtOps.find( + (e: DataOption) => e.name === val + )?.id; + // เรียกฟังก์ชันดึงข้อมูล แขวง / ตำบล + await storeLinkCenter.fetchSubDistrict(id ? id : null, "1", false); + + return id ? id : null; +} + +/** + * ฟังก์ชันแปลงชื่อแขวง / ตำบล เป็น ID + * @param val ชื่อแขวง / ตำบล + */ +async function convertSubdistrict(val: string) { + const result = storeLinkCenter.OpsAddress.subdistrictOps.find( + (e: DataOption) => e.name === val + ); + formDataAddress.registrationZipCode = result ? result.zipCode : null; + return result ? result.id : null; } watch( @@ -291,29 +352,37 @@ watch( showLoader(); count.value = 0; await storeLinkCenter.fetchPerson(); + await storeLinkCenter.fetchProvince(false); await amiRequest(); presentAddress.value = formDataAddress.registrationZipCode ? "0" : "1"; - if ( - storeLinkCenter.OpsAddress.provinceOps.length === 0 || - storeLinkCenter.OpsAddress.districtOps.length === 0 || - storeLinkCenter.OpsAddress.districtCOps.length === 0 || - storeLinkCenter.OpsAddress.subdistrictOps.length === 0 || - storeLinkCenter.OpsAddress.subdistrictCOps.length === 0 - ) { - await storeLinkCenter.fetchProvince(false); - storeLinkCenter.fetchDistrict( - formDataAddress.registrationProvinceId, - "1", - false - ); - storeLinkCenter.fetchSubDistrict( - formDataAddress.registrationDistrictId, - "1", - false - ); - } + // if ( + // storeLinkCenter.OpsAddress.provinceOps.length === 0 || + // storeLinkCenter.OpsAddress.districtOps.length === 0 || + // storeLinkCenter.OpsAddress.districtCOps.length === 0 || + // storeLinkCenter.OpsAddress.subdistrictOps.length === 0 || + // storeLinkCenter.OpsAddress.subdistrictCOps.length === 0 + // ) { + // await storeLinkCenter.fetchProvince(false); + // storeLinkCenter.fetchDistrict( + // formDataAddress.registrationProvinceId, + // "1", + // false + // ); + // storeLinkCenter.fetchSubDistrict( + // formDataAddress.registrationDistrictId, + // "1", + // false + // ); + // } hideLoader(); + } else { + age.value = ""; + formDataAddress.registrationAddress = ""; + formDataAddress.registrationProvinceId = null; + formDataAddress.registrationDistrictId = null; + formDataAddress.registrationSubDistrictId = null; + formDataAddress.registrationZipCode = null; } } ); diff --git a/src/modules/04_registryPerson/interface/request/Profile.ts b/src/modules/04_registryPerson/interface/request/Profile.ts index fcd9e6232..c4f49124c 100644 --- a/src/modules/04_registryPerson/interface/request/Profile.ts +++ b/src/modules/04_registryPerson/interface/request/Profile.ts @@ -1,5 +1,5 @@ interface RequestObject { - birthDate: Date | null; + birthDate: Date | null | string; bloodGroup: string | null; citizenId: string; // email: string | null;