feat: select district & sub when edit
This commit is contained in:
parent
2e28c00551
commit
f422d00d23
1 changed files with 37 additions and 27 deletions
|
|
@ -13,6 +13,11 @@ defineProps<{
|
||||||
close?: (...args: unknown[]) => void;
|
close?: (...args: unknown[]) => void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
fetchDistrict,
|
||||||
|
fetchSubDistrict,
|
||||||
|
});
|
||||||
|
|
||||||
const adrressStore = useAddressStore();
|
const adrressStore = useAddressStore();
|
||||||
const modal = defineModel('modal', { default: false });
|
const modal = defineModel('modal', { default: false });
|
||||||
const address = defineModel('address', { default: '' });
|
const address = defineModel('address', { default: '' });
|
||||||
|
|
@ -48,39 +53,38 @@ async function fetchSubDistrict(id: string | undefined) {
|
||||||
if (id) {
|
if (id) {
|
||||||
const result = await adrressStore.fetchSubDistrictByProvinceId(id);
|
const result = await adrressStore.fetchSubDistrictByProvinceId(id);
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log(addrOptions.value.subDistrictOps);
|
|
||||||
addrOptions.value.subDistrictOps = result;
|
addrOptions.value.subDistrictOps = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
async function selectProvince(id: string) {
|
||||||
await fetchProvince();
|
if (!id) return;
|
||||||
});
|
districtId.value = undefined;
|
||||||
|
|
||||||
watch(provinceId, async (v) => {
|
|
||||||
await fetchDistrict(v);
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(districtId, async (v) => {
|
|
||||||
subDistrictId.value = undefined;
|
subDistrictId.value = undefined;
|
||||||
await fetchSubDistrict(v);
|
addrOptions.value.districtOps = [];
|
||||||
});
|
addrOptions.value.subDistrictOps = [];
|
||||||
|
zipCode.value = '';
|
||||||
|
await fetchDistrict(id);
|
||||||
|
}
|
||||||
|
|
||||||
watch(subDistrictId, async (v) => {
|
async function selectDistrict(id: string) {
|
||||||
|
if (!id) return;
|
||||||
|
subDistrictId.value = undefined;
|
||||||
|
zipCode.value = '';
|
||||||
|
await fetchSubDistrict(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function selectSubDistrict(id: string) {
|
||||||
|
if (!id) return;
|
||||||
zipCode.value =
|
zipCode.value =
|
||||||
addrOptions.value.subDistrictOps
|
addrOptions.value.subDistrictOps
|
||||||
?.filter((x) => x.id === v)
|
?.filter((x) => x.id === id)
|
||||||
.map((x) => x.zipCode)[0] ?? '';
|
.map((x) => x.zipCode)[0] ?? '';
|
||||||
});
|
}
|
||||||
|
|
||||||
watch(provinceId, (v) => {
|
onMounted(async () => {
|
||||||
if (v) {
|
await fetchProvince();
|
||||||
addrOptions.value.districtOps = [];
|
|
||||||
addrOptions.value.subDistrictOps = [];
|
|
||||||
districtId.value = undefined;
|
|
||||||
subDistrictId.value = undefined;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -144,7 +148,7 @@ watch(provinceId, (v) => {
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
id="AddrL"
|
id="Addr"
|
||||||
label="ที่อยู่"
|
label="ที่อยู่"
|
||||||
class="col-12"
|
class="col-12"
|
||||||
v-model="address"
|
v-model="address"
|
||||||
|
|
@ -154,45 +158,48 @@ watch(provinceId, (v) => {
|
||||||
outlined
|
outlined
|
||||||
emit-value
|
emit-value
|
||||||
map-options
|
map-options
|
||||||
id="selectProvinceL"
|
id="selectProvince"
|
||||||
v-model="provinceId"
|
v-model="provinceId"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
label="จังหวัด"
|
label="จังหวัด"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:options="addrOptions.provinceOps"
|
:options="addrOptions.provinceOps"
|
||||||
|
@update:model-value="(v: string) => selectProvince(v)"
|
||||||
/>
|
/>
|
||||||
<q-select
|
<q-select
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
emit-value
|
emit-value
|
||||||
map-options
|
map-options
|
||||||
id="selectDistrictL"
|
id="selectDistrict"
|
||||||
v-model="districtId"
|
v-model="districtId"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
label="อำเภอ"
|
label="อำเภอ"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:options="addrOptions.districtOps"
|
:options="addrOptions.districtOps"
|
||||||
|
@update:model-value="(v: string) => selectDistrict(v)"
|
||||||
/>
|
/>
|
||||||
<q-select
|
<q-select
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
emit-value
|
emit-value
|
||||||
map-options
|
map-options
|
||||||
id="SelectSubDistrictEN"
|
id="SelectSubDistrict"
|
||||||
v-model="subDistrictId"
|
v-model="subDistrictId"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
label="ตำบล"
|
label="ตำบล"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:options="addrOptions.subDistrictOps"
|
:options="addrOptions.subDistrictOps"
|
||||||
|
@update:model-value="(v: string) => selectSubDistrict(v)"
|
||||||
/>
|
/>
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
readonly
|
readonly
|
||||||
outlined
|
outlined
|
||||||
id="zipL"
|
id="zip"
|
||||||
label="รหัสไปรษณีย์"
|
label="รหัสไปรษณีย์"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
v-model="zipCode"
|
v-model="zipCode"
|
||||||
|
|
@ -220,6 +227,7 @@ watch(provinceId, (v) => {
|
||||||
label="จังหวัด"
|
label="จังหวัด"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:options="addrOptions.provinceOps"
|
:options="addrOptions.provinceOps"
|
||||||
|
@update:model-value="(v: string) => selectProvince(v)"
|
||||||
/>
|
/>
|
||||||
<q-select
|
<q-select
|
||||||
dense
|
dense
|
||||||
|
|
@ -233,6 +241,7 @@ watch(provinceId, (v) => {
|
||||||
label="อำเภอ"
|
label="อำเภอ"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:options="addrOptions.districtOps"
|
:options="addrOptions.districtOps"
|
||||||
|
@update:model-value="(v: string) => selectDistrict(v)"
|
||||||
/>
|
/>
|
||||||
<q-select
|
<q-select
|
||||||
dense
|
dense
|
||||||
|
|
@ -246,6 +255,7 @@ watch(provinceId, (v) => {
|
||||||
label="ตำบล"
|
label="ตำบล"
|
||||||
class="col-3"
|
class="col-3"
|
||||||
:options="addrOptions.subDistrictOps"
|
:options="addrOptions.subDistrictOps"
|
||||||
|
@update:model-value="(v: string) => selectSubDistrict(v)"
|
||||||
/>
|
/>
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue