Autocomplete postcodes

This commit is contained in:
William Buezas 2024-01-10 12:11:49 -03:00
parent 50492151d8
commit 9aeba37140
6 changed files with 37 additions and 18 deletions

View File

@ -28,8 +28,8 @@ const countriesOptions = ref([]);
const provincesOptions = ref([]); const provincesOptions = ref([]);
const townsLocationOptions = ref([]); const townsLocationOptions = ref([]);
const onDataSaved = () => { const onDataSaved = (dataSaved) => {
emit('onDataSaved'); emit('onDataSaved', dataSaved);
}; };
const onCityCreated = async () => { const onCityCreated = async () => {

View File

@ -42,8 +42,8 @@ const { t } = useI18n();
const closeButton = ref(null); const closeButton = ref(null);
const isLoading = ref(false); const isLoading = ref(false);
const onDataSaved = () => { const onDataSaved = (dataSaved) => {
emit('onDataSaved'); emit('onDataSaved', dataSaved);
closeForm(); closeForm();
}; };
@ -59,7 +59,7 @@ const closeForm = () => {
:default-actions="false" :default-actions="false"
:url-create="urlCreate" :url-create="urlCreate"
:model="model" :model="model"
@on-data-saved="onDataSaved()" @on-data-saved="onDataSaved($event)"
> >
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<span ref="closeButton" class="close-icon" v-close-popup> <span ref="closeButton" class="close-icon" v-close-popup>

View File

@ -22,8 +22,12 @@ const provincesLocationOptions = ref([]);
const countriesOptions = ref([]); const countriesOptions = ref([]);
const postcodesOptions = ref([]); const postcodesOptions = ref([]);
const onPostcodeCreated = async () => { const onPostcodeCreated = async ({ code, provinceFk, townFk, countryFk }, formData) => {
postcodeFetchDataRef.value.fetch(); postcodeFetchDataRef.value.fetch();
formData.postcode = code;
formData.provinceFk = provinceFk;
formData.city = citiesLocationOptions.value.find((town) => town.id === townFk).name;
formData.countryFk = countryFk;
}; };
</script> </script>
@ -49,7 +53,12 @@ const onPostcodeCreated = async () => {
auto-load auto-load
url="Countries" url="Countries"
/> />
<FetchData
ref="postcodeFetchDataRef"
url="Postcodes/location"
@on-fetch="(data) => (postcodesOptions = data)"
auto-load
/>
<FormModel <FormModel
:url-update="`Clients/${route.params.id}/updateFiscalData`" :url-update="`Clients/${route.params.id}/updateFiscalData`"
:url="`Clients/${route.params.id}/getCard`" :url="`Clients/${route.params.id}/getCard`"
@ -114,7 +123,7 @@ const onPostcodeCreated = async () => {
> >
<template #form> <template #form>
<CustomerCreateNewPostcode <CustomerCreateNewPostcode
@on-data-saved="onPostcodeCreated($event)" @on-data-saved="onPostcodeCreated($event, data)"
/> />
</template> </template>
<template #option="scope"> <template #option="scope">
@ -136,7 +145,6 @@ const onPostcodeCreated = async () => {
</VnSelectCreate> </VnSelectCreate>
</div> </div>
<div class="col"> <div class="col">
<!-- ciudades -->
<VnSelectFilter <VnSelectFilter
:label="t('City')" :label="t('City')"
:options="citiesLocationOptions" :options="citiesLocationOptions"
@ -169,7 +177,7 @@ const onPostcodeCreated = async () => {
hide-selected hide-selected
option-label="name" option-label="name"
option-value="id" option-value="id"
v-model="data.province" v-model="data.provinceFk"
> >
<template #option="scope"> <template #option="scope">
<QItem v-bind="scope.itemProps"> <QItem v-bind="scope.itemProps">
@ -189,7 +197,7 @@ const onPostcodeCreated = async () => {
hide-selected hide-selected
option-label="country" option-label="country"
option-value="id" option-value="id"
v-model="data.country" v-model="data.countryFk"
/> />
</div> </div>
</VnRow> </VnRow>

View File

@ -36,8 +36,12 @@ const provincesLocationOptions = ref([]);
const countriesOptions = ref([]); const countriesOptions = ref([]);
const postcodesOptions = ref([]); const postcodesOptions = ref([]);
const onPostcodeCreated = async () => { const onPostcodeCreated = async ({ code, provinceFk, townFk, countryFk }, formData) => {
postcodeFetchDataRef.value.fetch(); postcodeFetchDataRef.value.fetch();
formData.postcode = code;
formData.provinceFk = provinceFk;
formData.city = citiesLocationOptions.value.find((town) => town.id === townFk).name;
formData.countryFk = countryFk;
}; };
</script> </script>
@ -81,7 +85,6 @@ const onPostcodeCreated = async () => {
</QToolbar> </QToolbar>
<FormModel <FormModel
:form-initial-data="newClientForm" :form-initial-data="newClientForm"
:observe-form-changes="false"
model="client" model="client"
url-create="Clients/createWithUser" url-create="Clients/createWithUser"
> >
@ -148,7 +151,7 @@ const onPostcodeCreated = async () => {
> >
<template #form> <template #form>
<CustomerCreateNewPostcode <CustomerCreateNewPostcode
@on-data-saved="onPostcodeCreated($event)" @on-data-saved="onPostcodeCreated($event, data)"
/> />
</template> </template>
<template #option="scope"> <template #option="scope">

View File

@ -24,8 +24,12 @@ const provincesLocationOptions = ref([]);
const townsLocationOptions = ref([]); const townsLocationOptions = ref([]);
const countriesOptions = ref([]); const countriesOptions = ref([]);
const onPostcodeCreated = async () => { const onPostcodeCreated = async ({ code, provinceFk, townFk, countryFk }, formData) => {
postcodeFetchDataRef.value.fetch(); postcodeFetchDataRef.value.fetch();
formData.postcode = code;
formData.provinceFk = provinceFk;
formData.city = townsLocationOptions.value.find((town) => town.id === townFk).name;
formData.countryFk = countryFk;
}; };
</script> </script>
<template> <template>
@ -179,7 +183,7 @@ const onPostcodeCreated = async () => {
> >
<template #form> <template #form>
<CustomerCreateNewPostcode <CustomerCreateNewPostcode
@on-data-saved="onPostcodeCreated($event)" @on-data-saved="onPostcodeCreated($event, data)"
/> />
</template> </template>
<template #option="scope"> <template #option="scope">

View File

@ -65,8 +65,11 @@ const onBankEntityCreated = (data) => {
bankEntitiesOptions.value.push(data); bankEntitiesOptions.value.push(data);
}; };
const onPostcodeCreated = async () => { const onPostcodeCreated = async ({ code, provinceFk, townFk }, formData) => {
postcodeFetchDataRef.value.fetch(); postcodeFetchDataRef.value.fetch();
formData.postcode = code;
formData.provinceFk = provinceFk;
formData.city = townsOptions.value.find((town) => town.id === townFk).name;
}; };
onMounted(async () => { onMounted(async () => {
@ -193,7 +196,7 @@ onMounted(async () => {
> >
<template #form> <template #form>
<CustomerCreateNewPostcode <CustomerCreateNewPostcode
@on-data-saved="onPostcodeCreated($event)" @on-data-saved="onPostcodeCreated($event, data)"
/> />
</template> </template>
<template #option="scope"> <template #option="scope">
@ -360,6 +363,7 @@ onMounted(async () => {
</template> </template>
</VnSelectCreate> </VnSelectCreate>
</VnRow> </VnRow>
<pre>{{ data }}</pre>
</template> </template>
</FormModel> </FormModel>
</QPage> </QPage>