Actualizar index.html
This commit is contained in:
375
index.html
375
index.html
@@ -6,25 +6,20 @@
|
||||
<title>Portal del Cliente - IntegraRepara</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script src="https://unpkg.com/lucide@latest"></script>
|
||||
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
background-color: #f4f7f9;
|
||||
background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
|
||||
background-size: 24px 24px;
|
||||
}
|
||||
body { background-color: #f4f7f9; background-image: radial-gradient(#e2e8f0 1px, transparent 1px); background-size: 24px 24px; }
|
||||
.fade-in { animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(20px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
.blob {
|
||||
position: absolute;
|
||||
filter: blur(60px);
|
||||
z-index: -1;
|
||||
opacity: 0.4;
|
||||
}
|
||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
|
||||
.blob { position: absolute; filter: blur(60px); z-index: -1; opacity: 0.4; }
|
||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
||||
|
||||
/* Ocultar marca de agua de leaflet para que quede más limpio */
|
||||
.leaflet-control-attribution { display: none !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="text-slate-800 font-sans antialiased min-h-screen flex flex-col items-center relative overflow-x-hidden">
|
||||
@@ -40,14 +35,6 @@
|
||||
<p class="text-sm font-black tracking-widest uppercase text-slate-500 animate-pulse">Conectando...</p>
|
||||
</div>
|
||||
|
||||
<div id="errorScreen" class="hidden w-full max-w-md mx-auto p-6 flex flex-col items-center justify-center min-h-screen text-center fade-in z-10 relative">
|
||||
<div class="w-24 h-24 bg-red-50 text-red-500 rounded-full flex items-center justify-center mb-6 shadow-xl shadow-red-500/20 border border-red-100">
|
||||
<i data-lucide="shield-alert" class="w-12 h-12"></i>
|
||||
</div>
|
||||
<h2 class="text-3xl font-black text-slate-800 mb-3 tracking-tight">Enlace no válido</h2>
|
||||
<p class="text-slate-500 font-medium leading-relaxed">Parece que este enlace ha caducado o no es correcto. Por favor, solicita un nuevo acceso a tu empresa reparadora.</p>
|
||||
</div>
|
||||
|
||||
<main id="mainContent" class="hidden w-full max-w-md mx-auto min-h-screen flex flex-col relative pb-10 z-10">
|
||||
|
||||
<div class="pt-10 pb-6 px-6 flex flex-col items-center text-center fade-in" style="animation-delay: 0.1s;">
|
||||
@@ -57,41 +44,27 @@
|
||||
<img id="companyLogo" src="" class="w-full h-full object-contain">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-[10px] font-black text-blue-600 uppercase tracking-widest mb-1.5 opacity-80">Portal del Cliente</p>
|
||||
<h1 id="companyName" class="text-2xl font-black tracking-tight text-slate-900 uppercase leading-none">Empresa Reparadora</h1>
|
||||
<h1 id="companyName" class="text-2xl font-black tracking-tight text-slate-900 uppercase leading-none">Empresa</h1>
|
||||
</div>
|
||||
|
||||
<div class="px-5 flex-1 flex flex-col gap-6 fade-in" style="animation-delay: 0.2s;">
|
||||
<h2 class="text-3xl font-black text-slate-800 tracking-tight pl-2">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2>
|
||||
|
||||
<h2 class="text-4xl font-black text-slate-800 tracking-tight pl-2">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2>
|
||||
|
||||
<div id="activeServicesContainer" class="space-y-6 mt-2">
|
||||
</div>
|
||||
<div id="activeServicesContainer" class="space-y-6 mt-2"></div>
|
||||
|
||||
<div id="noActiveServices" class="hidden text-center p-6 bg-white/80 backdrop-blur-xl rounded-[2.5rem] shadow-xl shadow-slate-200/40 border border-white">
|
||||
<div class="w-16 h-16 bg-slate-100 text-slate-400 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||
<i data-lucide="check-circle" class="w-8 h-8"></i>
|
||||
</div>
|
||||
<h3 class="text-lg font-black text-slate-800 tracking-tight">Todo al día</h3>
|
||||
<p class="text-xs text-slate-500 font-medium mt-2 mb-6">No tienes averías ni servicios activos en este momento con nosotros.</p>
|
||||
|
||||
<div class="bg-blue-50 border border-blue-100 p-5 rounded-2xl text-left">
|
||||
<h4 class="text-xs font-black text-blue-800 uppercase tracking-widest mb-1">¿Nueva Avería?</h4>
|
||||
<p class="text-[10px] text-blue-600 font-bold mb-4">Si necesitas un nuevo servicio de forma particular (fuera de seguro), puedes solicitarlo aquí. <br><br>⚠️ <i>Si es un siniestro del seguro, debes llamarles a ellos primero.</i></p>
|
||||
<button onclick="requestNewService()" class="w-full bg-blue-600 text-white font-black py-3 rounded-xl shadow-lg hover:bg-blue-700 transition-colors uppercase tracking-widest text-[10px]">
|
||||
Solicitar Servicio Particular
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="historyContainerWrapper" class="hidden mt-4">
|
||||
<h3 class="text-xs font-black text-slate-400 uppercase tracking-widest mb-3 ml-2">Historial de Expedientes</h3>
|
||||
<div id="historyServicesContainer" class="space-y-4">
|
||||
<h3 class="text-xs font-black text-slate-400 uppercase tracking-widest mb-3 ml-2">Historial</h3>
|
||||
<div id="historyServicesContainer" class="space-y-4"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
@@ -100,74 +73,44 @@
|
||||
: 'https://integrarepara-api.integrarepara.es';
|
||||
|
||||
let urlToken = "";
|
||||
let mapsToInit = [];
|
||||
let liveMaps = {};
|
||||
let liveMarkers = {};
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
lucide.createIcons();
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
urlToken = urlParams.get('token');
|
||||
|
||||
if (!urlToken) {
|
||||
showError();
|
||||
return;
|
||||
}
|
||||
if (!urlToken) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/public/portal/${urlToken}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.ok) throw new Error("Token inválido");
|
||||
|
||||
renderPortal(data.client, data.company, data.services);
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
showError();
|
||||
}
|
||||
} catch (e) { console.error(e); }
|
||||
});
|
||||
|
||||
function showError() {
|
||||
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
|
||||
setTimeout(() => {
|
||||
document.getElementById('loader').classList.add('hidden');
|
||||
document.getElementById('errorScreen').classList.remove('hidden');
|
||||
document.getElementById('errorScreen').classList.add('flex');
|
||||
}, 300);
|
||||
}
|
||||
|
||||
// LIMPIADOR INTELIGENTE DE TEXTOS DE ASEGURADORAS
|
||||
function summarizeDescription(rawText) {
|
||||
if (!rawText) return "Avería reportada.";
|
||||
|
||||
let text = rawText.replace(/\n/g, ' ');
|
||||
const regexCorte = /(\(|\bM\.O\b|\bMATERIAL\b|\bASEGURADO\b|\bTELEFONO\b|\bURGENTE\b)/i;
|
||||
let cutPos = text.search(regexCorte);
|
||||
|
||||
if (cutPos > 5) {
|
||||
text = text.substring(0, cutPos);
|
||||
}
|
||||
|
||||
if (cutPos > 5) text = text.substring(0, cutPos);
|
||||
text = text.trim();
|
||||
text = text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
|
||||
|
||||
let words = text.split(/\s+/);
|
||||
if (words.length > 10) {
|
||||
return words.slice(0, 10).join(" ") + "...";
|
||||
}
|
||||
|
||||
if (words.length > 10) return words.slice(0, 10).join(" ") + "...";
|
||||
if (text.length < 5) return "Reparación general solicitada.";
|
||||
|
||||
return text.endsWith('.') ? text : text + ".";
|
||||
}
|
||||
|
||||
// Helper para sumar 1 hora y crear la franja
|
||||
function addOneHour(timeStr) {
|
||||
if(!timeStr) return "";
|
||||
let [h, m] = timeStr.split(':').map(Number);
|
||||
let totalMins = h * 60 + m + 60;
|
||||
let newH = Math.floor(totalMins / 60);
|
||||
let newM = totalMins % 60;
|
||||
return `${String(newH).padStart(2,'0')}:${String(newM).padStart(2,'0')}`;
|
||||
let tm = h * 60 + m + 60;
|
||||
return `${String(Math.floor(tm / 60)).padStart(2,'0')}:${String(tm % 60).padStart(2,'0')}`;
|
||||
}
|
||||
|
||||
function formatDate(dateStr) {
|
||||
@@ -176,13 +119,12 @@
|
||||
const parts = dateStr.split('-');
|
||||
if(parts.length !== 3) return dateStr;
|
||||
const d = new Date(parts[0], parts[1]-1, parts[2]);
|
||||
const opciones = { weekday: 'long', day: 'numeric', month: 'long' };
|
||||
return d.toLocaleDateString('es-ES', opciones);
|
||||
return d.toLocaleDateString('es-ES', { weekday: 'long', day: 'numeric', month: 'long' });
|
||||
} catch(e) { return dateStr; }
|
||||
}
|
||||
|
||||
function renderPortal(client, company, allServices) {
|
||||
document.getElementById('companyName').innerText = company.name || "Empresa Reparadora";
|
||||
document.getElementById('companyName').innerText = company.name || "Empresa";
|
||||
if (company.logo) {
|
||||
document.getElementById('companyLogo').src = company.logo;
|
||||
document.getElementById('companyLogoContainer').classList.remove('hidden');
|
||||
@@ -191,77 +133,23 @@
|
||||
|
||||
const activeContainer = document.getElementById('activeServicesContainer');
|
||||
const historyContainer = document.getElementById('historyServicesContainer');
|
||||
const historyWrapper = document.getElementById('historyContainerWrapper');
|
||||
const noActiveDiv = document.getElementById('noActiveServices');
|
||||
|
||||
activeContainer.innerHTML = '';
|
||||
historyContainer.innerHTML = '';
|
||||
|
||||
let hasActive = false;
|
||||
let hasHistory = false;
|
||||
|
||||
allServices.forEach(srv => {
|
||||
const isFinalized = srv.status_name === 'Terminado';
|
||||
const isPendingWorker = (!srv.assigned_worker || srv.assigned_worker === 'Pendiente');
|
||||
|
||||
// Procesamos la descripción con la "mini-IA"
|
||||
const descLimpia = summarizeDescription(srv.description);
|
||||
|
||||
let statusHtml = '';
|
||||
|
||||
if (isFinalized) {
|
||||
// MODO HISTORIAL (Gris y apagado)
|
||||
statusHtml = `
|
||||
<div class="bg-slate-50 border border-slate-200 p-4 rounded-2xl flex items-center justify-between opacity-70 grayscale">
|
||||
<span class="text-[10px] font-black text-slate-500 uppercase flex items-center gap-1.5"><i data-lucide="archive" class="w-3.5 h-3.5"></i> ${srv.status_name}</span>
|
||||
<span class="text-xs font-black text-slate-400">${formatDate(srv.scheduled_date) || 'Cerrado'}</span>
|
||||
</div>
|
||||
`;
|
||||
} else if (isPendingWorker) {
|
||||
// MODO 1: AÚN NO HAY TÉCNICO (Botón de agendar bloqueado)
|
||||
statusHtml = `
|
||||
<div class="bg-slate-100 border border-slate-200 p-6 rounded-3xl text-center">
|
||||
<div class="w-12 h-12 bg-slate-200 text-slate-500 rounded-full flex items-center justify-center mx-auto mb-3 relative">
|
||||
<span class="absolute inset-0 bg-slate-300 rounded-full animate-ping opacity-30"></span>
|
||||
<i data-lucide="search" class="w-6 h-6 relative z-10"></i>
|
||||
</div>
|
||||
<h4 class="font-black text-slate-700 uppercase text-sm mb-1 tracking-tight">Buscando Técnico</h4>
|
||||
<p class="text-[10px] text-slate-500 font-bold leading-tight px-4 mt-2">Estamos asignando al técnico más cercano a tu domicilio.</p>
|
||||
<p class="text-[10px] text-blue-600 font-bold leading-tight px-4 mt-2">En cuanto esté asignado, se habilitará la opción de agendar la visita aquí mismo.</p>
|
||||
</div>
|
||||
`;
|
||||
} else if (srv.appointment_status === 'pending') {
|
||||
// MODO 2: PENDIENTE DE ACEPTACIÓN POR LA OFICINA
|
||||
statusHtml = `
|
||||
<div class="bg-amber-50 border border-amber-200 p-6 rounded-3xl text-center shadow-inner">
|
||||
<div class="w-12 h-12 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto mb-3 relative">
|
||||
<span class="absolute inset-0 bg-amber-200 rounded-full animate-ping opacity-50"></span>
|
||||
<i data-lucide="clock" class="w-6 h-6 relative z-10"></i>
|
||||
</div>
|
||||
<h4 class="font-black text-amber-800 uppercase text-sm mb-1 tracking-tight">Pendiente de Confirmación</h4>
|
||||
<p class="text-[10px] text-amber-700 font-bold leading-tight px-2 mt-2">Tu solicitud de fecha ha sido enviada. El técnico debe confirmarla en breve.</p>
|
||||
</div>
|
||||
`;
|
||||
} else if (srv.status_name === 'Visita Agendada' || (srv.scheduled_date && srv.scheduled_time)) {
|
||||
// MODO 3: CITA CONFIRMADA (FRANJA DE 1 HORA)
|
||||
const endT = addOneHour(srv.scheduled_time);
|
||||
statusHtml = `
|
||||
<div class="bg-gradient-to-br from-emerald-400 to-emerald-600 p-6 rounded-3xl flex items-center gap-5 text-white shadow-lg shadow-emerald-500/30 relative overflow-hidden">
|
||||
<div class="absolute -right-4 -top-4 opacity-10">
|
||||
<i data-lucide="calendar-check" class="w-32 h-32"></i>
|
||||
</div>
|
||||
<div class="w-14 h-14 bg-white/20 rounded-2xl flex items-center justify-center backdrop-blur-md border border-white/30 shrink-0 relative z-10">
|
||||
<i data-lucide="calendar-check" class="w-7 h-7 text-white"></i>
|
||||
</div>
|
||||
<div class="relative z-10">
|
||||
<p class="text-[9px] font-black uppercase tracking-widest text-emerald-100 mb-0.5">Visita Confirmada</p>
|
||||
<p class="font-black uppercase text-lg leading-none mb-1.5">${formatDate(srv.scheduled_date)}</p>
|
||||
<p class="text-sm font-bold text-emerald-50 flex items-center gap-1.5"><i data-lucide="clock" class="w-4 h-4"></i> Llegada aprox: ${srv.scheduled_time} - ${endT}</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else if (srv.status_name === 'Técnico de Camino') {
|
||||
// MODO 5: DE CAMINO
|
||||
</div>`;
|
||||
}
|
||||
else if (srv.status_name === 'Técnico de Camino') {
|
||||
// MODO MAPA EN VIVO
|
||||
statusHtml = `
|
||||
<div class="bg-indigo-50 border border-indigo-200 p-6 rounded-3xl relative overflow-hidden shadow-inner">
|
||||
<div class="flex items-center gap-4 mb-5 relative z-10">
|
||||
@@ -270,86 +158,56 @@
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="font-black text-indigo-800 uppercase text-base tracking-tight">¡Técnico en camino!</h4>
|
||||
<p class="text-[10px] text-indigo-600 font-bold mt-1">Llegando en breves momentos a tu domicilio.</p>
|
||||
<p class="text-[10px] text-indigo-600 font-bold mt-1">Sigue su ubicación en tiempo real.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-full h-24 bg-indigo-100/50 rounded-2xl border border-indigo-200 border-dashed flex items-center justify-center text-indigo-300 relative z-10">
|
||||
|
||||
<div id="liveMap-${srv.id}" class="w-full h-48 bg-slate-200 rounded-2xl border border-indigo-200 relative overflow-hidden z-10 shadow-inner">
|
||||
<div class="absolute inset-0 flex items-center justify-center bg-slate-100 z-[400]" id="map-loader-${srv.id}">
|
||||
<div class="text-center">
|
||||
<i data-lucide="map" class="w-6 h-6 mx-auto mb-1 opacity-50"></i>
|
||||
<p class="text-[8px] font-black uppercase tracking-widest mt-1">Señal GPS Próximamente</p>
|
||||
<i data-lucide="satellite" class="w-6 h-6 mx-auto mb-2 text-indigo-400 animate-pulse"></i>
|
||||
<p class="text-[9px] font-black uppercase tracking-widest text-slate-500">Buscando satélites...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else if (srv.status_name === 'En Reparación') {
|
||||
// MODO 8: TRABAJANDO
|
||||
mapsToInit.push(srv.id); // Guardamos para inicializar el mapa
|
||||
}
|
||||
else if (srv.status_name === 'En Reparación') {
|
||||
statusHtml = `
|
||||
<div class="bg-orange-50 border border-orange-200 p-6 rounded-3xl flex items-center gap-5 shadow-inner">
|
||||
<div class="w-14 h-14 bg-orange-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0">
|
||||
<i data-lucide="hammer" class="w-7 h-7"></i>
|
||||
</div>
|
||||
<div class="w-14 h-14 bg-orange-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0"><i data-lucide="hammer" class="w-7 h-7"></i></div>
|
||||
<div>
|
||||
<h4 class="font-black text-orange-800 uppercase text-base tracking-tight">En Reparación</h4>
|
||||
<p class="text-[10px] text-orange-600 font-bold mt-1.5 leading-tight">El técnico está trabajando en tu domicilio ahora mismo.</p>
|
||||
<p class="text-[10px] text-orange-600 font-bold mt-1.5 leading-tight">El técnico está trabajando en tu domicilio.</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else if (srv.status_name === 'Pausado / Incidencia') {
|
||||
// MODO 6: INCIDENCIA
|
||||
</div>`;
|
||||
}
|
||||
else if (srv.status_name === 'Visita Agendada' || (srv.scheduled_date && srv.scheduled_time)) {
|
||||
const endT = addOneHour(srv.scheduled_time);
|
||||
statusHtml = `
|
||||
<div class="bg-red-50 border border-red-200 p-6 rounded-3xl flex items-center gap-5 shadow-inner">
|
||||
<div class="w-14 h-14 bg-red-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0">
|
||||
<i data-lucide="alert-triangle" class="w-7 h-7"></i>
|
||||
<div class="bg-gradient-to-br from-emerald-400 to-emerald-600 p-6 rounded-3xl flex items-center gap-5 text-white shadow-lg shadow-emerald-500/30 relative overflow-hidden">
|
||||
<div class="w-14 h-14 bg-white/20 rounded-2xl flex items-center justify-center backdrop-blur-md border border-white/30 shrink-0 relative z-10"><i data-lucide="calendar-check" class="w-7 h-7 text-white"></i></div>
|
||||
<div class="relative z-10">
|
||||
<p class="text-[9px] font-black uppercase tracking-widest text-emerald-100 mb-0.5">Visita Confirmada</p>
|
||||
<p class="font-black uppercase text-lg leading-none mb-1.5">${formatDate(srv.scheduled_date)}</p>
|
||||
<p class="text-sm font-bold text-emerald-50 flex items-center gap-1.5"><i data-lucide="clock" class="w-4 h-4"></i> Llegada aprox: ${srv.scheduled_time} - ${endT}</p>
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="font-black text-red-800 uppercase text-base tracking-tight">Incidencia / Pausado</h4>
|
||||
<p class="text-[10px] text-red-600 font-bold mt-1.5 leading-tight">El servicio está pausado temporalmente. Te avisaremos pronto.</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
// MODO 4: PENDIENTE DE CITA NORMAL (Tiene técnico, no tiene cita)
|
||||
</div>`;
|
||||
}
|
||||
else {
|
||||
statusHtml = `
|
||||
<div class="bg-blue-50/50 border border-blue-100 p-6 rounded-3xl text-center">
|
||||
<div class="w-14 h-14 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto mb-4 relative">
|
||||
<span class="absolute inset-0 bg-blue-200 rounded-full animate-ping opacity-50"></span>
|
||||
<i data-lucide="calendar-clock" class="w-7 h-7 relative z-10"></i>
|
||||
</div>
|
||||
<h4 class="font-black text-slate-800 uppercase text-lg leading-tight tracking-tight">Pendiente de Cita</h4>
|
||||
<p class="text-[10px] text-slate-500 font-medium mt-2 mb-5 px-2">El técnico necesita saber cuándo puede pasar por tu domicilio para la reparación.</p>
|
||||
|
||||
<button onclick="startBooking('${srv.id}')" class="w-full bg-blue-600 text-white font-black py-4 rounded-2xl shadow-xl shadow-blue-600/30 hover:bg-blue-700 transition-all active:scale-95 flex justify-center items-center gap-2 uppercase tracking-widest text-[11px]">
|
||||
Agendar Visita Ahora <i data-lucide="arrow-right" class="w-4 h-4"></i>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
<div class="bg-slate-100 border border-slate-200 p-6 rounded-3xl text-center">
|
||||
<div class="w-12 h-12 bg-slate-200 text-slate-500 rounded-full flex items-center justify-center mx-auto mb-3"><i data-lucide="clock" class="w-6 h-6"></i></div>
|
||||
<h4 class="font-black text-slate-700 uppercase text-sm mb-1 tracking-tight">En Gestión</h4>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// ESTRUCTURA DE LA TARJETA MAESTRA UNIFICADA
|
||||
let cardHtml = '';
|
||||
|
||||
if (isFinalized) {
|
||||
// Historial compacto
|
||||
cardHtml = `
|
||||
<div class="bg-white/80 backdrop-blur-xl border border-slate-100 rounded-[2rem] p-5 mb-4 relative overflow-hidden">
|
||||
<div class="flex justify-between items-start mb-3">
|
||||
<div class="pr-2">
|
||||
<span class="text-[9px] font-black text-slate-400 uppercase tracking-widest">Exp. #${srv.title.replace('Expediente #', '').replace('🚨 URGENTE: ', '')}</span>
|
||||
<h3 class="font-black text-slate-800 text-sm mt-0.5 leading-tight">${descLimpia}</h3>
|
||||
</div>
|
||||
</div>
|
||||
${statusHtml}
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
// Tarjeta Principal Activa (La que te gusta pero ordenada para no ocultar el botón)
|
||||
cardHtml = `
|
||||
let cardHtml = `
|
||||
<div class="bg-white/80 backdrop-blur-xl border border-white shadow-xl shadow-slate-200/40 rounded-[2.5rem] p-6 mb-6 relative overflow-hidden">
|
||||
|
||||
<div class="flex justify-between items-start mb-5">
|
||||
<div class="pr-2">
|
||||
<span class="text-[10px] font-black text-slate-400 uppercase tracking-widest">Expediente #${srv.title.replace('Expediente #', '').replace('🚨 URGENTE: ', '')}</span>
|
||||
</div>
|
||||
${srv.assigned_worker && srv.assigned_worker !== 'Pendiente' ?
|
||||
`<div class="bg-slate-50 border border-slate-100 px-3 py-1.5 rounded-lg text-center shrink-0">
|
||||
<p class="text-[8px] uppercase font-black text-slate-400 mb-0.5">Técnico</p>
|
||||
@@ -357,79 +215,80 @@
|
||||
</div>` : ''
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
${statusHtml}
|
||||
</div>
|
||||
|
||||
<div class="pt-5 border-t border-slate-100 space-y-4">
|
||||
<div>
|
||||
<div class="mb-6">${statusHtml}</div>
|
||||
<div class="pt-5 border-t border-slate-100">
|
||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5">Motivo de la Visita</p>
|
||||
<h3 class="font-black text-slate-800 text-sm leading-snug">${descLimpia}</h3>
|
||||
</div>
|
||||
<div class="flex flex-col gap-3">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-8 h-8 bg-slate-50 rounded-full flex items-center justify-center text-slate-400 shrink-0 shadow-sm border border-slate-100"><i data-lucide="map-pin" class="w-4 h-4"></i></div>
|
||||
<p class="text-xs font-bold text-slate-600 leading-tight uppercase">${client.addresses[0] || "Dirección no especificada"}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-8 h-8 bg-slate-50 rounded-full flex items-center justify-center text-slate-400 shrink-0 shadow-sm border border-slate-100"><i data-lucide="phone" class="w-4 h-4"></i></div>
|
||||
<p class="text-xs font-bold text-slate-600">${client.phone}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${!isPendingWorker ? `
|
||||
<div class="grid grid-cols-2 gap-3 pt-5 mt-5 border-t border-slate-100">
|
||||
<button onclick="alert('Funcionalidad de llamada al técnico próximamente.')" class="bg-blue-50 border border-blue-100 text-blue-600 font-black py-3 rounded-xl hover:bg-blue-100 flex items-center justify-center gap-2 transition-all active:scale-95 shadow-sm">
|
||||
<i data-lucide="phone" class="w-4 h-4"></i> <span class="text-[10px] uppercase tracking-widest">Llamar</span>
|
||||
</button>
|
||||
<button onclick="alert('Funcionalidad de WhatsApp al técnico próximamente.')" class="bg-emerald-50 border border-emerald-100 text-emerald-600 font-black py-3 rounded-xl hover:bg-emerald-100 flex items-center justify-center gap-2 transition-all active:scale-95 shadow-sm">
|
||||
<i data-lucide="message-circle" class="w-4 h-4"></i> <span class="text-[10px] uppercase tracking-widest">WhatsApp</span>
|
||||
</button>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
if (isFinalized) {
|
||||
historyContainer.innerHTML += cardHtml;
|
||||
hasHistory = true;
|
||||
} else {
|
||||
activeContainer.innerHTML += cardHtml;
|
||||
hasActive = true;
|
||||
}
|
||||
if (isFinalized) historyContainer.innerHTML += cardHtml;
|
||||
else { activeContainer.innerHTML += cardHtml; hasActive = true; }
|
||||
});
|
||||
|
||||
// GESTIÓN DE VISIBILIDAD DE CONTENEDORES
|
||||
if (!hasActive) {
|
||||
activeContainer.classList.add('hidden');
|
||||
noActiveDiv.classList.remove('hidden');
|
||||
} else {
|
||||
activeContainer.classList.remove('hidden');
|
||||
noActiveDiv.classList.add('hidden');
|
||||
}
|
||||
|
||||
if (hasHistory) {
|
||||
historyWrapper.classList.remove('hidden');
|
||||
}
|
||||
if (!hasActive) document.getElementById('noActiveServices').classList.remove('hidden');
|
||||
|
||||
lucide.createIcons();
|
||||
|
||||
// Quitar loader
|
||||
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
|
||||
setTimeout(() => document.getElementById('loader').classList.add('hidden'), 300);
|
||||
setTimeout(() => {
|
||||
document.getElementById('loader').classList.add('hidden');
|
||||
document.getElementById('mainContent').classList.remove('hidden');
|
||||
|
||||
// INICIALIZAMOS LOS MAPAS
|
||||
mapsToInit.forEach(id => initLiveMap(id));
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function startBooking(serviceId) {
|
||||
window.location.href = `cita.html?token=${urlToken}&service=${serviceId}`;
|
||||
// ==========================================
|
||||
// LÓGICA DE MAPA EN TIEMPO REAL
|
||||
// ==========================================
|
||||
function initLiveMap(serviceId) {
|
||||
if(!document.getElementById(`map-${serviceId}`)) return;
|
||||
|
||||
// 1. Configuramos el mapa de Leaflet
|
||||
liveMaps[serviceId] = L.map(`map-${serviceId}`, { zoomControl: false, attributionControl: false }).setView([40.416775, -3.703790], 6);
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png').addTo(liveMaps[serviceId]);
|
||||
|
||||
// 2. Creamos un icono HTML personalizado (un puntito azul que brilla)
|
||||
const carIcon = L.divIcon({
|
||||
className: 'custom-div-icon',
|
||||
html: `<div style="position:relative;"><div style="background-color:#6366f1; width:20px; height:20px; border-radius:50%; border:3px solid white; box-shadow: 0 4px 6px rgba(0,0,0,0.3); position:relative; z-index:2;"></div><div style="position:absolute; top:-5px; left:-5px; width:30px; height:30px; background-color:#6366f1; border-radius:50%; opacity:0.4; animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite; z-index:1;"></div></div>`,
|
||||
iconSize: [20, 20],
|
||||
iconAnchor: [10, 10]
|
||||
});
|
||||
|
||||
liveMarkers[serviceId] = L.marker([40.416775, -3.703790], {icon: carIcon});
|
||||
|
||||
// 3. Ejecutamos la búsqueda de coordenadas cada 10 segundos
|
||||
fetchWorkerLocation(serviceId);
|
||||
setInterval(() => fetchWorkerLocation(serviceId), 10000);
|
||||
}
|
||||
|
||||
function requestNewService() {
|
||||
alert("Módulo de nuevo aviso particular en desarrollo. Próximamente el cliente podrá crear su propia avería desde aquí.");
|
||||
async function fetchWorkerLocation(serviceId) {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/public/portal/${urlToken}/location/${serviceId}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ok && data.location) {
|
||||
const loader = document.getElementById(`map-loader-${serviceId}`);
|
||||
if(loader) loader.classList.add('hidden'); // Ocultar pantalla de "Buscando satélites"
|
||||
|
||||
const lat = parseFloat(data.location.lat);
|
||||
const lng = parseFloat(data.location.lng);
|
||||
|
||||
// Si el marcador no está en el mapa, lo añadimos
|
||||
if (!liveMaps[serviceId].hasLayer(liveMarkers[serviceId])) {
|
||||
liveMarkers[serviceId].addTo(liveMaps[serviceId]);
|
||||
liveMaps[serviceId].setView([lat, lng], 15);
|
||||
} else {
|
||||
// Si ya está, lo movemos suavemente
|
||||
liveMarkers[serviceId].setLatLng([lat, lng]);
|
||||
liveMaps[serviceId].flyTo([lat, lng], 16, { animate: true, duration: 1.5 });
|
||||
}
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user