Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/js/lpost/delivery/map/src/js/ |
Upload File : |
import Formatting from "./Formatting"; import ViewManager from "./ViewManager"; import Balloon from "./Balloon"; import DateDeliverySelector from "./DateDeliverySelector"; export default class WidgetManager { prevDeliveryActiveId = false; constructor(options, orderManager) { this.orderManager = orderManager; this.Formatting = new Formatting(); this.options = options; } init() { return new Promise((resolve, reject) => { this.fetchHtml().then(html => { document.querySelector("body") .insertAdjacentHTML("beforeend", html); this.options.ajaxURL = "/bitrix/components/lpost/delivery.widget/ajax.php"; this.options.selectPoint = false; this.popup = this.createPopup(); this.container = BX("bx-soa-delivery"); this.popupContent = BX("lpost-pvz-popup").querySelector(".lpost-pvz"); this.point_options = { iconLayout: 'default#image', iconImageHref: '/bitrix/themes/lpost.delivery/map-point.png', iconImageOffset: [-15, -42], }; this.viewManager = new ViewManager(this, this.popupContent); this.setSelectedDelivery(); this.clearOldAddress(); this.createMap(); this._event(); resolve(this); }) }) } fetchHtml() { return new Promise((resolve, reject) => { BX.ajax({ url: '/bitrix/components/lpost/delivery.widget/ajax.php', data: { action: "show" }, method: "POST", onsuccess: data => resolve(data) }); }) } createMap() { if (typeof ymaps === "undefined") return false; ymaps.ready(e => { this.map = new ymaps.Map( this.popupContent.querySelector(".lpost-pvz__map"), { center: [55.757741, 37.624725], zoom: 10, controls: [] }, { suppressMapOpenBlock: true } ); this.objectManagerZone = new ymaps.ObjectManager({ clusterize: false, clusterDisableClickZoom: false, geoObjectOpenBalloonOnClick: true }); this.objectManagerPvz = new ymaps.ObjectManager({ clusterize: false, clusterDisableClickZoom: false, geoObjectOpenBalloonOnClick: false }); let popupContent = this.popupContent; this.yandeSearch = new ymaps.SuggestView( 'search-location', { provider: { suggest: (function (request, options) { // Код, чтобы вернуть подсказки с тем городом, который указан в местоположении let cityName = popupContent.querySelector("#search-location").placeholder; let array = []; return ymaps.suggest(cityName + ", " + request).then(items => { items.forEach(item => { if (item.displayName.indexOf(cityName) !== -1) { array.push(item); } }); return ymaps.vow.resolve(array); }); }) } } ); }) } getNumberZone (coords) { for (let polygon of this.polygons) { if (polygon.geometry.contains(coords)) { return { zoneNumber: polygon.properties.get("zoneNumber"), idPickup: polygon.properties.get("idPickup"), params: polygon.properties.get("params") }; } } return false; } getCityID () { return this.orderManager.getLocationId(); } setSelectedDelivery() { if(!this.orderManager) { return false; } this.selectedDelivery = this.orderManager.getSelectedDeliveryProfile() if(!this.selectedDelivery) { return false; } this.showDeliveryButtonLpost(this.selectedDelivery.ID); } showDeliveryButtonLpost(deliveryId) { let deliveryList = this.popupContent.querySelectorAll(".lpost-pvz__ctrl-item._button"); for (let deliveryItem of deliveryList) { deliveryItem.classList.remove("_active"); if (deliveryItem.dataset.id == deliveryId) { deliveryItem.classList.add("_active"); } } } createListPvz (cityID) { let _self = this; new Promise(function (resolve, reject) { let json = _self._request({ fields: { cityID: cityID, action: "pvz" }, async: false, type: "html" }); resolve(JSON.parse(json)); }).then(function (data) { _self.removeZone(); _self.setRegionBlock(data.city.name); _self.listPoints = data['pvz_list']; _self.createList(_self.listPoints); _self.viewManager.switch("pvz"); if (_self.map) { _self.createPointsPvz(_self.listPoints); _self.map.setCenter([data.city.lat, data.city.long], 12); } }); } createListZone (cityID) { let _self = this; new Promise(function (resolve, reject) { let json = _self._request({ fields: { cityID: cityID, action: "zone" }, async: false, type: "html" }); resolve(JSON.parse(json)); }).then(function (data) { _self.removePointsPvz(); _self.removePointsZone(); _self.setRegionBlock(data.city.name); _self.removeZone(); _self.createZone(data.zone, data['id_pickup'], { isCard: data['is_card'], isCash: data['is_cash'], deliverySpeed: data['params'] ? data['params']['deliverySpeed'] : {}, }); _self.viewManager.switch("zone"); _self.getDefaultCoords(data.city).then(function (data) { _self.map.setCenter(data.cityCoords, 12); if (data.geocode && data.geoObject) { let coords = data.geoObject.geometry.getCoordinates(); let dataZone = _self.getNumberZone(coords); if(dataZone){ _self.createPoint(coords, { address: data.geoObject.getAddressLine(), zoneNumber: dataZone['zoneNumber'], idPickup: dataZone['idPickup'], premiseNumber: dataZone ? data.geoObject.getPremiseNumber() : "", params: dataZone.params }, false); } } }); }); } getDefaultCoords (city) { return new Promise(BX.proxy(function (resolve, reject) { if (this.options.address) { ymaps.geocode(this.options.address).then(function (res) { resolve({ geocode: true, geoObject: res.geoObjects.get(0), cityCoords: [city.lat, city.long] }); }); } else { resolve({ geocode: false, cityCoords: [city.lat, city.long] }); } }, this)); } createZone (zones, idPickup, data = false) { if (!zones) return false; this.polygons = []; zones = zones.filter( a => typeof a.ZoneNumber == 'undefined'); for (let zone of zones.reverse()) { let dataPolygon = JSON.parse("{" + zone.WKT + "}"); let arPolygonCoordinates = []; for (let arItem of dataPolygon.Coordinates){ let arItemReverse = []; for(let key in arItem){ arItemReverse[key] = arItem[key].reverse(); } if(this.isMultiPolygon(arItemReverse)){ arPolygonCoordinates = arPolygonCoordinates.concat(this.createArPolygonFromMultiPolygon(arItemReverse)); }else{ arPolygonCoordinates.push(arItemReverse); } } for(let polygon of arPolygonCoordinates){ let ymapsPolygon = new ymaps.Polygon([polygon], { zoneNumber: 1, idPickup: idPickup, params: data }, { fillColor: "#6699ff", interactivityModel: 'default#transparent', opacity: 0.3, zIndex: 100, zIndexHover: 100, interactiveZIndex: 1, }) this.polygons.push(ymapsPolygon); this.map.geoObjects.add(ymapsPolygon); } } } removeZone () { if (this.map && this.map.geoObjects) { this.map.geoObjects.removeAll(); } } removePointsPvz (type) { if (this.objectManagerPvz) { this.objectManagerPvz.removeAll(); } } removePointsZone() { if (this.objectManagerZone) { return this.objectManagerZone.removeAll(); } } createPointsPvz(data) { if (!this.map) return false; this.removePointsPvz(); let features = []; for (let item of data) { if (!item['coord_lat'] || !item['coord_long']) { continue; } if (item.params) { if (item.params.deliverySpeed) { item.params.deliverySpeed.selected = "slow"; } } else { item.params = {}; } item.params.isCard = item.is_card; item.params.isCash = item.is_cash; features.push({ id: item.id_pickup, type: 'Feature', params: item.params, description: item.pickup_dop, timeWork: item.time_work, geometry: { type: 'Point', coordinates: [item['coord_lat'], item['coord_long']], radius: 100 }, properties: { balloonContent: new Balloon("pvz", { address: item.address, has_fitting_room: (item.has_fitting_room === 'Y'), id: item.id_pickup, buttonText: BX.message("LPOST_DELIVERY_SOA_MAP_BUTTON_CHOICE") }).generate().getHtml() }, options: this.point_options, }) } let collection = { type: 'FeatureCollection', features: features }; this.objectManagerPvz.add(collection); this.map.geoObjects.add(this.objectManagerPvz); } createPointPvz(item, deliverySpeed = "slow") { let id = (deliverySpeed === "fast") ? item.params.deliverySpeed.fast : item.params.deliverySpeed.slow; item.params.isCard = item.is_card; item.params.isCash = item.is_cash; let object = { id: id, type: 'Feature', params: item.params, description: item.pickup_dop, timeWork: item.time_work, geometry: { type: 'Point', coordinates: [item['coord_lat'], item['coord_long']], radius: 100 }, properties: { balloonContent: new Balloon("pvz", { address: item.address, has_fitting_room: (item.has_fitting_room === 'Y'), id: id, buttonText: BX.message("LPOST_DELIVERY_SOA_MAP_BUTTON_CHOICE") }).generate().getHtml() }, options: this.point_options, }; this.objectManagerPvz.add(object); } getDataPoint(id) { for (let item of this.listPoints) { if (item.params && item.params.deliverySpeed) { if (item.params.deliverySpeed.fast === id) { return item } else if (item.params.deliverySpeed.slow === id) { return item; } } } return false; } renderPointPvz(objectId, open = false) { let geoObject = this.objectManagerPvz.objects.getById(objectId); if (geoObject) { this.setSumDeliveryPoint(geoObject, objectId) .then(() => { if (open) { this.objectManagerPvz.objects.balloon.open(objectId); } }) } } createList(data) { let containerList = this.popupContent.querySelector(".lpost-pvz__list-wrapper"); BX.cleanNode(containerList); for(let item of data) { let content = BX.create({ tag: "div", attrs: { className: "list-item_content", }, children: [ BX.create({ tag: "div", text: this.Formatting.timeWork( JSON.parse(item.time_work), item.day_logistic ) }), BX.create({ tag: "div", text: item.pickup_dop }), BX.create({ tag: "div", attrs: { className: "lpost-pvz-list_button", }, dataset: { id: item.id_pickup, address: item.address, coords: item.coord_lat + "," + item.coord_long }, text: BX.message("LPOST_DELIVERY_SOA_MAP_BUTTON_CHOICE_PICK_UP") }) ] }); let title = BX.create({ tag: "div", attrs: { className: "lpost-pvz-list_title", }, text: item.address, children: [ BX.create({ tag: "div", attrs: { className: "title_item _metro" }, text: item.metro }), BX.create({ tag: "div", attrs: { className: "title_item _address" }, text: item.address }), BX.create({ tag: "div", attrs: { className: "title_item _payment" }, html: this.Formatting.paymentMethod(item.is_card, item.is_cash) }), ] }) ; let elem = BX.create("div", { attrs: { className: "lpost-pvz__item", }, children: [title, content] }); containerList.append(elem); } } setRegionBlock(name) { this.popupContent.querySelector(".lpost-pvz__ctrl-item._location span:last-child") .innerHTML = name; this.popupContent.querySelector("#search-location") .placeholder = name; } getProfileActive() { let selectedDeliveryID = this.selectedDelivery?.ID; if(!selectedDeliveryID) { return false; } return this.getDeliveryProfileById(selectedDeliveryID); } getProfileActiveId() { let profile = this.getProfileActive(); return profile["ID"] ?? false; } isLpostProfile() { let profileActive = this.orderManager.getSelectedDeliveryProfile(); if(!profileActive) { return false; } for (let profile of this.orderManager.options.profiles) { if (profile.ID === profileActive.ID) { return true; } } return false; } getDeliveryProfileById(id) { for (let profile of this.orderManager.options.profiles) { if (profile.ID == id) { return profile; } } return false; } isActiveDeliverySpeedBlock() { if (this.deliverySpeedContainer) { return this.deliverySpeedContainer.classList.contains("_active"); } return false; } updateDeliveryProfileActive() { let deliveryList = this.popupContent.querySelectorAll(".lpost-pvz__ctrl-item._button"); for (let deliveryItem of deliveryList) { if (!BX("ID_DELIVERY_ID_" + deliveryItem.dataset.id)) { deliveryItem.classList.add("_disabled"); // deliveryItem.remove(); } else { deliveryItem.classList.remove("_disabled"); } } } getActiveProfileType() { let activeProfile = this.getProfileActive(); if (activeProfile && this.isProfileZone(activeProfile)) { return "zone"; } else { return "pvz"; } } isProfileZone(profile) { return profile.CLASS_NAME.indexOf("Zone") >= 0 } createPopup() { let popup = new BX.PopupWindow("lpost-pvz-popup", null, { content: document.querySelector('.lpost-pvz'), bindOnResize: false, zIndex: 0, autoHide: true, offsetTop: 1, offsetLeft: 0, resizable: true, className: '', lightShadow: true, closeIcon: "x", closeByEsc: true, params: {}, overlay: { backgroundColor: "#000", opacity: 80 }, events: { onAfterPopupShow: function (e) { }, onPopupDestroy: function (e) { }, onPopupShow: function (e) { } } }); popup.setAnimation("scale"); return popup; } selectPoint(event) { let profileActive = this.getProfileActive(); let fullAddress = event.target.dataset.address; if (this.isProfileZone(profileActive)) { if(this.options.store_full_address == '1'){ if(event.target.dataset.porch) fullAddress += `, ${BX.message("LPOST_DELIVERY_SOA_PORCH")} ${event.target.dataset.porch}`; if(event.target.dataset.floor) fullAddress += `, ${BX.message("LPOST_DELIVERY_SOA_FLOOR")} ${event.target.dataset.floor}`; if(event.target.dataset.flat) fullAddress += `, ${BX.message("LPOST_DELIVERY_SOA_FLAT")} ${event.target.dataset.flat}`; if(event.target.dataset.code) fullAddress += `, ${BX.message("LPOST_DELIVERY_SOA_CODE")} ${event.target.dataset.code}`; } if(document.querySelector("input[name=LPOST_ZONE_NUMBER_ID]")) { document.querySelector("input[name=LPOST_ZONE_NUMBER_ID]").value = event.target.dataset.id; } if(document.querySelector("input[name=LPOST_ZONE_ADDRESS]")) { document.querySelector("input[name=LPOST_ZONE_ADDRESS]").value = fullAddress; } if(document.querySelector("input[name=LPOST_ZONE_PRICE]")) { document.querySelector("input[name=LPOST_ZONE_PRICE]").value = event.target.dataset.price; } if(document.querySelector("input[name=LPOST_ZONE_COORDS]")) { document.querySelector("input[name=LPOST_ZONE_COORDS]").value = event.target.dataset.coords; } if(document.querySelector("input[name=LPOST_ZONE_DAY]")) { document.querySelector("input[name=LPOST_ZONE_DAY]").value = event.target.dataset.day; } if (IS_SHOW_ADDITIONAL_PROPERTIES) { let flat = event.target.dataset.flat, floor = event.target.dataset.floor, porch = event.target.dataset.porch, code = event.target.dataset.code; if (typeof flat !== 'undefined') { if (document.querySelector("input[name=LPOST_ZONE_FLAT]")) { document.querySelector("input[name=LPOST_ZONE_FLAT]").value = flat; } this.orderManager.renderAdditionalField(flat, ADDITIONAL_PROPERTY_OPTION_CODES['FLAT']); } if (typeof floor !== 'undefined') { if (document.querySelector("input[name=LPOST_ZONE_FLOOR]")) { document.querySelector("input[name=LPOST_ZONE_FLOOR]").value = floor; } this.orderManager.renderAdditionalField(floor, ADDITIONAL_PROPERTY_OPTION_CODES['FLOOR']); } if (typeof porch !== 'undefined') { if (document.querySelector("input[name=LPOST_ZONE_PORCH]")) { document.querySelector("input[name=LPOST_ZONE_PORCH]").value = porch; } this.orderManager.renderAdditionalField(porch, ADDITIONAL_PROPERTY_OPTION_CODES['PORCH']); } if (typeof code !== 'undefined') { if (document.querySelector("input[name=LPOST_ZONE_CODE]")) { document.querySelector("input[name=LPOST_ZONE_CODE]").value = code; } this.orderManager.renderAdditionalField(code, ADDITIONAL_PROPERTY_OPTION_CODES['CODE']); } } if(event.target.dataset.dateDayDelivery){ document.querySelector("input[name=LPOST_ZONE_DATE_DAY_DELIVERY]") .value = event.target.dataset.dateDayDelivery } if(event.target.dataset.dateTimeDelivery){ document.querySelector("input[name=LPOST_ZONE_DATE_TIME_DELIVERY]") .value = event.target.dataset.dateTimeDelivery } } else { if (this.isActiveDeliverySpeedBlock()) { document.querySelector("input[name=LPOST_PVZ_ID]").value = this.getActiveDeliverySpeedId(); } else { document.querySelector("input[name=LPOST_PVZ_ID]").value = event.target.dataset.id; } document.querySelector("input[name=LPOST_PVZ_PRICE]").value = event.target.dataset.price; document.querySelector("input[name=LPOST_PVZ_ADDRESS]").value = event.target.dataset.address; document.querySelector("input[name=LPOST_PVZ_DAY]").value = event.target.dataset.day; } this.options.selectPoint = event.target.dataset.id; this.popup.close(); this.orderManager.renderAddress(fullAddress); this.orderManager.renderPrice(event.target.dataset.price); this.orderManager.refresh(); } getSumCalcDelivery(coords, pickupID) { return new Promise((resolve, reject) => { BX.ajax.runAction("lpost:delivery.api.DeliveryCalculate.getCalcForWidget", { data: { pickupId: pickupID, coords: coords, profileId: this.getProfileActive().ID, profileType: this.getActiveProfileType() } }) .then(response => { resolve(response.data); }) }) } setSumDeliveryPoint(geoObject, idPickup) { return new Promise((resolve, reject) => { if (geoObject.properties.balloonContent.indexOf("#") >= 0) { this.getSumCalcDelivery(geoObject.geometry.coordinates, idPickup) .then(data => { if (!data) { reject("data empty"); } geoObject.properties.balloonContent = geoObject.properties.balloonContent .replace("#SUM_FORMAT#", data.sumFormat ? data.sumFormat : 0); geoObject.properties.balloonContent = geoObject.properties.balloonContent .replace("#SUM#", data.sum ? data.sum : 0); geoObject.properties.balloonContent = geoObject.properties.balloonContent .replace(/#DELIVERY_DAY#/g, data.day); geoObject.properties.balloonContent = geoObject.properties.balloonContent .replace("#DESCRIPTION#", geoObject.description ? geoObject.description : "" ); if (geoObject.params.isCard || geoObject.params.isCash) { geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( "#METHOD_PAY#", this.Formatting.paymentMethod(geoObject.params.isCard, geoObject.params.isCash) ); } if (geoObject.timeWork) { geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( "#TIME_WORK#", this.Formatting.timeWork( JSON.parse(geoObject.timeWork), data.day ) ); } if (IS_SHOW_COURIER_DATES) { if(data.dateDelivery.length > 0) { let dateDeliverySelector = new DateDeliverySelector(data.dateDelivery); geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( "#DATE_DELIVERY_SELECTOR#", dateDeliverySelector.generate().getHtml() ); geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( "#DATE_DAY_DELIVERY#", dateDeliverySelector.getDayDefaultValue() ); geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( "#DATE_TIME_DELIVERY#", dateDeliverySelector.getTimeDefaultValue() ); } } else { geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( '#DATE_DAY_DELIVERY#', '' ); geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( '#DATE_TIME_DELIVERY#', '' ); geoObject.properties.balloonContent = geoObject.properties.balloonContent.replace( '#DATE_DELIVERY_SELECTOR#', '' ); } resolve({ sum: data.sum, day: data.day }); }) } else { resolve(true); } }) } _request(data = false) { let result; BX.ajax({ url: this.options.ajaxURL, method: "POST", data: data.fields, dataType: data.type || "html", async: data.async, onsuccess: function (response) { result = response; } }); return result; } removeDeliverySpeedContainer() { if (this.isActiveDeliverySpeedBlock()) { this.deliverySpeedContainer.classList.remove("_active"); this.deliverySpeedContainer.querySelector("#delivery-type-slow").checked = true; } } createDeliverySpeedContainer(objectId) { this.removeDeliverySpeedContainer(); let objectManager = (this.isProfileZone(this.getProfileActive())) ? this.objectManagerZone : this.objectManagerPvz; let geoObject = objectManager.objects.getById(objectId); if (geoObject && geoObject.params && geoObject.params.deliverySpeed) { if (geoObject.params.deliverySpeed.fast && geoObject.params.deliverySpeed.slow) { let objectFastId = geoObject.params.deliverySpeed.fast; let objectSlowId = geoObject.params.deliverySpeed.slow; this.deliverySpeedContainer = this.popupContent.querySelector(".lpost-pvz__ctrl-item._delivery-type"); this.deliverySpeedContainer.classList.add("_active"); this.deliverySpeedContainer.querySelector("#delivery-type-slow").dataset.idPickup = objectSlowId; this.deliverySpeedContainer.querySelector("#delivery-type-fast").dataset.idPickup = objectFastId; if (geoObject.params.deliverySpeed.selected === "fast") { this.deliverySpeedContainer.querySelector("#delivery-type-fast").checked = true; } else { this.deliverySpeedContainer.querySelector("#delivery-type-slow").checked = true; } } } } getDeliverySpeed() { return this.deliverySpeedContainer.querySelector(".delivery-type__group input:checked").value; } getActiveDeliverySpeedId() { return this.deliverySpeedContainer.querySelector(".delivery-type__group input:checked").dataset.idPickup; } reCreatePointZone(newPickupID = false) { let object = this.objectManagerZone.objects.balloon.getData(); let dataZone = this.getNumberZone(object.geometry.coordinates); this.createPoint( object.geometry.coordinates, { address: object.geometry.address, premiseNumber: object.geometry.premiseNumber, zoneNumber: dataZone['zoneNumber'], idPickup: newPickupID || dataZone['idPickup'], params: object.params }, true ); } createPoint(coords, content = {}, balloonOpen = true) { let properties = {}; let propertiesType = "zone"; if (content.premiseNumber && content.idPickup) { properties = { address: content.address, id: content.idPickup, coords: coords, buttonText: BX.message("LPOST_DELIVERY_SOA_MAP_BUTTON_CHOICE_ZONE") }; } else { if(Number.isInteger(content.zoneNumber)) { properties = { buttonText: BX.message("LPOST_DELIVERY_SOA_MAP_ADDRESS_EMPTY").replace("#ADDRESS#", content.address) }; } else { properties = { buttonText: BX.message("LPOST_DELIVERY_SOA_MAP_ADDRESS_OUTSIDE").replace("#ADDRESS#", content.address) }; } propertiesType = "notDelivery"; } this.objectManagerZone.add({ type: 'FeatureCollection', features: [{ id: content.idPickup, type: 'Feature', params: content.params, geometry: { type: 'Point', coordinates: coords, radius: 100, address: content.address, premiseNumber: content.premiseNumber }, properties: { balloonContent: new Balloon( propertiesType, properties ).generate().getHtml() }, options: this.point_options, }] }); this.map.geoObjects.add(this.objectManagerZone); let geoObject = this.objectManagerZone.objects.getById(content.idPickup); if (content.premiseNumber) { this.setSumDeliveryPoint(geoObject, content.idPickup) .then(BX.proxy(function (data) { if (balloonOpen) { setTimeout(BX.proxy(function () { if (balloonOpen) { this.objectManagerZone.objects.balloon.open(content.idPickup) .then(resolve => { this.renderingInformationFromTheBallon(); let map_balloon = BX("lpost-pvz-popup").querySelector('.lpost-pvz__map-balloon'); let input_day = map_balloon.querySelector('.input-date-day-delivery'), input_time = map_balloon.querySelector('.input-date-time-delivery'); BX.fireEvent(input_day, 'change'); BX.fireEvent(input_time, 'change'); }); this.createDeliverySpeedContainer(content.idPickup); } }, this), 5); let search_input = BX("lpost-pvz-popup").querySelector('#search-location'); if (!properties.address) { search_input.value = ''; } else if (search_input.value.trim() !== properties.address) { search_input.value = properties.address } } }, this)); } else { if (balloonOpen) { this.objectManagerZone.objects.balloon.open(content.idPickup).then(this.renderingInformationFromTheBallon); BX("lpost-pvz-popup").querySelector('#search-location').value = ''; } } } renderingInformationFromTheBallon() { BX("lpost-pvz-popup").querySelector('.lpost-pvz__view div.lpost-courier__form div.lpost-courier__form-info') .innerHTML = BX("lpost-pvz-popup").querySelector('.lpost-pvz__map-balloon').innerHTML; } clearOldAddress() { if(this.isLpostProfile() && this.prevDeliveryActiveId != this.getProfileActiveId()) { this.orderManager.renderAddress(""); } this.prevDeliveryActiveId = this.getProfileActiveId(); } _event() { let _self = this; if (typeof ymaps !== "undefined") { ymaps.ready(BX.proxy(function () { this.map.events.add('click', BX.proxy(function (e) { let objectId = e.get('objectId'); let profileActive = this.getProfileActive(); if (!objectId && this.isProfileZone(profileActive)) { _self.removeDeliverySpeedContainer(); _self.removePointsZone(); let coords = e.get('coords'); ymaps.geocode(coords).then(function (res) { let newObject = res.geoObjects.get(0); let dataZone = _self.getNumberZone(coords); if (dataZone && dataZone['params']['deliverySpeed']['selected']) { dataZone['params']['deliverySpeed']['selected'] = "slow"; } _self.createPoint(coords, { address: newObject.getAddressLine(), zoneNumber: dataZone['zoneNumber'], idPickup: dataZone['idPickup'], params: dataZone.params, premiseNumber: newObject.getPremiseNumber(), }); }); } }, this)); this.objectManagerZone.events.add("click", BX.proxy(function (e) { // event click point zone }, this)); this.objectManagerPvz.objects.events.add("click", e => { let objectId = e.get('objectId'); this.renderPointPvz(objectId, true); this.createDeliverySpeedContainer(objectId); }); this.yandeSearch.events.add('select', BX.proxy(function (e) { ymaps.geocode(e.get('item').value, {results: 1}) .then(BX.proxy(function (res) { let geoObject = res.geoObjects.get(0); let coords = geoObject.geometry.getCoordinates(); let dataZone = this.getNumberZone(coords); this.removePointsZone(); this.createPoint(coords, { address: geoObject.getAddressLine(), zoneNumber: dataZone['zoneNumber'], idPickup: dataZone['idPickup'], premiseNumber: geoObject.getPremiseNumber(), params: dataZone.params }); }, this)); }, this), this); }, this)); } BX.bindDelegate(this.popupContent, "click", {className: "map-balloon__button"}, e => this.selectPoint(e) ); BX.bindDelegate(this.popupContent, "click", {className: "lpost-courier__form-btn-for-map"}, function () { _self.viewManager.switch("zone_with_map") } ); BX.bindDelegate(this.popupContent, "click", {className: "lpost-pvz__return"}, function () { _self.viewManager.switch("zone") } ); BX.bindDelegate(this.popupContent, "click", {className: "lpost-pvz-list_button"}, BX.proxy(function (e) { let coords = e.target.dataset.coords; let pickupID = e.target.dataset.id; this.getSumCalcDelivery(coords, pickupID).then(BX.proxy(function (data) { e.target.dataset.price = data.sum; e.target.dataset.day = data.day; this.selectPoint(e); }, this)); }, this)); BX.bindDelegate(document, 'click', {className: "lpost-pvz__popup-run"}, BX.proxy(function (e) { if (!this.getCityID()) { alert(BX.message('LPOST_DELIVERY_SOA_ALERT_WHEN_THERE_IS_NO_CITY_ID')); return false; } this.updateDeliveryProfileActive(); this.setSelectedDelivery(); let profileActive = this.getProfileActive(); if (this.isProfileZone(profileActive)) { this.createListZone(this.getCityID()) } else { this.createListPvz(this.getCityID(), this.selectedDelivery.ID); } this.popup.show(); }, this) ); BX.bindDelegate(this.popupContent, 'change', {className: "delivery-type__group"}, BX.proxy(function (e) { let deliverySpeedId = this.getActiveDeliverySpeedId(); let objectManager; if (this.isProfileZone(this.getProfileActive())) { objectManager = this.objectManagerZone; } else { objectManager = this.objectManagerPvz; } let object = objectManager.objects.balloon.getData(); object.params.deliverySpeed.selected = this.getDeliverySpeed(); if (this.isProfileZone(this.getProfileActive())) { this.reCreatePointZone(deliverySpeedId); } else { objectManager.remove(object); this.createPointPvz( this.getDataPoint(deliverySpeedId), object.params.deliverySpeed.selected ); this.renderPointPvz(deliverySpeedId, true); } }, this) ); BX.bindDelegate(this.popupContent, 'click', {className: "lpost-pvz__ctrl-item"}, function (e) { if (!BX.hasClass(this, "_button")) return false; let deliveryID = this.dataset.id; _self.removeDeliverySpeedContainer(); if (deliveryID != _self.selectedDelivery.ID) { BX.fireEvent(BX("ID_DELIVERY_ID_" + deliveryID), "click"); _self.setSelectedDelivery(); let profile = _self.getDeliveryProfileById(_self.selectedDelivery.ID); if (_self.isProfileZone(profile)) { _self.removePointsPvz(); _self.createListZone(_self.getCityID()) } else { _self.removePointsZone(); _self.createListPvz(_self.getCityID()); } } } ); BX.bindDelegate(this.popupContent, 'change', {className: "input-date-day-delivery"}, e => { e.preventDefault(); let view = BX.findParent(e.target, {className: 'lpost-pvz__view'}); view.querySelectorAll('.map-balloon__button').forEach(elem => elem.dataset.dateDayDelivery = e.target.value); view.querySelectorAll('.input-date-day-delivery').forEach(elem => elem.value = e.target.value); } ); BX.bindDelegate(this.popupContent, 'change', {className: "input-date-time-delivery"}, e => { e.preventDefault(); let view = BX.findParent(e.target, {className: 'lpost-pvz__view'}); view.querySelectorAll('.map-balloon__button').forEach(elem => elem.dataset.dateTimeDelivery = e.target.value); view.querySelectorAll('.input-date-time-delivery').forEach(elem => elem.value = e.target.value); } ); BX.bindDelegate(this.popupContent, 'change', {className: "map-balloon__additional-input"}, e => { e.preventDefault(); let field_name = e.target.dataset.inputFor; let view = BX.findParent(e.target, {className: 'lpost-pvz__view'}); view.querySelectorAll('.map-balloon__button').forEach(elem => { elem.dataset[field_name] = e.target.value }); view.querySelectorAll(`.lpost-delivery-input-${field_name}`).forEach(elem => { elem.value = e.target.value }); } ); BX.bindDelegate(this.popupContent, 'change', {className: "lpost-delivery-day-selector"}, e => this.handlerChangeDaySelector(e) ); BX.addCustomEvent('onAjaxSuccess', data => { this.setSelectedDelivery(); this.clearOldAddress(); this.orderManager.displayInputAddressContainer(this.isLpostProfile()) }); } handlerChangeDaySelector(event) { this.hideAllTimeSelector(); this.showTimeSelector(event.target.value); } hideAllTimeSelector() { this.popupContent.querySelectorAll(`.lpost-delivery-time-selector`).forEach((e) => { e.style.display = "none"; }) } showTimeSelector(selectorId) { let timeSelectList = this.popupContent.querySelectorAll(`.lpost-delivery-time-selector[data-id='${selectorId}']`) timeSelectList.forEach((e,i) => { e.style.display = "block" }) } isEqualCoords(arCoords1, arCoords2) { return (arCoords1[0] === arCoords2[0]) && (arCoords1[1] === arCoords2[1]); } isMultiPolygon(array = []) { let first = array[0]; let last = array[array.length - 1]; return !this.isEqualCoords(first, last); } createArPolygonFromMultiPolygon(array = []) { let arPolygon = []; let firstKey = 0; let coords = []; for (let key in array) { if (Number(key) === firstKey) { coords = array[key]; continue; } if (this.isEqualCoords(coords, array[key])) { arPolygon.push(array.slice(firstKey, Number(key) + 1)) firstKey = Number(key) + 1; coords = array[firstKey]; } } return arPolygon; } }