ขอแก้ไขทะเบียนประวัติ mapping และปรับ format ข้อมูล
This commit is contained in:
parent
f36e8e720c
commit
0d769363a4
2 changed files with 97 additions and 28 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
interface RequestObject {
|
||||
birthDate: Date | null;
|
||||
birthDate: Date | null | string;
|
||||
bloodGroup: string | null;
|
||||
citizenId: string;
|
||||
// email: string | null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue