ขอแก้ไขทะเบียนประวัติ mapping และปรับ format ข้อมูล

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-11-11 16:12:58 +07:00
parent f36e8e720c
commit 0d769363a4
2 changed files with 97 additions and 28 deletions

View file

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

View file

@ -1,5 +1,5 @@
interface RequestObject {
birthDate: Date | null;
birthDate: Date | null | string;
bloodGroup: string | null;
citizenId: string;
// email: string | null;