Cargando registros...
0 puntos seleccionados
* {
box-sizing: border-box;
font-family: system-ui, -apple-system, sans-serif;
margin: 0;
padding: 0;
}
body {
background-color: #f1f5f9;
color: #1e293b;
padding-bottom: 95px;
}
header {
background-color: #0f172a;
color: #ffffff;
padding: 20px 15px;
text-align: center;
position: sticky;
top: 0;
z-index: 10;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
header p {
font-size: 0.85rem;
color: #94a3b8;
margin-top: 4px;
}
.buscador-contenedor {
max-width: 600px;
margin: 12px auto 0;
}
#buscador {
width: 100%;
padding: 10px 14px;
border-radius: 8px;
border: none;
font-size: 0.95rem;
outline: none;
}
.contenedor {
max-width: 600px;
margin: 15px auto;
padding: 0 15px;
display: flex;
flex-direction: column;
gap: 12px;
}
.mensaje-estado {
text-align: center;
color: #64748b;
padding: 20px;
}
.tarjeta {
background: #ffffff;
border-radius: 10px;
padding: 15px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
border-left: 5px solid #cbd5e1;
transition: border-color 0.2s, background-color 0.2s;
}
.tarjeta.seleccionada {
border-left-color: #2563eb;
background-color: #eff6ff;
}
.tarjeta-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 10px;
margin-bottom: 8px;
}
.store-id {
display: inline-block;
font-size: 0.75rem;
font-weight: 700;
color: #475569;
background-color: #e2e8f0;
padding: 2px 6px;
border-radius: 4px;
margin-bottom: 4px;
}
.tarjeta-header h2 {
font-size: 1rem;
line-height: 1.3;
}
.direccion {
font-size: 0.85rem;
color: #475569;
margin-bottom: 12px;
line-height: 1.4;
}
.check-ruta {
display: flex;
align-items: center;
gap: 5px;
font-size: 0.8rem;
font-weight: 600;
color: #2563eb;
cursor: pointer;
white-space: nowrap;
}
.check-ruta input {
width: 18px;
height: 18px;
cursor: pointer;
}
.botones {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.btn {
text-decoration: none;
text-align: center;
padding: 10px 5px;
border-radius: 6px;
font-size: 0.85rem;
font-weight: 600;
color: #ffffff;
}
.btn-llamar { background-color: #0284c7; }
.btn-whatsapp { background-color: #16a34a; }
.btn-waze { background-color: #33ccff; color: #0f172a; }
.btn-deshabilitado {
background-color: #cbd5e1;
color: #64748b;
pointer-events: none;
}
.panel-flotante {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #0f172a;
color: #ffffff;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.25);
z-index: 20;
}
.oculto {
display: none;
}
.acciones-ruta {
display: flex;
gap: 10px;
}
button {
border: none;
padding: 10px 14px;
border-radius: 6px;
font-weight: 600;
cursor: pointer;
}
.btn-secundario { background-color: #475569; color: #ffffff; }
.btn-ruta { background-color: #2563eb; color: #ffffff; }
let todosLosRegistros = [];
let puntosSeleccionados = [];
document.addEventListener('DOMContentLoaded', () => {
cargarCSV();
document.getElementById('buscador').addEventListener('input', (e) => {
const termino = e.target.value.toLowerCase().trim();
const filtrados = todosLosRegistros.filter(item =>
item.nombre.toLowerCase().includes(termino) ||
item.id.toLowerCase().includes(termino) ||
item.direccion.toLowerCase().includes(termino)
);
renderizarTarjetas(filtrados);
});
document.getElementById('btn-limpiar').addEventListener('click', () => {
puntosSeleccionados = [];
renderizarTarjetas(todosLosRegistros);
document.getElementById('buscador').value = '';
actualizarPanelRuta();
});
document.getElementById('btn-rutar').addEventListener('click', iniciarRutaMultipunto);
});
// Analizador CSV que respeta textos entre comillas con comas internas
function parsearLineaCSV(linea) {
const resultado = [];
let actual = '';
let dentroComillas = false;
for (let i = 0; i < linea.length; i++) {
const char = linea[i];
if (char === '"') {
dentroComillas = !dentroComillas;
} else if (char === ',' && !dentroComillas) {
resultado.push(actual.trim());
actual = '';
} else {
actual += char;
}
}
resultado.push(actual.trim());
return resultado;
}
async function cargarCSV() {
const contenedor = document.getElementById('lista-contactos');
try {
const respuesta = await fetch('datos.csv');
const texto = await respuesta.text();
const lineas = texto.trim().split(/\r?\n/);
// Se omite la fila 0 (Store ID,Node Name,Coordenadas,Direccion,Telefono)
for (let i = 1; i < lineas.length; i++) {
if (!lineas[i].trim()) continue;
const cols = parsearLineaCSV(lineas[i]);
if (cols.length < 4) continue;
const coordsLimpias = cols[2].replace(/\s+/g, '');
const telLimpio = (cols[4] || '').replace(/\D/g, '');
todosLosRegistros.push({
id: cols[0],
nombre: cols[1],
coordenadas: coordsLimpias,
direccion: cols[3],
telefono: telLimpio
});
}
renderizarTarjetas(todosLosRegistros);
} catch (error) {
contenedor.innerHTML = 'Error al leer datos.csv. Verifica que el archivo esté en la misma carpeta.
';
}
}
function renderizarTarjetas(lista) {
const contenedor = document.getElementById('lista-contactos');
contenedor.innerHTML = '';
if (lista.length === 0) {
contenedor.innerHTML = 'No se encontraron resultados.
';
return;
}
lista.forEach((item) => {
const estaSeleccionado = puntosSeleccionados.some(p => p.id === item.id);
const tieneTelefono = item.telefono.length >= 10;
const telWhatsApp = item.telefono.length === 10 ? `52${item.telefono}` : item.telefono;
const tarjeta = document.createElement('div');
tarjeta.className = `tarjeta ${estaSeleccionado ? 'seleccionada' : ''}`;
tarjeta.innerHTML = `
${item.direccion}
`;
const checkbox = tarjeta.querySelector('input[type="checkbox"]');
checkbox.addEventListener('change', (e) => {
if (e.target.checked) {
puntosSeleccionados.push({ id: item.id, coords: item.coordenadas });
tarjeta.classList.add('seleccionada');
} else {
puntosSeleccionados = puntosSeleccionados.filter(p => p.id !== item.id);
tarjeta.classList.remove('seleccionada');
}
actualizarPanelRuta();
});
contenedor.appendChild(tarjeta);
});
}
function actualizarPanelRuta() {
const panel = document.getElementById('panel-ruta');
const contador = document.getElementById('contador-ruta');
if (puntosSeleccionados.length > 0) {
panel.classList.remove('oculto');
contador.textContent = `${puntosSeleccionados.length} punto(s) en ruta`;
} else {
panel.classList.add('oculto');
}
}
function iniciarRutaMultipunto() {
if (puntosSeleccionados.length === 0) return;
if (puntosSeleccionados.length === 1) {
window.open(`https://waze.com{puntosSeleccionados[0].coords}&navigate=yes`, '_blank');
return;
}
const coordsLista = puntosSeleccionados.map(p => p.coords);
const destinoFinal = coordsLista[coordsLista.length - 1];
const paradasIntermedias = coordsLista.slice(0, -1).join('|');
const urlRuta = `https://google.com{destinoFinal}&waypoints=${encodeURIComponent(paradasIntermedias)}&travelmode=driving`;
window.open(urlRuta, '_blank');
}