diff --git a/src/api/registry/api.registry.ts b/src/api/registry/api.registry.ts index b23bb1ee7..081275570 100644 --- a/src/api/registry/api.registry.ts +++ b/src/api/registry/api.registry.ts @@ -10,10 +10,9 @@ export default { // metadata profileNewMetaMain: `${metadata}main/person`, - profileNewGender: `${metadata}gender`, - profileNewReligion: `${metadata}religion`, - profileNewRelationship: `${metadata}relationship`, - profileNewBloodGroup: `${metadata}bloodGroup`, + profileNewProvince: `${metadata}province`, + profileNewDistrictByPId: (id: string) => `${metadata}province/${id}`, + profileNewSubDistrictByDId: (id: string) => `${metadata}district/${id}`, // ประวัติส่วนตัว profileNewProfileByProfileId: (profileId: string) => @@ -159,8 +158,4 @@ export default { `${registryNew}changeName/${changeNameId}`, profileNewChangeNameHisByChangeNameId: (changeNameId: string) => `${registryNew}changeName/history/${changeNameId}`, - profileSalaryNew: `${salaryNew}`, - profileListSalaryNew: (id: string) => `${salaryNew}/${id}`, - profileListSalaryHistoryNew: (profileId: string) => - `${salaryNew}/history/${profileId}`, }; diff --git a/src/modules/04_registryNew/components/detail/PersonalInformation/03_Address.vue b/src/modules/04_registryNew/components/detail/PersonalInformation/03_Address.vue index 16593da7d..e02bb2204 100644 --- a/src/modules/04_registryNew/components/detail/PersonalInformation/03_Address.vue +++ b/src/modules/04_registryNew/components/detail/PersonalInformation/03_Address.vue @@ -37,14 +37,14 @@ const profileId = ref( route.params.id ? route.params.id.toString() : "" ); -const statusAdd = ref(false); const modal = ref(false); const modalHistory = ref(false); const rowsHistory = ref([]); -const tittleHistory = ref("ประวัติแก้ไขข้อมูลที่อยู่"); // +const tittleHistory = ref("ประวัติแก้ไขข้อมูลที่อยู่"); const filterHistory = ref(""); const id = ref(""); +const rawSameAddress = ref("0"); const sameAddress = ref("0"); const addressData = reactive(store.defaultAddress); const formData = reactive(store.defaultAddressForm); @@ -111,6 +111,7 @@ const columnsHistory = ref([ field: "registrationProvince", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => (v ? v.name : "-"), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -122,6 +123,7 @@ const columnsHistory = ref([ field: "registrationDistrict", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => (v ? v.name : "-"), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -133,6 +135,7 @@ const columnsHistory = ref([ field: "registrationSubDistrict", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => (v ? v.name : "-"), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -152,7 +155,11 @@ const columnsHistory = ref([ align: "left", label: "ที่อยู่ปัจจุบันตรงกับที่อยู่ตามทะเบียนบ้าน", sortable: true, - field: "registrationSame", + field: (v) => + v.registrationAddress === v.currentAddress && + v.registrationZipCode === v.currentZipCode + ? "ใช่" + : "ไม่", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -177,6 +184,7 @@ const columnsHistory = ref([ field: "currentProvince", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => (v ? v.name : "-"), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -188,6 +196,7 @@ const columnsHistory = ref([ field: "currentDistrict", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => (v ? v.name : "-"), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -199,6 +208,7 @@ const columnsHistory = ref([ field: "currentSubDistrict", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => (v ? v.name : "-"), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -232,6 +242,7 @@ const columnsHistory = ref([ field: "createdAt", headerStyle: "font-size: 14px", style: "font-size: 14px", + format: (v) => date2Thai(v), sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, @@ -246,13 +257,16 @@ async function getData() { if (addressData) { id.value = addressData.id; - if ( - addressData.currentAddress === addressData.registrationAddress && - addressData.currentZipCode === addressData.registrationZipCode - ) { - sameAddress.value = "1"; - } + addressData.currentAddress === addressData.registrationAddress && + addressData.currentZipCode === addressData.registrationZipCode && + addressData.currentAddress && + addressData.registrationAddress && + addressData.currentZipCode && + addressData.registrationZipCode + ? (rawSameAddress.value = "1") + : (rawSameAddress.value = "0"); } + sameAddress.value = rawSameAddress.value; }) .catch((e) => { messageError($q, e); @@ -262,131 +276,64 @@ async function getData() { }); } -async function getProvince() { - await fetchProvince(); - const checkRegistProvinceId = await store.Ops.provinceOps.find( - (e: any) => e.id === addressData.registrationProvinceId - ); - if (!checkRegistProvinceId) { - addressData.registrationProvinceId = ""; - addressData.registrationDistrictId = ""; - addressData.registrationSubDistrictId = ""; - addressData.registrationZipCode = ""; - } - const checkCurrentProvinceId = await store.Ops.provinceOps.find( - (e: any) => e.id === addressData.currentProvinceId - ); - if (!checkCurrentProvinceId) { - addressData.currentProvinceId = ""; - addressData.currentDistrictId = ""; - addressData.currentSubDistrictId = ""; - addressData.currentZipCode = ""; - } -} - -async function getDistrict(id: string | null, position: string) { - if (!id) return; - await fetchDistrict(id, position); - - if (position == "1") { - const checkRegistDistrictId = await store.Ops.districtOps.find( - (e: any) => e.id === addressData.registrationDistrictId - ); - if (!checkRegistDistrictId) { - addressData.registrationDistrictId = ""; - addressData.registrationSubDistrictId = ""; - addressData.registrationZipCode = ""; - } - } else { - const checkCurrentDistrictIdC = await store.Ops.districtCOps.find( - (e: any) => e.id === addressData.currentDistrictId - ); - if (!checkCurrentDistrictIdC) { - addressData.currentDistrictId = ""; - addressData.currentSubDistrictId = ""; - addressData.currentZipCode = ""; - } - } -} - -async function getSubDistrict(id: string | null, position: string) { - if (!id) return; - await fetchSubDistrict(id, position); - if (position == "1") { - const checkRegistSubdistrictId = await store.Ops.subdistrictOps.find( - (e: any) => e.id === addressData.registrationSubDistrictId - ); - if (!checkRegistSubdistrictId) { - addressData.registrationSubDistrictId = ""; - addressData.registrationZipCode = ""; - } - } else { - const checkCurrentSubdistrictIdC = await store.Ops.subdistrictCOps.find( - (e: any) => e.id === addressData.currentSubDistrictId - ); - if (!checkCurrentSubdistrictIdC) { - addressData.currentSubDistrictId = ""; - addressData.currentZipCode = ""; - } - } -} - async function selectProvince(e: string | null, name: string) { - if (e != null) { - if (name == "1") { - formData.registrationDistrictId = ""; - formData.registrationSubDistrictId = ""; - formData.registrationZipCode = ""; - } else { - formData.currentDistrictId = ""; - formData.currentSubDistrictId = ""; - formData.currentZipCode = ""; - } - await fetchDistrict(e, name); + if (!e) return; + if (name == "1") { + formData.registrationDistrictId = ""; + formData.registrationSubDistrictId = ""; + formData.registrationZipCode = ""; + } else { + formData.currentDistrictId = ""; + formData.currentSubDistrictId = ""; + formData.currentZipCode = ""; } + await fetchDistrict(e, name); } async function selectDistrict(e: string | null, name: string) { - if (e != null) { - if (name == "1") { - formData.registrationSubDistrictId = ""; - formData.registrationZipCode = ""; - } else { - formData.currentSubDistrictId = ""; - formData.currentZipCode = ""; - } - await fetchSubDistrict(e, name); + if (!e) return; + if (name == "1") { + formData.registrationSubDistrictId = ""; + formData.registrationZipCode = ""; + } else { + formData.currentSubDistrictId = ""; + formData.currentZipCode = ""; } + await fetchSubDistrict(e, name); } function selectSubDistrict(e: string | null, name: string) { - if (e != null) { - if (name == "1") { - const findcode = store.Ops.subdistrictOps.filter((r) => r.id == e); - const namecode = findcode.length > 0 ? findcode[0].zipCode : ""; - formData.registrationZipCode = namecode; - } else { - const findcode = store.Ops.subdistrictCOps.filter((r) => r.id == e); - const namecode = findcode.length > 0 ? findcode[0].zipCode : ""; - formData.currentZipCode = namecode; - } + if (!e) return; + if (name == "1") { + const findcode = store.Ops.subdistrictOps.filter((r) => r.id == e); + const namecode = findcode.length > 0 ? findcode[0].zipCode : ""; + formData.registrationZipCode = namecode; + } else { + const findcode = store.Ops.subdistrictCOps.filter((r) => r.id == e); + const namecode = findcode.length > 0 ? findcode[0].zipCode : ""; + formData.currentZipCode = namecode; } } async function fetchAll() { await getData(); + if (!store.profileIdBefore) { + store.profileIdBefore = profileId.value; + } if ( store.Ops.provinceOps.length === 0 || store.Ops.districtOps.length === 0 || store.Ops.districtCOps.length === 0 || store.Ops.subdistrictOps.length === 0 || - store.Ops.subdistrictCOps.length === 0 + store.Ops.subdistrictCOps.length === 0 || + store.profileIdBefore !== profileId.value ) { - await getProvince(); - await getDistrict(addressData.registrationProvinceId, "1"); - await getDistrict(addressData.currentProvinceId, "2"); - await getSubDistrict(addressData.registrationDistrictId, "1"); - await getSubDistrict(addressData.currentDistrictId, "2"); + await fetchProvince(); + await fetchDistrict(addressData.registrationProvinceId, "1"); + await fetchDistrict(addressData.currentProvinceId, "2"); + await fetchSubDistrict(addressData.registrationDistrictId, "1"); + await fetchSubDistrict(addressData.currentDistrictId, "2"); + store.profileIdBefore = profileId.value; } adsName.regisP = findData( @@ -436,10 +383,38 @@ async function editData() { }); } -function onClickOpenDialog() { +function clickClose() { + Object.assign(formData, store.defaultAddressForm); + modal.value = false; +} + +async function onClickOpenDialog() { if (!addressData) return; + await Object.assign(formData, addressData); + const checkDistrict = await store.Ops.districtOps.some( + (e: any) => e.id === addressData.registrationDistrictId + ); + const checkSubDistrict = await store.Ops.subdistrictOps.some( + (e: any) => e.id === addressData.registrationSubDistrictId + ); + const checkDistrictC = await store.Ops.districtCOps.some( + (e: any) => e.id === addressData.currentDistrictId + ); + const checkSubDistrictC = await store.Ops.subdistrictCOps.some( + (e: any) => e.id === addressData.currentSubDistrictId + ); + modal.value = true; - Object.assign(formData, addressData); + sameAddress.value = rawSameAddress.value; + + if (!checkDistrict || !checkSubDistrict) { + await fetchDistrict(addressData.registrationProvinceId, "1"); + await fetchSubDistrict(addressData.registrationDistrictId, "1"); + } + if (!checkDistrictC || !checkSubDistrictC) { + await fetchDistrict(addressData.currentProvinceId, "2"); + await fetchSubDistrict(addressData.currentDistrictId, "2"); + } } async function clickHistory() { @@ -448,7 +423,6 @@ async function clickHistory() { .get(config.API.profileNewAddressHisById(id.value)) .then((res) => { rowsHistory.value = res.data.result; - console.log(rowsHistory.value); }) .catch((e) => { messageError($q, e); @@ -462,6 +436,15 @@ function onSubmit() { dialogConfirm( $q, async () => { + if (sameAddress.value === "1") { + formData.currentAddress = formData.registrationAddress; + formData.currentProvinceId = formData.registrationProvinceId; + formData.currentDistrictId = formData.registrationDistrictId; + formData.currentSubDistrictId = formData.registrationSubDistrictId; + formData.currentZipCode = formData.registrationZipCode; + store.Ops.districtCOps = store.Ops.districtOps; + store.Ops.subdistrictCOps = store.Ops.subdistrictOps; + } editData(); modal.value = false; }, @@ -470,18 +453,22 @@ function onSubmit() { ); } +function sameAddressToggle(v: string) { + if (v === "0") { + formData.currentAddress = ""; + formData.currentProvinceId = ""; + formData.currentDistrictId = ""; + formData.currentSubDistrictId = ""; + formData.currentZipCode = ""; + store.Ops.districtCOps = []; + store.Ops.subdistrictCOps = []; + } +} + watch( () => sameAddress.value, (v) => { - if (v === "1") { - formData.currentAddress = formData.registrationAddress; - formData.currentProvinceId = formData.registrationProvinceId; - formData.currentDistrictId = formData.registrationDistrictId; - formData.currentSubDistrictId = formData.registrationSubDistrictId; - formData.currentZipCode = formData.registrationZipCode; - store.Ops.districtCOps = store.Ops.districtOps - store.Ops.subdistrictCOps = store.Ops.subdistrictOps - } + sameAddressToggle(v); } ); @@ -581,10 +568,7 @@ onMounted(async () => { - + @@ -839,16 +823,7 @@ onMounted(async () => {