forked from verdnatura/salix-front
perf: refs #8061 use opts from VnSelect
This commit is contained in:
parent
507b78f5e8
commit
3a695bdfe1
|
@ -23,9 +23,8 @@ const postcodeFormData = reactive({
|
||||||
});
|
});
|
||||||
|
|
||||||
const townsFetchDataRef = ref(false);
|
const townsFetchDataRef = ref(false);
|
||||||
const countriesFetchDataRef = ref(false);
|
const countriesRef = ref(false);
|
||||||
const provincesFetchDataRef = ref(false);
|
const provincesFetchDataRef = ref(false);
|
||||||
const countriesOptions = ref([]);
|
|
||||||
const provincesOptions = ref([]);
|
const provincesOptions = ref([]);
|
||||||
const townsOptions = ref([]);
|
const townsOptions = ref([]);
|
||||||
const town = ref({});
|
const town = ref({});
|
||||||
|
@ -42,7 +41,7 @@ function onDataSaved(formData) {
|
||||||
({ id }) => id === formData.provinceFk
|
({ id }) => id === formData.provinceFk
|
||||||
);
|
);
|
||||||
newPostcode.province = provinceObject?.name;
|
newPostcode.province = provinceObject?.name;
|
||||||
const countryObject = countriesOptions.value.find(
|
const countryObject = countriesRef.value.opts.find(
|
||||||
({ id }) => id === formData.countryFk
|
({ id }) => id === formData.countryFk
|
||||||
);
|
);
|
||||||
newPostcode.country = countryObject?.name;
|
newPostcode.country = countryObject?.name;
|
||||||
|
@ -80,16 +79,6 @@ async function filterTowns(name) {
|
||||||
await townsFetchDataRef.value?.fetch();
|
await townsFetchDataRef.value?.fetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function filterCountries(name) {
|
|
||||||
if (name !== '') {
|
|
||||||
countryFilter.value.where = {
|
|
||||||
name: {
|
|
||||||
like: `%${name}%`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
await countriesFetchDataRef.value?.fetch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchTowns(countryFk) {
|
async function fetchTowns(countryFk) {
|
||||||
if (!countryFk) return;
|
if (!countryFk) return;
|
||||||
|
@ -111,10 +100,6 @@ async function handleTowns(data) {
|
||||||
townsOptions.value = data;
|
townsOptions.value = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCountries(data) {
|
|
||||||
countriesOptions.value = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setProvince(id, data) {
|
async function setProvince(id, data) {
|
||||||
const newProvince = provincesOptions.value.find((province) => province.id == id);
|
const newProvince = provincesOptions.value.find((province) => province.id == id);
|
||||||
if (!newProvince) return;
|
if (!newProvince) return;
|
||||||
|
@ -148,15 +133,6 @@ async function onProvinceCreated(data) {
|
||||||
auto-load
|
auto-load
|
||||||
url="Towns/location"
|
url="Towns/location"
|
||||||
/>
|
/>
|
||||||
<FetchData
|
|
||||||
ref="countriesFetchDataRef"
|
|
||||||
:limit="30"
|
|
||||||
:filter="countryFilter"
|
|
||||||
:sort-by="['name ASC']"
|
|
||||||
@on-fetch="handleCountries"
|
|
||||||
auto-load
|
|
||||||
url="Countries"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
url-create="postcodes"
|
url-create="postcodes"
|
||||||
|
@ -225,12 +201,15 @@ async function onProvinceCreated(data) {
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
|
ref="countriesRef"
|
||||||
|
:limit="30"
|
||||||
|
:filter="countryFilter"
|
||||||
|
:sort-by="['name ASC']"
|
||||||
|
auto-load
|
||||||
|
url="Countries"
|
||||||
required
|
required
|
||||||
:label="t('Country')"
|
:label="t('Country')"
|
||||||
@update:options="handleCountries"
|
|
||||||
:options="countriesOptions"
|
|
||||||
hide-selected
|
hide-selected
|
||||||
@filter="filterCountries"
|
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
v-model="data.countryFk"
|
v-model="data.countryFk"
|
||||||
|
|
Loading…
Reference in New Issue