forked from verdnatura/salix-front
parent
f6e97efe78
commit
7650997c24
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, ref, watch } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
@ -10,7 +10,6 @@ import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import CreateNewCityForm from './CreateNewCityForm.vue';
|
import CreateNewCityForm from './CreateNewCityForm.vue';
|
||||||
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
|
||||||
import FormModelPopup from './FormModelPopup.vue';
|
import FormModelPopup from './FormModelPopup.vue';
|
||||||
import ClaimFilter from 'src/pages/Claim/Card/ClaimFilter';
|
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved']);
|
const emit = defineEmits(['onDataSaved']);
|
||||||
|
|
||||||
|
@ -24,12 +23,15 @@ const postcodeFormData = reactive({
|
||||||
});
|
});
|
||||||
|
|
||||||
const townsFetchDataRef = ref(false);
|
const townsFetchDataRef = ref(false);
|
||||||
|
const countriesFetchDataRef = ref(false);
|
||||||
const provincesFetchDataRef = ref(false);
|
const provincesFetchDataRef = ref(false);
|
||||||
const countriesOptions = ref([]);
|
const countriesOptions = ref([]);
|
||||||
const provincesOptions = ref([]);
|
const provincesOptions = ref([]);
|
||||||
const townsOptions = ref([]);
|
const townsOptions = ref([]);
|
||||||
const town = ref({});
|
const town = ref({});
|
||||||
const townFilter = ref({});
|
const townFilter = ref({});
|
||||||
|
const countryFilter = ref({});
|
||||||
|
|
||||||
function onDataSaved(formData) {
|
function onDataSaved(formData) {
|
||||||
const newPostcode = {
|
const newPostcode = {
|
||||||
...formData,
|
...formData,
|
||||||
|
@ -61,14 +63,13 @@ function setTown(newTown, data) {
|
||||||
data.provinceFk = newTown?.provinceFk ?? newTown;
|
data.provinceFk = newTown?.provinceFk ?? newTown;
|
||||||
data.countryFk = newTown?.province?.countryFk ?? newTown;
|
data.countryFk = newTown?.province?.countryFk ?? newTown;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setCountry(countryFk, data) {
|
async function setCountry(countryFk, data) {
|
||||||
// town.value = newTown;
|
data.townFk = null;
|
||||||
// data.provinceFk = newTown?.provinceFk ?? newTown;
|
data.provinceFk = null;
|
||||||
data.countryFk = countryFk;
|
data.countryFk = countryFk;
|
||||||
// if (countryFk) {
|
|
||||||
// await fetchTowns(countryFk);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function filterTowns(name) {
|
async function filterTowns(name) {
|
||||||
if (name !== '') {
|
if (name !== '') {
|
||||||
townFilter.value.where = {
|
townFilter.value.where = {
|
||||||
|
@ -79,6 +80,17 @@ 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;
|
||||||
townFilter.value.where = {
|
townFilter.value.where = {
|
||||||
|
@ -88,6 +100,21 @@ async function fetchTowns(countryFk) {
|
||||||
};
|
};
|
||||||
await townsFetchDataRef.value?.fetch();
|
await townsFetchDataRef.value?.fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleProvinces(data) {
|
||||||
|
provincesOptions.value = data;
|
||||||
|
if (postcodeFormData.countryFk) {
|
||||||
|
await fetchTowns(postcodeFormData.countryFk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function handleTowns(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;
|
||||||
|
@ -101,55 +128,6 @@ async function onProvinceCreated(data) {
|
||||||
});
|
});
|
||||||
postcodeFormData.provinceFk = data.id;
|
postcodeFormData.provinceFk = data.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// watch(
|
|
||||||
// () => [postcodeFormData.countryFk],
|
|
||||||
// async (newCountryFk, oldValueFk) => {
|
|
||||||
// if (Array.isArray(newCountryFk)) {
|
|
||||||
// newCountryFk = newCountryFk[0];
|
|
||||||
// }
|
|
||||||
// if (Array.isArray(oldValueFk)) {
|
|
||||||
// oldValueFk = oldValueFk[0];
|
|
||||||
// }
|
|
||||||
// if (!!oldValueFk && newCountryFk !== oldValueFk) {
|
|
||||||
// postcodeFormData.provinceFk = null;
|
|
||||||
// postcodeFormData.townFk = null;
|
|
||||||
// }
|
|
||||||
// if (oldValueFk !== newCountryFk) {
|
|
||||||
// await fetchProvinces(newCountryFk);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// async function fetchProvinces(countryFk) {
|
|
||||||
// const provincesFilter = countryFk
|
|
||||||
// ? {
|
|
||||||
// where: {
|
|
||||||
// countryFk: countryFk,
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// : {};
|
|
||||||
// await provincesFetchDataRef.value.fetch(provincesFilter);
|
|
||||||
// }
|
|
||||||
// watch(
|
|
||||||
// () => postcodeFormData.provinceFk,
|
|
||||||
// async (newProvinceFk, oldValueFk) => {
|
|
||||||
// if (Array.isArray(newProvinceFk)) {
|
|
||||||
// newProvinceFk = newProvinceFk[0];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
async function handleProvinces(data) {
|
|
||||||
provincesOptions.value = data;
|
|
||||||
if (postcodeFormData.countryFk) {
|
|
||||||
await fetchTowns(postcodeFormData.countryFk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async function handleTowns(data) {
|
|
||||||
townsOptions.value = data;
|
|
||||||
}
|
|
||||||
async function handleCountries(data) {
|
|
||||||
countriesOptions.value = data;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -157,7 +135,7 @@ async function handleCountries(data) {
|
||||||
ref="provincesFetchDataRef"
|
ref="provincesFetchDataRef"
|
||||||
@on-fetch="handleProvinces"
|
@on-fetch="handleProvinces"
|
||||||
:sort-by="['name ASC']"
|
:sort-by="['name ASC']"
|
||||||
:limit="30"
|
:limit="3"
|
||||||
auto-load
|
auto-load
|
||||||
url="Provinces/location"
|
url="Provinces/location"
|
||||||
/>
|
/>
|
||||||
|
@ -170,6 +148,15 @@ async function handleCountries(data) {
|
||||||
auto-load
|
auto-load
|
||||||
url="Towns/location"
|
url="Towns/location"
|
||||||
/>
|
/>
|
||||||
|
<FetchData
|
||||||
|
ref="countriesFetchDataRef"
|
||||||
|
:limit="3"
|
||||||
|
:filter="countryFilter"
|
||||||
|
:sort-by="['name ASC']"
|
||||||
|
@on-fetch="handleCountries"
|
||||||
|
auto-load
|
||||||
|
url="Countries"
|
||||||
|
/>
|
||||||
|
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
url-create="postcodes"
|
url-create="postcodes"
|
||||||
|
@ -235,13 +222,11 @@ async function handleCountries(data) {
|
||||||
@on-province-created="onProvinceCreated"
|
@on-province-created="onProvinceCreated"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:sort-by="['name ASC']"
|
|
||||||
@on-fetch="handleCountries"
|
|
||||||
auto-load
|
|
||||||
url="Countries"
|
|
||||||
:limit="3"
|
|
||||||
: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