methods: {
suggest(request, options) {
delete options['provider'];
return ymaps.suggest(request, options).then(items => {
let arrayResult = [];
let arrayPromises = [];
function pushGeoData(displayName, value, jsonData) {
arrayResult.push({displayName: displayName, value: value, jsonData: jsonData});
}
items.forEach(i => {
arrayPromises.push(ymaps.geocode(i.value).then(gc => {
let displayName = "";
let value = i.value;
if (!i.value.match(/.*подъезд.*/)) {
let geoObject = gc.geoObjects.get(0);
if (geoObject) {
let jsonData = JSON.stringify({
'city': geoObject.getLocalities()[0] || geoObject.getAdministrativeAreas()[0],
'street': geoObject.getThoroughfare() || geoObject.getLocalities()[0],
'house': geoObject.getPremiseNumber(),
});
if (geoObject.getCountryCode() == "RU") {
value = value.replace(geoObject.getCountry()+", ", "");
value = value.replace(geoObject.getAdministrativeAreas()[0]+", ", "");
displayName = "<div class='yandex-map-address_info'>"+value+"</div><div class='yandex-map-localities_info'>"+geoObject.getCountry()+", "+geoObject.getLocalities()[0]+"</div>";
value = value.replace("undefined", "");
displayName = displayName.replace("undefined", "");
pushGeoData(displayName, value, jsonData);
}
}
}
}));
});
return Promise.all(arrayPromises).then( function(){
console.log(this.test)
return ymaps.vow.resolve(arrayResult);
});
});
},
}
provider: {
suggest: this.suggest()
}