ขออัปเดตข้อมูลจากกรมการปกครอง
This commit is contained in:
parent
189347832c
commit
c49d222a3f
10 changed files with 2155 additions and 14 deletions
325
src/modules/04_registryPerson/components/Dialog/02_Address.vue
Normal file
325
src/modules/04_registryPerson/components/Dialog/02_Address.vue
Normal file
|
|
@ -0,0 +1,325 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch } from "vue";
|
||||
|
||||
import { useDataLinkCenter } from "@/modules/04_registryPerson/stores/LinkCenter";
|
||||
import type { RequestAddressObject } from "@/modules/04_registryPerson/interface/request/Address";
|
||||
|
||||
const storeLinkCenter = useDataLinkCenter();
|
||||
const formDataAddress = defineModel<RequestAddressObject>("formDataAddress", {
|
||||
required: true,
|
||||
});
|
||||
const presentAddress = defineModel<string>("presentAddress", {
|
||||
required: true,
|
||||
});
|
||||
|
||||
const dataLabel = {
|
||||
registrationAddress: "ที่อยู่ตามทะเบียนบ้าน",
|
||||
registrationProvince: "จังหวัด",
|
||||
registrationDistrict: "เขต/อำเภอ",
|
||||
registrationSubDistrict: "แขวง / ตำบล",
|
||||
registrationZipCode: "รหัสไปรษณีย์",
|
||||
currentAddress: "ที่อยู่ปัจจุบัน",
|
||||
currentProvince: "จังหวัด",
|
||||
currentDistrict: "เขต/อำเภอ",
|
||||
currentSubDistrict: "แขวง / ตำบล",
|
||||
currentZipCode: "รหัสไปรษณีย์",
|
||||
registrationSame: "ที่อยู่ปัจจุบันตรงกับที่อยู่ตามทะเบียนบ้าน",
|
||||
};
|
||||
|
||||
/**
|
||||
* ฟังก์ชันเลือกข้อมูลจังหวัด
|
||||
* @param e id จังหวัด
|
||||
* @param name ที่อยู่ตามทะเบียนบ้าน , ที่อยู่ปัจจุบัน
|
||||
*/
|
||||
async function selectProvince(e: string | null, name: string) {
|
||||
if (e != null) {
|
||||
if (name == "1") {
|
||||
formDataAddress.value.registrationSubDistrictId = "";
|
||||
formDataAddress.value.registrationZipCode = "";
|
||||
formDataAddress.value.registrationDistrictId = "";
|
||||
} else {
|
||||
formDataAddress.value.currentSubDistrictId = "";
|
||||
formDataAddress.value.currentZipCode = "";
|
||||
formDataAddress.value.currentDistrictId = "";
|
||||
}
|
||||
await storeLinkCenter.fetchDistrict(e, name, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันเลือก เขต / อำเภอ
|
||||
* @param e แขวง/ตำบลที่เลือก
|
||||
* @param name 1 คือ ที่อยู่ตามทะเบียนบ้าน 2 คือ ที่อยู่ปัจจุบัน
|
||||
*/
|
||||
async function selectDistrict(e: string | null, name: string) {
|
||||
if (!e) return;
|
||||
if (name == "1") {
|
||||
formDataAddress.value.registrationSubDistrictId = "";
|
||||
formDataAddress.value.registrationZipCode = "";
|
||||
} else {
|
||||
formDataAddress.value.currentSubDistrictId = "";
|
||||
formDataAddress.value.currentZipCode = "";
|
||||
}
|
||||
await storeLinkCenter.fetchSubDistrict(e, name, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันเลือก แขวง / ตำบล
|
||||
* @param e แขวง / ตำบล ที่เลือก
|
||||
* @param name 1 คือ ที่อยู่ตามทะเบียนบ้าน 2 คือ ที่อยู่ปัจจุบัน
|
||||
*/
|
||||
function selectSubDistrict(e: string | null, name: string) {
|
||||
if (!e) return;
|
||||
if (name == "1") {
|
||||
const findcode = storeLinkCenter.OpsAddress.subdistrictOps.filter(
|
||||
(r) => r.id == e
|
||||
);
|
||||
const namecode = findcode.length > 0 ? findcode[0].zipCode : "";
|
||||
formDataAddress.value.registrationZipCode = namecode;
|
||||
} else {
|
||||
const findcode = storeLinkCenter.OpsAddress.subdistrictCOps.filter(
|
||||
(r) => r.id == e
|
||||
);
|
||||
const namecode = findcode.length > 0 ? findcode[0].zipCode : "";
|
||||
formDataAddress.value.currentZipCode = namecode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ดูการเปลี่ยนแปลงที่อยู่ปัจจุบันตรงกับที่อยู่ตามทะเบียนบ้าน
|
||||
*/
|
||||
watch(
|
||||
() => presentAddress.value,
|
||||
(v) => {
|
||||
if (v === "0") {
|
||||
formDataAddress.value.currentAddress = "";
|
||||
formDataAddress.value.currentProvinceId = "";
|
||||
formDataAddress.value.currentDistrictId = "";
|
||||
formDataAddress.value.currentSubDistrictId = "";
|
||||
formDataAddress.value.currentZipCode = "";
|
||||
storeLinkCenter.OpsAddress.districtCOps = [];
|
||||
storeLinkCenter.OpsAddress.subdistrictCOps = [];
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
|
||||
<div class="col-12 text-tooltip text-weight-medium">ข้อมูลที่อยู่</div>
|
||||
<div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
|
||||
<div class="col-xs-6 col-sm-6 col-md-12">
|
||||
<q-input
|
||||
dense
|
||||
outlined
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.registrationAddress"
|
||||
:label="dataLabel.registrationAddress"
|
||||
:rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ตามทะเบียนบ้าน'}`]"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-select
|
||||
dense
|
||||
outlined
|
||||
use-input
|
||||
lazy-rules
|
||||
emit-value
|
||||
map-options
|
||||
hide-bottom-space
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
input-debounce="0"
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.registrationProvinceId"
|
||||
:options="storeLinkCenter.OpsAddress.provinceOps"
|
||||
:label="dataLabel.registrationProvince"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]"
|
||||
@update:model-value="(value:string) => selectProvince(value, '1')"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => storeLinkCenter.filterSelector(inputValue, doneFn,'provinceOps'
|
||||
) "
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-select
|
||||
dense
|
||||
outlined
|
||||
use-input
|
||||
lazy-rules
|
||||
emit-value
|
||||
map-options
|
||||
hide-bottom-space
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
input-debounce="0"
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.registrationDistrictId"
|
||||
:options="storeLinkCenter.OpsAddress.districtOps"
|
||||
:label="dataLabel.registrationDistrict"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]"
|
||||
@update:model-value="(value:string) => selectDistrict(value, '1')"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => storeLinkCenter.filterSelector(inputValue, doneFn,'districtOps'
|
||||
) "
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-select
|
||||
dense
|
||||
outlined
|
||||
use-input
|
||||
lazy-rules
|
||||
emit-value
|
||||
map-options
|
||||
hide-bottom-space
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
input-debounce="0"
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.registrationSubDistrictId"
|
||||
:options="storeLinkCenter.OpsAddress.subdistrictOps"
|
||||
:label="dataLabel.registrationSubDistrict"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]"
|
||||
@update:model-value="(value:string) => selectSubDistrict(value, '1')"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => storeLinkCenter.filterSelector(inputValue, doneFn,'subdistrictOps'
|
||||
) "
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-input
|
||||
dense
|
||||
readonly
|
||||
outlined
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
v-model="formDataAddress.registrationZipCode"
|
||||
:label="dataLabel.registrationZipCode"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<!-- same address ? -->
|
||||
<div class="col-xs-12 q-gutter-sm items-center flex q-my-sm">
|
||||
<label class="text-medium"
|
||||
>ที่อยู่ปัจจุบันตรงกับที่อยู่ตามทะเบียนบ้าน</label
|
||||
>
|
||||
<q-radio
|
||||
dense
|
||||
val="1"
|
||||
label="ใช่"
|
||||
checked-icon="task_alt"
|
||||
class="inputgreen"
|
||||
v-model="presentAddress"
|
||||
unchecked-icon="panorama_fish_eye"
|
||||
/>
|
||||
<q-radio
|
||||
dense
|
||||
val="0"
|
||||
label="ไม่"
|
||||
checked-icon="task_alt"
|
||||
class="inputgreen"
|
||||
v-model="presentAddress"
|
||||
unchecked-icon="panorama_fish_eye"
|
||||
/>
|
||||
</div>
|
||||
<!-- current address -->
|
||||
<div v-if="presentAddress === '0'">
|
||||
<div class="col-12 q-pb-xs">
|
||||
<q-input
|
||||
dense
|
||||
outlined
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.currentAddress"
|
||||
:label="dataLabel.currentAddress"
|
||||
:rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ปัจจุบัน'}`]"
|
||||
/>
|
||||
</div>
|
||||
<div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-select
|
||||
dense
|
||||
outlined
|
||||
use-input
|
||||
lazy-rules
|
||||
emit-value
|
||||
map-options
|
||||
hide-bottom-space
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
input-debounce="0"
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.currentProvinceId"
|
||||
:options="storeLinkCenter.OpsAddress.provinceOps"
|
||||
:label="dataLabel.currentProvince"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]"
|
||||
@update:model-value="(value:string) => selectProvince(value, '2')"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => storeLinkCenter.filterSelector(inputValue, doneFn,'provinceOps'
|
||||
) "
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-select
|
||||
dense
|
||||
outlined
|
||||
use-input
|
||||
lazy-rules
|
||||
emit-value
|
||||
map-options
|
||||
hide-bottom-space
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
input-debounce="0"
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.currentDistrictId"
|
||||
:options="storeLinkCenter.OpsAddress.districtCOps"
|
||||
:label="dataLabel.currentDistrict"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]"
|
||||
@update:model-value="(value:string) => selectDistrict(value, '2')"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => storeLinkCenter.filterSelector(inputValue, doneFn,'districtCOps'
|
||||
) "
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-select
|
||||
dense
|
||||
outlined
|
||||
use-input
|
||||
lazy-rules
|
||||
emit-value
|
||||
map-options
|
||||
hide-bottom-space
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
input-debounce="0"
|
||||
class="inputgreen"
|
||||
v-model="formDataAddress.currentSubDistrictId"
|
||||
:options="storeLinkCenter.OpsAddress.subdistrictCOps"
|
||||
:label="dataLabel.currentSubDistrict"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]"
|
||||
@update:model-value="(value:string) => selectSubDistrict(value, '2')"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => storeLinkCenter.filterSelector(inputValue, doneFn,'subdistrictCOps'
|
||||
) "
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-3">
|
||||
<q-input
|
||||
dense
|
||||
readonly
|
||||
outlined
|
||||
lazy-rules
|
||||
hide-bottom-space
|
||||
v-model="formDataAddress.currentZipCode"
|
||||
:label="dataLabel.registrationZipCode"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Loading…
Add table
Add a link
Reference in a new issue