From 201062289ff3cee46f71618b18841d58e71fa3c6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 28 Jun 2024 14:59:47 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9?= =?UTF-8?q?=E0=B8=A5=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=20=3D>=20fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/org/api.org.ts | 8 + .../01_Information/01_Information.vue | 4 +- .../01_Information/02_ChangeName.vue | 4 +- .../10_registry/01_Information/03_Address.vue | 165 ++++++++++++++++-- .../10_registry/01_Information/04_Family.vue | 41 +++-- .../01_Information/05_Educations.vue | 4 +- .../10_registry/01_Information/06_Ability.vue | 4 +- .../interface/response/01_Information.ts | 48 +++++ src/modules/10_registry/views/main.vue | 24 ++- 9 files changed, 259 insertions(+), 43 deletions(-) create mode 100644 src/modules/10_registry/interface/response/01_Information.ts diff --git a/src/api/org/api.org.ts b/src/api/org/api.org.ts index 1eb55c9..66c6e06 100644 --- a/src/api/org/api.org.ts +++ b/src/api/org/api.org.ts @@ -1,5 +1,6 @@ import env from "../index"; +const metadata = `${env.API_URI}/org/metadata/`; const org = `${env.API_URI}/org`; const profileOrg = `${env.API_URI}/org/profile`; const report = `${env.API_URI}/report/profile/`; @@ -66,4 +67,11 @@ export default { /** struct-chart*/ orgStructChart: (id: string, type: string) => `${org}/struct-chart/${id}/${type}`, + + /** + * ข้อมูลจังหวัด + */ + profileNewProvince: `${metadata}province`, + profileNewDistrictByPId: (id: string) => `${metadata}province/${id}`, + profileNewSubDistrictByDId: (id: string) => `${metadata}district/${id}`, }; diff --git a/src/modules/10_registry/01_Information/01_Information.vue b/src/modules/10_registry/01_Information/01_Information.vue index b9933a7..b4063f7 100644 --- a/src/modules/10_registry/01_Information/01_Information.vue +++ b/src/modules/10_registry/01_Information/01_Information.vue @@ -251,7 +251,9 @@ function getData() { messageError($q, e); }) .finally(() => { - hideLoader(); + setTimeout(() => { + hideLoader(); + }, 2000); }); } diff --git a/src/modules/10_registry/01_Information/02_ChangeName.vue b/src/modules/10_registry/01_Information/02_ChangeName.vue index 6dbe5e4..3edbd24 100644 --- a/src/modules/10_registry/01_Information/02_ChangeName.vue +++ b/src/modules/10_registry/01_Information/02_ChangeName.vue @@ -170,7 +170,9 @@ function getData() { messageError($q, e); }) .finally(() => { - hideLoader(); + setTimeout(() => { + hideLoader(); + }, 2000); }); } diff --git a/src/modules/10_registry/01_Information/03_Address.vue b/src/modules/10_registry/01_Information/03_Address.vue index 7678f62..815793d 100644 --- a/src/modules/10_registry/01_Information/03_Address.vue +++ b/src/modules/10_registry/01_Information/03_Address.vue @@ -2,12 +2,19 @@ import { useCounterMixin } from "@/stores/mixin"; import { useQuasar, type QTableProps } from "quasar"; import { ref, reactive, onMounted } from "vue"; +import http from "@/plugins/http"; +import config from "@/app.config"; + +import type { + Address, + Provinces, + Districts, + SubDistricts, +} from "@/modules/10_registry/interface/response/01_Information"; //history dialog import DialogHistory from "@/modules/10_registry/Dialog/DialogHistory.vue"; -import http from "@/plugins/http"; -import config from "@/app.config"; import { useRegistryInFormationStore } from "@/modules/10_registry/store/registry"; const store = useRegistryInFormationStore(); @@ -19,7 +26,7 @@ const { showLoader, hideLoader, messageError, date2Thai } = mixin; const modalHistory = ref(false); /** ตัวแปรข้อมูล */ -const formData = reactive({ +const formData = reactive({ registrationAddress: "", //ที่อยู่ตามทะเบียนบ้าน registrationProvince: "", //จังหวัด registrationDistrict: "", //เขต / อำเภอ @@ -33,6 +40,12 @@ const formData = reactive({ currentZipCode: "", //รหัสไปรษณีย์ }); +const provinceData = ref([]); +const districtRegistration = ref([]); +const districtCurrent = ref([]); +const subDistrictRegistration = ref([]); +const subDistrictCurrent = ref([]); + const visibleColumnsHistory = ref([ "currentAddress", "currentDistrict", @@ -216,23 +229,31 @@ function getData() { http .get(config.API.dataUserAddress) .then((res) => { - const data = res.data.result; + const data: Address = res.data.result; + fetchDistrict(data.registrationProvinceId, "1"); + fetchDistrict(data.currentProvinceId, "2"); + fetchSubDistrict(data.registrationDistrictId, "1"); + fetchSubDistrict(data.currentDistrictId, "2"); + formData.registrationAddress = data.registrationAddress; - formData.registrationProvince = data.registrationProvince; - formData.registrationDistrict = data.registrationDistrict; - formData.registrationSubDistrict = data.registrationSubDistrict; + formData.registrationProvince = data.registrationProvinceId; + formData.registrationDistrict = data.registrationDistrictId; + formData.registrationSubDistrict = data.registrationSubDistrictId; formData.registrationZipCode = data.registrationZipCode; + formData.currentAddress = data.currentAddress; - formData.currentProvince = data.currentProvince; - formData.currentDistrict = data.currentDistrict; - formData.currentSubDistrict = data.currentSubDistrict; + formData.currentProvince = data.currentProvinceId; + formData.currentDistrict = data.currentDistrictId; + formData.currentSubDistrict = data.currentSubDistrictId; formData.currentZipCode = data.currentZipCode; }) .catch((e) => { messageError($q, e); }) .finally(() => { - hideLoader(); + setTimeout(() => { + hideLoader(); + }, 2000); }); } @@ -257,8 +278,101 @@ function getHistory() { }); } -onMounted(() => { - getData(); +/** + *function fetch ข้อมูลจังหวัด + */ +function fetchProvince() { + http + .get(config.API.profileNewProvince) + .then((res) => { + const data = res.data.result; + provinceData.value = data; + }) + .catch((e) => { + messageError($q, e); + }); +} + +/** + * function fetch ข้อมูลอำเภอ + * @param id จังหวัด + * @param position ที่อยู่ตามทะเบียนบ้าน,ที่อยู่ปัจจุบัน + */ +function fetchDistrict(id: string | null, position: string) { + if (!id) return; + http + .get(config.API.profileNewDistrictByPId(id)) + .then((res) => { + const data = res.data.result.districts; + if (position === "1") { + districtRegistration.value = data; + } else { + districtCurrent.value = data; + } + }) + .catch((e) => { + messageError($q, e); + }); +} + +/** + * function fetch ข้อมูลตำบล + * @param id อำเภอ + * @param position ที่อยู่ตามทะเบียนบ้าน,ที่อยู่ปัจจุบัน + */ +function fetchSubDistrict(id: string | null, position: string) { + if (!id) return; + http + .get(config.API.profileNewSubDistrictByDId(id)) + .then((res) => { + const data = res.data.result.subDistricts; + if (position === "1") { + subDistrictRegistration.value = data; + } else { + subDistrictCurrent.value = data; + } + }) + .catch((e) => { + messageError($q, e); + }); +} + +/** + * function แปลงชื่อจังหวัด + * @param id จังหวัด + */ +function convertProvinceName(id: string) { + const province = provinceData.value.find((e: Provinces) => e.id === id); + return province?.name; +} + +/** + * function แปลงชื่ออำเภอ + * @param id อำเภอ + * @param type ที่อยู่ตามทะเบียนบ้าน,ที่อยู่ปัจจุบัน + */ +function convertDistrictName(id: string, type: string) { + const data = + type === "1" ? districtRegistration.value : districtCurrent.value; + const district = data.find((e: Districts) => e.id === id); + return district?.name; +} + +/** + * function แปลงชื่อตำบล + * @param id ตำบล + * @param type ที่อยู่ตามทะเบียนบ้าน,ที่อยู่ปัจจุบัน + */ +function convertSubDistrictName(id: string, type: string) { + const data = + type === "1" ? subDistrictRegistration.value : subDistrictCurrent.value; + const district = data.find((e: SubDistricts) => e.id === id); + return district?.name; +} + +onMounted(async () => { + await fetchProvince(); + await getData(); });