forked from verdnatura/salix-front
perf: emit options from VnSelectProvince
This commit is contained in:
parent
4a6f859a86
commit
854e72fe51
|
@ -25,7 +25,6 @@ const townsFetchDataRef = ref(false);
|
||||||
const townFilter = ref({});
|
const townFilter = ref({});
|
||||||
|
|
||||||
const countriesRef = ref(false);
|
const countriesRef = ref(false);
|
||||||
const provincesFetchDataRef = ref(false);
|
|
||||||
const provincesOptions = ref([]);
|
const provincesOptions = ref([]);
|
||||||
const townsOptions = ref([]);
|
const townsOptions = ref([]);
|
||||||
const town = ref({});
|
const town = ref({});
|
||||||
|
@ -71,9 +70,6 @@ async function setProvince(id, data) {
|
||||||
await fetchTowns();
|
await fetchTowns();
|
||||||
}
|
}
|
||||||
async function onProvinceCreated(data) {
|
async function onProvinceCreated(data) {
|
||||||
await provincesFetchDataRef.value.fetch({
|
|
||||||
where: { countryFk: postcodeFormData.countryFk },
|
|
||||||
});
|
|
||||||
postcodeFormData.provinceFk = data.id;
|
postcodeFormData.provinceFk = data.id;
|
||||||
}
|
}
|
||||||
function provinceByCountry(countryFk = postcodeFormData.countryFk) {
|
function provinceByCountry(countryFk = postcodeFormData.countryFk) {
|
||||||
|
@ -92,7 +88,6 @@ function setTown(newTown, data) {
|
||||||
data.countryFk = newTown?.province?.countryFk ?? newTown;
|
data.countryFk = newTown?.province?.countryFk ?? newTown;
|
||||||
}
|
}
|
||||||
async function onCityCreated(newTown, formData) {
|
async function onCityCreated(newTown, formData) {
|
||||||
await provincesFetchDataRef.value.fetch();
|
|
||||||
newTown.province = provincesOptions.value.find(
|
newTown.province = provincesOptions.value.find(
|
||||||
(province) => province.id === newTown.provinceFk
|
(province) => province.id === newTown.provinceFk
|
||||||
);
|
);
|
||||||
|
@ -125,14 +120,6 @@ async function filterTowns(name) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
ref="provincesFetchDataRef"
|
|
||||||
@on-fetch="handleProvinces"
|
|
||||||
:sort-by="['name ASC']"
|
|
||||||
:limit="30"
|
|
||||||
auto-load
|
|
||||||
url="Provinces/location"
|
|
||||||
/>
|
|
||||||
<FetchData
|
<FetchData
|
||||||
ref="townsFetchDataRef"
|
ref="townsFetchDataRef"
|
||||||
:sort-by="['name ASC']"
|
:sort-by="['name ASC']"
|
||||||
|
@ -205,6 +192,11 @@ async function filterTowns(name) {
|
||||||
:country-fk="data.countryFk"
|
:country-fk="data.countryFk"
|
||||||
:province-selected="data.provinceFk"
|
:province-selected="data.provinceFk"
|
||||||
@update:model-value="(value) => setProvince(value, data)"
|
@update:model-value="(value) => setProvince(value, data)"
|
||||||
|
@update:options="
|
||||||
|
(data) => {
|
||||||
|
provincesOptions = data;
|
||||||
|
}
|
||||||
|
"
|
||||||
v-model="data.provinceFk"
|
v-model="data.provinceFk"
|
||||||
@on-province-created="onProvinceCreated"
|
@on-province-created="onProvinceCreated"
|
||||||
required
|
required
|
||||||
|
|
|
@ -7,7 +7,7 @@ import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
|
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['onProvinceCreated', 'onProvinceFetched']);
|
const emit = defineEmits(['onProvinceCreated', 'onProvinceFetched', 'update:options']);
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
countryFk: {
|
countryFk: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
@ -41,6 +41,7 @@ async function onProvinceCreated(_, data) {
|
||||||
}
|
}
|
||||||
async function handleProvinces(data) {
|
async function handleProvinces(data) {
|
||||||
provincesOptions.value = data;
|
provincesOptions.value = data;
|
||||||
|
emit('update:options', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
Loading…
Reference in New Issue