{% extends 'application/layout.html.twig' %}
{% block content %}
<h1>Распределительные центры</h1>
<form class="rc-search" id="searchForm">
<div class="form__group">
<input id="chainSearchInput" name="text" type="text" class="form__control" placeholder="Поиск по наименованию, адресу, сети">
</div>
<div class="form__btn">
<button type="submit" class="btn" disabled="disabled">
<span class="btn__icon">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.063 3.438a5.625 5.625 0 1 0 0 11.25 5.625 5.625 0 0 0 0-11.25zm-7.5 5.624a7.5 7.5 0 1 1 15 0 7.5 7.5 0 0 1-15 0z" fill="#405464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M13.04 13.04a.937.937 0 0 1 1.326 0l3.797 3.797a.937.937 0 0 1-1.326 1.326l-3.797-3.797a.937.937 0 0 1 0-1.326z"/></svg>
</span>
<span class="btn__text">Найти</span>
</button>
</div>
<div class="rc-search__dropdown dropdown scroll" id="searchResult">
</div>
</form>
<div class="main__content box rc-list">
<div class="rc-list__header">
<div class="btn-group rc-list__toggle a-toggle-list">
<button class="btn btn--light active show-list">
<span class="btn__icon">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.125 12.73a.806.806 0 0 1-.593-.24.806.806 0 0 1-.24-.594c0-.236.08-.43.24-.584a.826.826 0 0 1 .593-.229h13.75c.236 0 .434.08.594.24.16.16.24.35.24.573 0 .236-.08.434-.24.594a.807.807 0 0 1-.594.24H3.125zm0 3.728a.806.806 0 0 1-.593-.24.806.806 0 0 1-.24-.593c0-.236.08-.43.24-.583a.826.826 0 0 1 .593-.23h13.75c.236 0 .434.08.594.24.16.16.24.35.24.573 0 .25-.08.451-.24.604a.826.826 0 0 1-.594.23H3.125zm0-7.479a.806.806 0 0 1-.593-.24.782.782 0 0 1-.24-.572c0-.236.08-.434.24-.594.16-.16.357-.24.593-.24h13.75c.236 0 .434.08.594.24.16.16.24.358.24.594s-.08.43-.24.583a.826.826 0 0 1-.594.23H3.125zm0-3.75a.806.806 0 0 1-.593-.24.806.806 0 0 1-.24-.593c0-.236.08-.43.24-.583a.826.826 0 0 1 .593-.23h13.75c.236 0 .434.08.594.24.16.16.24.35.24.573 0 .25-.08.451-.24.604a.826.826 0 0 1-.594.23H3.125z"/></svg>
</span>
<span class="btn__text">Список</span>
</button>
<button class="btn btn--light show-map">
<span class="btn__icon">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10 16.417c1.778-1.625 3.09-3.101 3.938-4.427.847-1.327 1.27-2.49 1.27-3.49 0-1.583-.503-2.875-1.51-3.875-1.007-1-2.24-1.5-3.698-1.5-1.458 0-2.691.5-3.698 1.5-1.007 1-1.51 2.292-1.51 3.875 0 1 .434 2.16 1.302 3.48.868 1.319 2.17 2.798 3.906 4.437zm0 1.812c-.125 0-.247-.017-.365-.052A.867.867 0 0 1 9.313 18c-2.07-1.847-3.619-3.552-4.646-5.114C3.639 11.322 3.125 9.86 3.125 8.5c0-2.139.691-3.847 2.073-5.125C6.58 2.097 8.18 1.458 10 1.458c1.82 0 3.42.64 4.802 1.917 1.382 1.278 2.073 2.986 2.073 5.125 0 1.361-.514 2.823-1.542 4.386-1.027 1.562-2.576 3.267-4.646 5.114a.882.882 0 0 1-.312.177 1.256 1.256 0 0 1-.375.052z"/></svg>
</span>
<span class="btn__text">На карте</span>
</button>
</div>
<div class="rc-list__tags">
<div id="chainList" class="rc-tag">
<div class="rc-tag__item active">
<a href="#" class="rc rc-tag__link chainItem" data-id="">
<span class="rc__name">Все РЦ</span>
</a>
</div>
{% for chain in topChains %}
<div class="rc-tag__item">
<a href="#" class="rc rc-tag__link chainItem" data-id="{{ chain.id }}">
<span class="rc__logo">
<img width="30" height="30" src="{{ resizeImage(chain.image) }}" />
</span>
<span class="rc__name">{{ chain.name }}</span>
</a>
</div>
{% endfor %}
</div>
{% if showMoreChains %}
<button class="btn btn--light rc-tag__all">
<span class="btn__text">Еще</span>
<span class="btn__icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.375 8.675c.217-.183.458-.28.725-.287.267-.009.5.087.7.287l4.225 4.225 4.25-4.25c.183-.183.42-.27.713-.262.291.008.529.104.712.287.217.217.32.454.313.713a.994.994 0 0 1-.313.687l-4.975 4.975c-.1.1-.208.175-.325.225a.942.942 0 0 1-.375.075.941.941 0 0 1-.375-.075 1.038 1.038 0 0 1-.325-.225l-4.95-4.95a.916.916 0 0 1-.288-.7c.009-.267.105-.508.288-.725z"/></svg>
</span>
</button>
{% endif %}
</div>
</div>
<div class="rc-list__body">
<div class="tbl">
<div class="tbl__body scroll" id="hubTable">
{% include 'application/hubs/hub-table.html.twig' %}
</div>
</div>
<div class="map" id="map" style="height: 100%; width: 100%">
</div>
</div>
</div>
{% endblock %}
{% block popups %}
<div class="panel panel--rc scroll">
<button class="panel__close">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.636 3.636a1 1 0 0 1 1.414 0L16.364 14.95a1 1 0 0 1-1.415 1.414L3.636 5.05a1 1 0 0 1 0-1.414z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M3.636 16.364a1 1 0 0 1 0-1.414L14.95 3.636a1 1 0 1 1 1.414 1.414L5.05 16.364a1 1 0 0 1-1.414 0z"/></svg>
</button>
<div id="hubPanel"></div>
</div>
<div class="panel panel--review scroll">
<button class="panel__close">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.636 3.636a1 1 0 0 1 1.414 0L16.364 14.95a1 1 0 0 1-1.415 1.414L3.636 5.05a1 1 0 0 1 0-1.414z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M3.636 16.364a1 1 0 0 1 0-1.414L14.95 3.636a1 1 0 1 1 1.414 1.414L5.05 16.364a1 1 0 0 1-1.414 0z"/></svg>
</button>
<div class="panel__header">
<h3 class="panel__title text--primary">Оставьте отзыв</h3>
</div>
<div class="panel__body">
<form class="form" id="reviewForm">
<input type="hidden" name="hubId" id="reviewIdInput">
<div class="form__group form__group--md">
<div class="form__label">Номер заказа</div>
<input name="orderNumber" type="text" class="form__control w-sm" placeholder="Введите номер" required>
</div>
{% for key, rating in ratings %}
<div class="add-review__item ">
<div class="add-review__num">{{ loop.index }}</div>
<div class="add-review__title">{{ rating }}</div>
<div class="add-review__rating">
<input type="hidden" name="ratings[{{ key }}]">
<div class="rating a-rating">
<div class="rating__item"><svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M27.911 12.668a1.746 1.746 0 0 0-.593-.848 1.763 1.763 0 0 0-.97-.366l-6.363-.437-2.357-5.91A1.764 1.764 0 0 0 16 4a1.764 1.764 0 0 0-1.628 1.107l-2.4 5.942-6.32.405c-.352.023-.69.151-.969.368a1.779 1.779 0 0 0-.037 2.773l4.863 4.089-1.446 5.654a1.959 1.959 0 0 0 .75 2.087 1.936 1.936 0 0 0 2.152.064l5.024-3.163h.022l5.41 3.397c.277.18.6.276.931.277a1.776 1.776 0 0 0 1.393-.694 1.751 1.751 0 0 0 .3-1.52l-1.532-6.187 4.841-4.004a1.788 1.788 0 0 0 .557-1.927z"></path></svg></div>
<div class="rating__item"><svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M27.911 12.668a1.746 1.746 0 0 0-.593-.848 1.763 1.763 0 0 0-.97-.366l-6.363-.437-2.357-5.91A1.764 1.764 0 0 0 16 4a1.764 1.764 0 0 0-1.628 1.107l-2.4 5.942-6.32.405c-.352.023-.69.151-.969.368a1.779 1.779 0 0 0-.037 2.773l4.863 4.089-1.446 5.654a1.959 1.959 0 0 0 .75 2.087 1.936 1.936 0 0 0 2.152.064l5.024-3.163h.022l5.41 3.397c.277.18.6.276.931.277a1.776 1.776 0 0 0 1.393-.694 1.751 1.751 0 0 0 .3-1.52l-1.532-6.187 4.841-4.004a1.788 1.788 0 0 0 .557-1.927z"></path></svg></div>
<div class="rating__item"><svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M27.911 12.668a1.746 1.746 0 0 0-.593-.848 1.763 1.763 0 0 0-.97-.366l-6.363-.437-2.357-5.91A1.764 1.764 0 0 0 16 4a1.764 1.764 0 0 0-1.628 1.107l-2.4 5.942-6.32.405c-.352.023-.69.151-.969.368a1.779 1.779 0 0 0-.037 2.773l4.863 4.089-1.446 5.654a1.959 1.959 0 0 0 .75 2.087 1.936 1.936 0 0 0 2.152.064l5.024-3.163h.022l5.41 3.397c.277.18.6.276.931.277a1.776 1.776 0 0 0 1.393-.694 1.751 1.751 0 0 0 .3-1.52l-1.532-6.187 4.841-4.004a1.788 1.788 0 0 0 .557-1.927z"></path></svg></div>
<div class="rating__item"><svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M27.911 12.668a1.746 1.746 0 0 0-.593-.848 1.763 1.763 0 0 0-.97-.366l-6.363-.437-2.357-5.91A1.764 1.764 0 0 0 16 4a1.764 1.764 0 0 0-1.628 1.107l-2.4 5.942-6.32.405c-.352.023-.69.151-.969.368a1.779 1.779 0 0 0-.037 2.773l4.863 4.089-1.446 5.654a1.959 1.959 0 0 0 .75 2.087 1.936 1.936 0 0 0 2.152.064l5.024-3.163h.022l5.41 3.397c.277.18.6.276.931.277a1.776 1.776 0 0 0 1.393-.694 1.751 1.751 0 0 0 .3-1.52l-1.532-6.187 4.841-4.004a1.788 1.788 0 0 0 .557-1.927z"></path></svg></div>
<div class="rating__item"><svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M27.911 12.668a1.746 1.746 0 0 0-.593-.848 1.763 1.763 0 0 0-.97-.366l-6.363-.437-2.357-5.91A1.764 1.764 0 0 0 16 4a1.764 1.764 0 0 0-1.628 1.107l-2.4 5.942-6.32.405c-.352.023-.69.151-.969.368a1.779 1.779 0 0 0-.037 2.773l4.863 4.089-1.446 5.654a1.959 1.959 0 0 0 .75 2.087 1.936 1.936 0 0 0 2.152.064l5.024-3.163h.022l5.41 3.397c.277.18.6.276.931.277a1.776 1.776 0 0 0 1.393-.694 1.751 1.751 0 0 0 .3-1.52l-1.532-6.187 4.841-4.004a1.788 1.788 0 0 0 .557-1.927z"></path></svg></div>
</div>
</div>
</div>
{% endfor %}
<div class="form__group">
<textarea id="reviewMessage" name="message" class="form__control" cols="30" rows="3" placeholder="Оставить текстовый отзыв"></textarea>
</div>
<div class="form__group file a-file">
<div class="file__path">
<input name="image" type="file" accept="image/*">
<span class="file__icon"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M13.473 3.348a3.75 3.75 0 1 1 5.288 5.319L9.78 17.31a1.125 1.125 0 0 1-1.56-1.622l8.972-8.635a1.5 1.5 0 0 0-2.128-2.115l-9.197 9.178a3.37 3.37 0 0 0 4.766 4.766l7.697-7.68a1.125 1.125 0 1 1 1.59 1.594l-7.697 7.677a5.62 5.62 0 1 1-7.947-7.948l9.197-9.178z"/></svg></span>
<span id="reviewFileName" class="file__text">Приложить фото</span>
</div>
</div>
<div class="form__btn form__btn--sm">
<button class="btn btn--block" type="submit">Отправить</button>
</div>
</form>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(document).ready(function () {
function chainFilterClick(item) {
let id = item.attr('data-id');
$.ajax({
type: "GET",
url: '{{ path('select-chain') }}',
data: {
id: id,
},
dataType: "json",
success: function (data) {
$('#hubTable').html(data.html);
$('#chainList > div').removeClass('active');
$('#chainList a[data-id="' + id + '"]').parent().addClass('active');
updateMap(data.hubPoints);
initHubTable();
}
}).fail(function() {
popupAlert('Ошибка');
});
return false;
}
$('.chainItem').click(function () {
chainFilterClick($(this));
});
initHubTable();
$('.rc-search .form__control').keyup(function() {
if($(this).val()) {
$.ajax({
type: "GET",
url: '{{ path('hub-search-chain') }}',
data: {
text: $(this).val(),
},
success: function (html) {
$('#searchResult').html(html);
$('#searchResult .chainItem').click(function () {
$('.rc-search .dropdown').hide();
if ($(this).attr('data-id')) {
$('.rc-search .btn').attr('disabled','disabled');
$('#chainSearchInput').val('');
chainFilterClick($(this));
} else {
$('#chainSearchInput').val($(this).attr('data-name'));
}
});
}
});
}
});
$('#searchForm').submit(function () {
$.ajax({
type: "POST",
url: '{{ path('hub-search') }}',
data: $('#searchForm').serialize(),
dataType: "json",
success: function (data) {
$('#hubTable').html(data.html);
$('#chainList > div').removeClass('active');
$('#chainList a[data-id=""]').parent().addClass('active');
$('.rc-search .dropdown').hide();
updateMap(data.hubPoints);
initHubTable();
}
}).fail(function() {
popupAlert('Ошибка');
});
return false;
});
function initHubTable() {
$('.hubLink').click(function () {
openHubPanel($(this).attr('data-id'));
return false;
});
}
$('#reviewForm').submit(function () {
let messageRequired = false;
let rating = null;
{% for key, rating in ratings %}
rating = $(this).find('input[name="ratings[{{ key }}]"').val();
if (!rating) {
popupAlert('Не выбран рейтинг "{{ rating }}"');
return false;
}
if (rating == 1 || rating == 2) {
messageRequired = true;
}
{% endfor %}
if (messageRequired && !$('#reviewMessage').val()) {
popupAlert('Не заполнен отзыв');
return false;
}
$.ajax({
type: "POST",
url: '{{ path('review-message') }}',
data: new FormData($(this)[0]),
dataType: "json",
contentType: false,
processData: false,
success: function () {
popupAlert('Ваш отзыв отправлен');
closePopup();
$('.a-rating div.checked').removeClass('checked');
$('#reviewForm input').val('');
$('#reviewForm textarea').val('');
$('#reviewFileName').html('Приложить фото');
}
}).fail(function() {
popupAlert('Ошибка');
});
return false;
});
$('.a-rating div').click(function () {
let parent = $(this).parent();
parent.parent().find('input').val(parent.find('div.checked').length);
});
});
function openHubPanel(id) {
history.pushState({}, '', '/hubs/' + id);
$.ajax({
type: "GET",
url: '{{ path('hub-panel') }}',
data: {
id: id,
},
success: function (html) {
$('#hubPanel').html(html);
$('.panel--rc').addClass('showen');
$('.panel__backdrop').addClass('showen');
$('.tabs__link').on('click', function() {
var tabName = $(this).attr('data-tab');
$(this).closest('.tabs').find('.tabs__item.active').removeClass('active');
$(this).closest('.tabs__item').addClass('active');
$(this).closest('.tabs').find('.tabs__pane.show').removeClass('show');
$('#' + tabName + '').addClass('show');
});
$('.dropdown__toggle').on('click', function(){
if ( ! $(this).closest('.dropdown').hasClass('opened')) {
$('.dropdown').removeClass('opened');
$(this).closest('.dropdown').toggleClass('opened');
} else {
$('.dropdown').removeClass('opened');
}
return false;
});
$('.dropdown__menu').click(function(e){
e.stopPropagation();
});
new Carousel(document.querySelector('.carousel'), {
'infinite' : false,
'center': false,
'fill' : true,
'dragFree' : false
});
}
}).fail(function() {
popupAlert('Ошибка');
});
}
function openReview(id) {
closePopup();
$('#reviewIdInput').val(id);
$('.panel__backdrop').addClass('showen');
$('.panel--review').addClass('showen');
}
{% if openHubId %}
openHubPanel('{{ openHubId }}');
{% endif %}
</script>
<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>
<script>
{% set id = random() %}
let map{{ id }} = null;
function updateMap(hubPoints) {
let map = map{{ id }};
let objects = [];
map.geoObjects.each(function (geoObject) {
objects.push(geoObject);
return true;
});
for (let i = 0; i < objects.length; i++) {
map.geoObjects.remove(objects[i]);
}
for (let i = 0; i < hubPoints.length; i++) {
let point = hubPoints[i];
if (point.icon) {
let myPlacemark = new ymaps.Placemark(point.coordinates, {
hintContent: point.name,
}, {
iconLayout: 'default#image',
iconImageHref: point.icon,
iconImageSize: [30, 30],
iconImageOffset: [0, 0],
});
myPlacemark.events.add([
'click',
], function (e) {
openHubPanel(point.id);
});
map.geoObjects.add(myPlacemark);
}
}
}
ymaps.ready(function () {
map{{ id }} = new ymaps.Map('map',
{
center: [55.751574, 37.573856],
zoom: 6
},
{
searchControlProvider: 'yandex#search'
}
);
updateMap({{ hubPoints|json_encode|raw }});
});
</script>
{% endblock %}