112 lines
4.3 KiB
HTML
112 lines
4.3 KiB
HTML
{% extends 'base.html' %}
|
|
{% load static i18n i18n_tags %}
|
|
|
|
{% block breadcrumb %}{% include 'includes/breadcrumb.html' %}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css">
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<section class="section bg-white py-4">
|
|
<div class="container">
|
|
<div class="section-title">
|
|
<h2>{% trans '客户分布' %}</h2>
|
|
<p>{% trans '我们的客户遍布全国各地' %}</p>
|
|
</div>
|
|
<div class="map-wrapper">
|
|
<div class="map-container">
|
|
<div id="customer-map"></div>
|
|
</div>
|
|
<div class="customer-list-panel">
|
|
<div class="customer-list-header">
|
|
<h5>{% trans '客户列表' %}<span class="count" id="customer-count"></span></h5>
|
|
</div>
|
|
<ul class="customer-list" id="customer-list"></ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const map = L.map('customer-map').setView([35.8617, 104.1954], 4);
|
|
const markers = {};
|
|
|
|
L.tileLayer('https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}', {
|
|
subdomains: ['1', '2', '3', '4'],
|
|
attribution: '© 高德地图'
|
|
}).addTo(map);
|
|
|
|
function createNumberedIcon(index, color) {
|
|
return L.divIcon({
|
|
className: '',
|
|
html: '<div class="numbered-marker" style="background:' + (color || '#165DFF') + ';">' + index + '</div>',
|
|
iconSize: [32, 32],
|
|
iconAnchor: [16, 16],
|
|
popupAnchor: [0, -16]
|
|
});
|
|
}
|
|
|
|
fetch("{% url 'customer_locations_api' %}")
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const listEl = document.getElementById('customer-list');
|
|
const countEl = document.getElementById('customer-count');
|
|
const locations = data.locations || [];
|
|
|
|
countEl.textContent = '(' + locations.length + ')';
|
|
|
|
locations.forEach(loc => {
|
|
let marker;
|
|
if (loc.icon) {
|
|
const customIcon = L.icon({
|
|
iconUrl: loc.icon,
|
|
iconSize: [32, 32],
|
|
iconAnchor: [16, 16],
|
|
popupAnchor: [0, -16]
|
|
});
|
|
marker = L.marker([loc.lat, loc.lng], { icon: customIcon });
|
|
} else {
|
|
marker = L.marker([loc.lat, loc.lng], {
|
|
icon: createNumberedIcon(loc.index, loc.color)
|
|
});
|
|
}
|
|
marker.addTo(map);
|
|
markers[loc.id] = marker;
|
|
|
|
if (loc.name || loc.address || loc.description) {
|
|
let popup = '';
|
|
if (loc.name) popup += '<h6>' + loc.name + '</h6>';
|
|
if (loc.address) popup += '<p><i class="fa fa-map-marker"></i> ' + loc.address + '</p>';
|
|
if (loc.description) popup += '<p>' + loc.description + '</p>';
|
|
if (popup) marker.bindPopup(popup);
|
|
}
|
|
|
|
const li = document.createElement('li');
|
|
li.dataset.id = loc.id;
|
|
li.innerHTML = '<span class="customer-index" style="background:' + (loc.color || '#165DFF') + ';">' + loc.index + '</span>' +
|
|
'<span class="customer-name">' + (loc.name || '-') + '</span>';
|
|
li.addEventListener('click', function() {
|
|
document.querySelectorAll('#customer-list li').forEach(el => el.classList.remove('active'));
|
|
li.classList.add('active');
|
|
map.flyTo([loc.lat, loc.lng], 8, { duration: 0.8 });
|
|
if (markers[loc.id]) {
|
|
markers[loc.id].openPopup();
|
|
}
|
|
});
|
|
listEl.appendChild(li);
|
|
});
|
|
|
|
if (locations.length) {
|
|
const bounds = L.latLngBounds(locations.map(loc => [loc.lat, loc.lng]));
|
|
map.fitBounds(bounds, { padding: [60, 60] });
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|