233 lines
7.3 KiB
HTML
233 lines
7.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">
|
|
<style>
|
|
.map-wrapper {
|
|
display: flex;
|
|
gap: 20px;
|
|
height: 600px;
|
|
}
|
|
.map-container {
|
|
flex: 1;
|
|
height: 600px;
|
|
border-radius: 12px;
|
|
overflow: hidden;
|
|
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
|
|
}
|
|
#customer-map {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
.customer-list-panel {
|
|
width: 320px;
|
|
height: 600px;
|
|
flex-shrink: 0;
|
|
background: #fff;
|
|
border-radius: 12px;
|
|
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
|
|
overflow: hidden;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.customer-list-header {
|
|
padding: 16px 20px;
|
|
border-bottom: 1px solid #eef0f4;
|
|
background: #fafbfc;
|
|
flex-shrink: 0;
|
|
}
|
|
.customer-list-header h5 {
|
|
margin: 0;
|
|
color: var(--title-color);
|
|
font-size: 1rem;
|
|
}
|
|
.customer-list-header .count {
|
|
color: var(--text-secondary);
|
|
font-size: 0.8rem;
|
|
margin-left: 8px;
|
|
}
|
|
.customer-list {
|
|
flex: 1 1 auto;
|
|
overflow-y: auto;
|
|
list-style: none;
|
|
padding: 0;
|
|
margin: 0;
|
|
height: 0;
|
|
}
|
|
.customer-list li {
|
|
padding: 14px 20px;
|
|
border-bottom: 1px solid #f3f5f8;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
transition: background 0.2s;
|
|
}
|
|
.customer-list li:hover {
|
|
background: #f7f9fc;
|
|
}
|
|
.customer-list li.active {
|
|
background: #eef4ff;
|
|
}
|
|
.customer-index {
|
|
width: 28px;
|
|
height: 28px;
|
|
border-radius: 50%;
|
|
background: var(--primary-color);
|
|
color: #fff;
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-shrink: 0;
|
|
}
|
|
.customer-name {
|
|
flex: 1;
|
|
color: var(--title-color);
|
|
font-size: 0.9rem;
|
|
line-height: 1.4;
|
|
}
|
|
.leaflet-popup-content-wrapper { border-radius: 8px; }
|
|
.leaflet-popup-content { margin: 12px 16px; }
|
|
.leaflet-popup-content h6 { margin-bottom: 4px; color: var(--title-color); }
|
|
.leaflet-popup-content p { margin-bottom: 0; color: var(--text-secondary); font-size: 0.875rem; }
|
|
.numbered-marker {
|
|
background: var(--primary-color);
|
|
color: #fff;
|
|
border-radius: 50%;
|
|
width: 32px;
|
|
height: 32px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-weight: 600;
|
|
font-size: 0.8rem;
|
|
border: 2px solid #fff;
|
|
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
|
|
}
|
|
|
|
@media (max-width: 992px) {
|
|
.map-wrapper {
|
|
flex-direction: column;
|
|
height: auto;
|
|
}
|
|
.map-container {
|
|
height: 400px;
|
|
flex: none;
|
|
}
|
|
.customer-list-panel {
|
|
width: 100%;
|
|
height: 300px;
|
|
flex: none;
|
|
}
|
|
}
|
|
</style>
|
|
{% 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 %}
|