diff --git a/src/components/form/AddressForm.vue b/src/components/form/AddressForm.vue index 9f2d4911..40e259ed 100644 --- a/src/components/form/AddressForm.vue +++ b/src/components/form/AddressForm.vue @@ -8,7 +8,11 @@ import useAddressStore, { import { selectFilterOptionRefMod } from 'stores/utils'; import { QSelect } from 'quasar'; import { useI18n } from 'vue-i18n'; +import SelectInput from 'src/components/shared/SelectInput.vue'; +import useOptionStore from 'stores/options'; +const { locale } = useI18n({ useScope: 'global' }); +const optionStore = useOptionStore(); defineProps<{ title?: string; addressTitle?: string; @@ -54,6 +58,8 @@ const employmentOfficeEN = defineModel( 'employmentOfficeEn', ); +const areaOptions = ref[]>([]); + const addrOptions = reactive<{ provinceOps: Province[]; districtOps: District[]; @@ -204,6 +210,12 @@ async function selectSubDistrict(id: string) { } const provinceOptions = ref[]>([]); + +let areaFilter: ( + value: string, + update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void, +) => void; + let provinceFilter: ( value: string, update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void, @@ -233,12 +245,40 @@ let subDistrictEnFilter: ( update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void, ) => void; +const rawOption = ref(); +const areaENOption = ref([]); + onMounted(async () => { + const resultOption = await fetch('/option/option.json'); + rawOption.value = await resultOption.json(); + areaENOption.value = rawOption.value.eng.area; + await fetchProvince(); await fetchDistrict(); await fetchSubDistrict(); }); +onMounted(() => { + if (optionStore.globalOption?.area) { + areaFilter = selectFilterOptionRefMod( + ref(optionStore.globalOption.area), + areaOptions, + 'label', + ); + } +}); + +watch( + () => optionStore.globalOption, + () => { + areaFilter = selectFilterOptionRefMod( + ref(optionStore.globalOption.prefix), + areaOptions, + 'label', + ); + }, +); + watch(provinceId, fetchDistrict); watch(districtId, fetchSubDistrict); @@ -315,26 +355,57 @@ watch(districtId, fetchSubDistrict); ] " /> - - + + + +