901}902});903904const {905postalcode,906'pickup-id': pickupId,907'pickup-address': pickupAddress,908'pickup-name': pickupName,909} = userFields;910const serviceId = tcart_newDelivery.deliveryState.activeServiceUid;911const activeService = tcart_newDelivery.deliveryState.services[serviceId];912// Является ли активная доставка пунктом выдачи
const isActiveServiceIsPickup = activeService && activeService.type === 'pickup'; const hasAutocompleteFields = Object.values(activeService.fields).some(field => field.autocomplete); // Если есть сохраненный pickup-id и адрес сохранен, то выбираем и показываем информацию о ПВЗ if (this.deliveryState.isSavedAddressSelected && pickupId) { const pickupSearchbox = cart.querySelector('#pickup-searchbox'); const inputEl = cart.querySelector('[name="tildadelivery-pickup-name"]'); if (!pickupSearchbox || !inputEl) return; inputEl.setAttribute('data-pickup-id', userFields['pickup-id'] || ''); inputEl.setAttribute('data-pickup-address', userFields['pickup-address'] || ''); inputEl.setAttribute('data-option-selected', 'true'); inputEl.value = userFields['pickup-name'] || ''; // Устанавливаем адрес пикапа, потому что он сбрасывается при триггере смены типа доставки this.changePickupHandler(pickupId, pickupName, postalcode, pickupSearchbox, pickupAddress); this.showPickupInfo(userFields['pickup-id'], pickupSearchbox); } else if (this.deliveryState.isSavedAddressSelected || (!isActiveServiceIsPickup && !hasAutocompleteFields)) { this.updateDeliveryPrice(postalcode, serviceId); } // Выставляем флаг в дефолтное значение this.deliveryState.isSavedAddressSelected = false; }, /** * Очищает поля доставки и ререндерит ее */ clearDeliveryFields: function () { const that = tcart_newDelivery; window.t_delivery__autocompleteFields.clearState(); that.renderServices(); }, /** * Adding a Yandex map script * * @param {string} type map type, only 'yandex'. TODO: add 'google' * @param {string} ymapApiKey Yandex map key */ mapAppendScript: function (type, ymapApiKey) { var script = document.createElement('script'); script.src = 'https://api-maps.yandex.ru/2.1/?apikey=' + (ymapApiKey || '') + '&lang=ru_RU'; document.head.appendChild(script); }, /** * Init a Yandex map * * @param {string} type map type, only 'yandex'. TODO: add 'google' */ mapInit: function (type) { if (type === 'yandex') { if (window.ymaps !== undefined) { var mapWrapper = document.createElement('div'); mapWrapper.id = 'delivery-yandex-map'; document .getElementById('pickup-searchbox') .querySelector('.searchbox-inner-wrapper') .appendChild(mapWrapper); var that = this; window.ymaps.ready(function () { window.t_delivery__map = new ymaps.Map( 'delivery-yandex-map', { center: that.deliveryState.cityCoordinates || [55.76, 37.64], zoom: 8, controls: ['zoomControl'], minZoom: 3, maxZoom: 20, }, { yandexMapDisablePoiInteractivity: true, suppressMapOpenBlock: true, } ); var eventsPane = window.t_delivery__map.panes.get('events'); var eventsPaneEl = eventsPane.getElement(); var mobilePanelText = { EN: 'Use two fingers to move the map', RU: 'Чтобы переместить карту проведите по ней двумя пальцами', FR: 'Utilisez deux doigts pour déplacer la carte', DE: 'Verschieben der Karte mit zwei Fingern', ES: 'Para mover el mapa, utiliza dos dedos',