mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 00:23:50 +00:00
Issue316 addresses search by postal code
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
:taggable="true"
|
||||
:multiple="false"
|
||||
@tag="addAddress"
|
||||
:loading="isLoading"
|
||||
:options="addresses">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
@@ -48,14 +49,17 @@
|
||||
|
||||
<script>
|
||||
import VueMultiselect from 'vue-multiselect';
|
||||
import { searchReferenceAddresses, fetchReferenceAddresses } from '../../api.js';
|
||||
|
||||
|
||||
export default {
|
||||
name: 'AddressSelection',
|
||||
components: { VueMultiselect },
|
||||
props: ['entity', 'updateMapCenter'],
|
||||
props: ['entity', 'context', 'updateMapCenter'],
|
||||
data() {
|
||||
return {
|
||||
value: null
|
||||
value: this.context.edit ? this.entity.address.addressReference : null,
|
||||
isLoading: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -107,6 +111,36 @@ export default {
|
||||
},
|
||||
listenInputSearch(query) {
|
||||
//console.log('listenInputSearch', query, this.isAddressSelectorOpen);
|
||||
if (!this.entity.selected.writeNew.postcode) {
|
||||
if (query.length > 2) {
|
||||
this.isLoading = true;
|
||||
searchReferenceAddresses(query, this.entity.selected.city).then(
|
||||
addresses => new Promise((resolve, reject) => {
|
||||
this.entity.loaded.addresses = addresses.results;
|
||||
this.isLoading = false;
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
console.log(error); //TODO better error handling
|
||||
this.isLoading = false;
|
||||
});
|
||||
} else {
|
||||
if (query.length === 0) { // Fetch all cities when suppressing the query
|
||||
this.isLoading = true;
|
||||
fetchReferenceAddresses(this.entity.selected.city).then(
|
||||
addresses => new Promise((resolve, reject) => {
|
||||
this.entity.loaded.addresses = addresses.results;
|
||||
this.isLoading = false;
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
this.isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isAddressSelectorOpen) {
|
||||
this.$data.value = { text: query };
|
||||
} else if (this.isEnteredCustomAddress) {
|
||||
|
@@ -18,6 +18,7 @@
|
||||
:multiple="false"
|
||||
@tag="addPostcode"
|
||||
:tagPlaceholder="$t('create_postal_code')"
|
||||
:loading="isLoading"
|
||||
:options="cities">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
@@ -48,15 +49,17 @@
|
||||
|
||||
<script>
|
||||
import VueMultiselect from 'vue-multiselect';
|
||||
import { searchCities, fetchCities } from '../../api.js';
|
||||
|
||||
export default {
|
||||
name: 'CitySelection',
|
||||
components: { VueMultiselect },
|
||||
props: ['entity', 'focusOnAddress', 'updateMapCenter'],
|
||||
props: ['entity', 'context', 'focusOnAddress', 'updateMapCenter'],
|
||||
emits: ['getReferenceAddresses'],
|
||||
data() {
|
||||
return {
|
||||
value: null
|
||||
value: this.context.edit ? this.entity.address.postcode : null,
|
||||
isLoading: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -93,6 +96,15 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
console.log('writeNew.postcode', this.entity.selected.writeNew.postcode, 'in mounted');
|
||||
if (this.context.edit) {
|
||||
this.entity.selected.city = this.value;
|
||||
this.entity.selected.postcode.name = this.value.name;
|
||||
this.entity.selected.postcode.code = this.value.code;
|
||||
this.$emit('getReferenceAddresses', this.value);
|
||||
if (this.value.center) {
|
||||
this.updateMapCenter(this.value.center);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
transName(value) {
|
||||
@@ -105,7 +117,6 @@ export default {
|
||||
this.entity.selected.postcode.code = value.code;
|
||||
this.entity.selected.postcode.coordinates = value.center.coordinates;
|
||||
this.entity.selected.writeNew.postcode = false;
|
||||
console.log('writeNew.postcode false, in selectCity');
|
||||
this.$emit('getReferenceAddresses', value);
|
||||
this.focusOnAddress();
|
||||
if (value.center) {
|
||||
@@ -113,7 +124,33 @@ export default {
|
||||
}
|
||||
},
|
||||
listenInputSearch(query) {
|
||||
//console.log('listenInputSearch', query, this.isCitySelectorOpen);
|
||||
if (query.length > 2) {
|
||||
this.isLoading = true;
|
||||
searchCities(query, this.entity.selected.country).then(
|
||||
cities => new Promise((resolve, reject) => {
|
||||
this.entity.loaded.cities = cities.results.filter(c => c.origin !== 3); // filter out user-defined cities
|
||||
this.isLoading = false;
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
console.log(error); //TODO better error handling
|
||||
this.isLoading = false;
|
||||
});
|
||||
} else {
|
||||
if (query.length === 0) { // Fetch all cities when suppressing the query
|
||||
this.isLoading = true;
|
||||
fetchCities(this.entity.selected.country).then(
|
||||
cities => new Promise((resolve, reject) => {
|
||||
this.entity.loaded.cities = cities.results.filter(c => c.origin !== 3); // filter out user-defined cities
|
||||
this.isLoading = false;
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
this.isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.isCitySelectorOpen) {
|
||||
this.$data.value = { text: query };
|
||||
} else if (this.isEnteredCustomCity) {
|
||||
|
Reference in New Issue
Block a user