Actualizar index.html

This commit is contained in:
2026-02-24 20:27:37 +00:00
parent 2985b45916
commit 9d5a5cdc21

View File

@@ -9,7 +9,6 @@
<style> <style>
body { body {
background-color: #f4f7f9; background-color: #f4f7f9;
/* Patrón de fondo muy sutil */
background-image: radial-gradient(#e2e8f0 1px, transparent 1px); background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
background-size: 24px 24px; background-size: 24px 24px;
} }
@@ -24,6 +23,8 @@
z-index: -1; z-index: -1;
opacity: 0.4; opacity: 0.4;
} }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
</style> </style>
</head> </head>
<body class="text-slate-800 font-sans antialiased min-h-screen flex flex-col items-center relative overflow-x-hidden"> <body class="text-slate-800 font-sans antialiased min-h-screen flex flex-col items-center relative overflow-x-hidden">
@@ -57,7 +58,7 @@
</div> </div>
</div> </div>
<p class="text-[10px] font-black text-blue-600 uppercase tracking-widest mb-1.5 opacity-80">Gestión de Siniestro</p> <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 Reparadora</h1>
</div> </div>
@@ -65,74 +66,33 @@
<div class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] shadow-xl shadow-slate-200/40 border border-white"> <div class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] shadow-xl shadow-slate-200/40 border border-white">
<h2 class="text-3xl font-black text-slate-800 mb-1 tracking-tight">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2> <h2 class="text-3xl font-black text-slate-800 mb-1 tracking-tight">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2>
<p class="text-sm text-slate-500 font-medium mb-6">Detalles de tu expediente <span id="serviceRef" class="font-bold text-slate-700 bg-slate-100 px-2 py-0.5 rounded text-xs ml-1">#0000</span></p>
<div id="dateContainer"> <div id="activeServicesContainer" class="mt-6 space-y-6">
</div> </div>
</div>
<div id="workerCard" class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] border border-white shadow-xl shadow-slate-200/40 hidden fade-in" style="animation-delay: 0.3s;"> <div id="noActiveServices" class="hidden text-center mt-6 pt-6 border-t border-slate-100">
<div class="flex justify-between items-center mb-5"> <div class="w-16 h-16 bg-slate-100 text-slate-400 rounded-full flex items-center justify-center mx-auto mb-4">
<p class="text-[10px] font-black text-indigo-500 uppercase tracking-widest">Técnico Asignado</p> <i data-lucide="check-circle" class="w-8 h-8"></i>
<span class="relative flex h-3 w-3">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-emerald-500"></span>
</span>
</div>
<div class="flex items-center gap-5 mb-6">
<div class="w-16 h-16 bg-gradient-to-br from-indigo-50 to-blue-50 border border-blue-100 rounded-full flex items-center justify-center shadow-inner text-blue-600 shrink-0">
<i data-lucide="user" class="w-8 h-8"></i>
</div> </div>
<div> <h3 class="text-lg font-black text-slate-800 tracking-tight">Todo al día</h3>
<h3 id="workerName" class="font-black text-slate-800 text-xl uppercase leading-tight tracking-tight">Juan Pérez</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>
<p class="text-xs text-slate-500 font-medium mt-1">Operario Especialista</p>
</div>
</div>
<div class="grid grid-cols-2 gap-4"> <div class="bg-blue-50 border border-blue-100 p-5 rounded-2xl text-left">
<a href="#" id="btnCall" class="bg-white border-2 border-slate-100 text-slate-700 font-black py-3.5 rounded-2xl flex justify-center items-center gap-2 shadow-sm hover:border-blue-200 hover:text-blue-600 transition-all active:scale-95 text-xs uppercase tracking-wider"> <h4 class="text-xs font-black text-blue-800 uppercase tracking-widest mb-1">¿Nueva Avería?</h4>
<i data-lucide="phone" class="w-4 h-4"></i> Llamar <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>
</a> <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]">
<a href="#" id="btnWa" class="bg-[#25D366] text-white font-black py-3.5 rounded-2xl flex justify-center items-center gap-2 shadow-lg shadow-[#25D366]/30 hover:bg-[#128C7E] transition-all active:scale-95 text-xs uppercase tracking-wider"> Solicitar Servicio Particular
<i data-lucide="message-circle" class="w-4 h-4 text-white fill-white"></i> WhatsApp </button>
</a>
</div>
</div>
<div class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] shadow-xl shadow-slate-200/40 border border-white space-y-6 fade-in" style="animation-delay: 0.4s;">
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-2 border-b border-slate-100 pb-3">Información del Aviso</p>
<div class="flex items-start gap-4">
<div class="bg-slate-50 border border-slate-100 w-10 h-10 flex items-center justify-center rounded-2xl text-slate-400 shrink-0"><i data-lucide="map-pin" class="w-5 h-5"></i></div>
<div>
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-0.5">Dirección</p>
<p id="serviceAddress" class="font-bold text-slate-700 text-sm uppercase leading-snug"></p>
</div>
</div>
<div class="flex items-start gap-4">
<div class="bg-slate-50 border border-slate-100 w-10 h-10 flex items-center justify-center rounded-2xl text-slate-400 shrink-0"><i data-lucide="phone" class="w-5 h-5"></i></div>
<div>
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-0.5">Teléfono de Contacto</p>
<p id="servicePhone" class="font-black text-slate-700 text-sm"></p>
</div>
</div>
<div class="flex items-start gap-4">
<div class="bg-amber-50 border border-amber-100 w-10 h-10 flex items-center justify-center rounded-2xl text-amber-500 shrink-0"><i data-lucide="alert-triangle" class="w-5 h-5"></i></div>
<div class="w-full">
<p class="text-[10px] font-black text-amber-600 uppercase tracking-widest mb-1.5">Avería Reportada</p>
<div class="bg-slate-50 border border-slate-100 p-4 rounded-2xl">
<p id="serviceDesc" class="font-medium text-slate-600 text-sm leading-relaxed"></p>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="text-center mt-4 mb-2"> <div id="historyContainerWrapper" class="hidden">
<p class="text-[10px] font-bold text-slate-400">Tecnología de gestión por IntegraRepara</p> <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">
</div>
</div> </div>
</div> </div>
</main> </main>
@@ -140,31 +100,28 @@
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
? 'http://localhost:3000' ? 'http://localhost:3000'
: 'https://integrarepara-api.integrarepara.es'; : 'https://integrarepara-api.integrarepara.es';
</script>
<script> let urlToken = "";
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
lucide.createIcons(); lucide.createIcons();
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token'); urlToken = urlParams.get('token');
const serviceId = urlParams.get('service'); const targetServiceId = urlParams.get('service'); // Puede venir o no
if (!token || !serviceId) { if (!urlToken) {
showError(); showError();
return; return;
} }
try { try {
const res = await fetch(`${API_URL}/public/portal/${token}`); const res = await fetch(`${API_URL}/public/portal/${urlToken}`);
const data = await res.json(); const data = await res.json();
if (!data.ok) throw new Error("Token inválido"); if (!data.ok) throw new Error("Token inválido");
const service = data.services.find(s => String(s.id) === String(serviceId)); renderPortal(data.client, data.company, data.services, targetServiceId);
if (!service) throw new Error("Servicio no encontrado");
renderPortal(data.client, data.company, service);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@@ -181,77 +138,16 @@
}, 300); }, 300);
} }
function renderPortal(client, company, service) { // Helper para sumar 1 hora y crear la franja
// Textos básicos y Logo rediseñado function addOneHour(timeStr) {
document.getElementById('companyName').innerText = company.name || "Empresa Reparadora"; if(!timeStr) return "";
if (company.logo) { let [h, m] = timeStr.split(':').map(Number);
document.getElementById('companyLogo').src = company.logo; let totalMins = h * 60 + m + 60;
document.getElementById('companyLogoContainer').classList.remove('hidden'); let newH = Math.floor(totalMins / 60);
} let newM = totalMins % 60;
return `${String(newH).padStart(2,'0')}:${String(newM).padStart(2,'0')}`;
document.getElementById('clientName').innerText = client.name.split(' ')[0];
document.getElementById('serviceRef').innerText = "#" + (service.title.replace('Expediente #', '') || service.id);
document.getElementById('serviceAddress').innerText = client.addresses[0] || "Dirección no especificada";
document.getElementById('servicePhone').innerText = client.phone;
document.getElementById('serviceDesc').innerText = service.description || "Avería general reportada.";
// ¿Hay un técnico asignado?
if (service.assigned_worker && service.assigned_worker !== "Pendiente") {
document.getElementById('workerCard').classList.remove('hidden');
document.getElementById('workerName').innerText = service.assigned_worker;
document.getElementById('btnCall').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); };
document.getElementById('btnWa').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); };
}
// ¿Hay cita o está pendiente de agendar? (Rediseño de la tarjeta interior)
const dateContainer = document.getElementById('dateContainer');
if (service.scheduled_date) {
// Nuevo diseño de Cita Confirmada (Gradient Premium)
dateContainer.innerHTML = `
<div class="bg-gradient-to-br from-emerald-400 to-emerald-600 p-5 rounded-[1.5rem] 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 flex-col 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-1">Visita Confirmada</p>
<p class="font-black uppercase text-lg leading-none mb-1.5">${formatDate(service.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> Turno: ${service.scheduled_time || 'A convenir'}</p>
</div>
</div>
`;
} else {
// Nuevo diseño de Pendiente de Cita (Llamada a la acción vibrante)
dateContainer.innerHTML = `
<div class="bg-blue-50/50 border border-blue-100 p-6 rounded-[1.5rem] 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-xs text-slate-500 font-medium mt-2 mb-5">El técnico necesita saber cuándo puede pasar por tu domicilio para la reparación.</p>
<button onclick="startBooking()" class="w-full bg-blue-600 text-white font-black py-4 rounded-2xl shadow-xl shadow-blue-600/30 hover:bg-blue-700 hover:shadow-blue-700/40 transition-all active:scale-95 flex justify-center items-center gap-2 uppercase tracking-widest text-xs">
Agendar Visita Ahora <i data-lucide="arrow-right" class="w-4 h-4"></i>
</button>
</div>
`;
}
lucide.createIcons();
// Quitar loader
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
setTimeout(() => document.getElementById('loader').classList.add('hidden'), 300);
document.getElementById('mainContent').classList.remove('hidden');
} }
// Formateador de fechas simple
function formatDate(dateStr) { function formatDate(dateStr) {
if (!dateStr) return ""; if (!dateStr) return "";
try { try {
@@ -263,11 +159,191 @@
} catch(e) { return dateStr; } } catch(e) { return dateStr; }
} }
function startBooking() { function renderPortal(client, company, allServices, targetServiceId) {
const urlParams = new URLSearchParams(window.location.search); document.getElementById('companyName').innerText = company.name || "Empresa Reparadora";
const token = urlParams.get('token'); if (company.logo) {
const serviceId = urlParams.get('service'); document.getElementById('companyLogo').src = company.logo;
window.location.href = `cita.html?token=${token}&service=${serviceId}`; document.getElementById('companyLogoContainer').classList.remove('hidden');
}
document.getElementById('clientName').innerText = client.name.split(' ')[0];
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.toLowerCase().includes('terminado') ||
srv.status_name.toLowerCase().includes('anulado') ||
srv.status_name.toLowerCase().includes('desasignado');
// --- CONSTRUCCIÓN DEL BLOQUE DE ESTADO DEPENDIENDO DE LA SITUACIÓN ---
let statusHtml = '';
let isPendingClientAction = false;
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 (srv.appointment_status === 'pending') {
// MODO 2: PENDIENTE DE ACEPTACIÓN POR LA OFICINA
statusHtml = `
<div class="bg-amber-50 border border-amber-200 p-5 rounded-2xl text-center shadow-inner">
<div class="w-10 h-10 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto mb-3">
<i data-lucide="clock" class="w-5 h-5 animate-pulse"></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">Tu solicitud de fecha ha sido enviada. El técnico debe confirmarla en breve.</p>
</div>
`;
} else if (srv.status_name === 'Visita Agendada' || srv.status_name === 'Asignado a Técnico') {
// 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-5 rounded-2xl flex items-center gap-4 text-white shadow-lg shadow-emerald-500/30 relative overflow-hidden">
<div class="w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center backdrop-blur-md border border-white/30 shrink-0 relative z-10">
<i data-lucide="calendar-check" class="w-6 h-6 text-white"></i>
</div>
<div class="relative z-10">
<p class="text-[8px] font-black uppercase tracking-widest text-emerald-100 mb-0.5">Visita Confirmada</p>
<p class="font-black uppercase text-base leading-tight mb-1">${formatDate(srv.scheduled_date)}</p>
<p class="text-xs font-bold text-emerald-50 flex items-center gap-1"><i data-lucide="clock" class="w-3 h-3"></i> Llegada aprox: ${srv.scheduled_time} - ${endT}</p>
</div>
</div>
`;
} else if (srv.status_name === 'Técnico de Camino') {
// MODO 5: DE CAMINO (MAPA PLACEHOLDER)
statusHtml = `
<div class="bg-indigo-50 border border-indigo-200 p-5 rounded-2xl relative overflow-hidden shadow-inner">
<div class="flex items-center gap-3 mb-4 relative z-10">
<div class="w-10 h-10 bg-indigo-500 text-white rounded-full flex items-center justify-center shadow-md animate-bounce">
<i data-lucide="truck" class="w-5 h-5"></i>
</div>
<div>
<h4 class="font-black text-indigo-800 uppercase text-sm tracking-tight">¡Técnico en camino!</h4>
<p class="text-[10px] text-indigo-600 font-bold">Llegando en breves momentos a tu domicilio.</p>
</div>
</div>
<div class="w-full h-24 bg-indigo-100 rounded-xl border border-indigo-200 border-dashed flex items-center justify-center text-indigo-300 relative z-10">
<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">Señal GPS Próximamente</p>
</div>
</div>
</div>
`;
} else if (srv.status_name === 'En Reparación') {
// MODO 8: TRABAJANDO
statusHtml = `
<div class="bg-orange-50 border border-orange-200 p-5 rounded-2xl flex items-center gap-4 shadow-inner">
<div class="w-12 h-12 bg-orange-500 text-white rounded-xl flex items-center justify-center shadow-md shrink-0">
<i data-lucide="hammer" class="w-6 h-6"></i>
</div>
<div>
<h4 class="font-black text-orange-800 uppercase text-sm tracking-tight">En Reparación</h4>
<p class="text-[10px] text-orange-600 font-bold">El técnico está trabajando en tu domicilio ahora mismo.</p>
</div>
</div>
`;
} else if (srv.status_name === 'Pausado / Incidencia') {
// MODO 6: INCIDENCIA
statusHtml = `
<div class="bg-red-50 border border-red-200 p-5 rounded-2xl flex items-center gap-4 shadow-inner">
<div class="w-12 h-12 bg-red-500 text-white rounded-xl flex items-center justify-center shadow-md shrink-0">
<i data-lucide="alert-triangle" class="w-6 h-6"></i>
</div>
<div>
<h4 class="font-black text-red-800 uppercase text-sm tracking-tight">Incidencia / Pausado</h4>
<p class="text-[10px] text-red-600 font-bold">El servicio está pausado (ej: esperando pieza). Te avisaremos pronto.</p>
</div>
</div>
`;
} else {
// MODO 4: PENDIENTE DE CITA NORMAL (TU DISEÑO QUE TE GUSTABA)
isPendingClientAction = true;
statusHtml = `
<div class="bg-blue-50/50 border border-blue-100 p-6 rounded-2xl text-center">
<div class="w-12 h-12 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto mb-3 relative">
<span class="absolute inset-0 bg-blue-200 rounded-full animate-ping opacity-50"></span>
<i data-lucide="calendar-clock" class="w-6 h-6 relative z-10"></i>
</div>
<h4 class="font-black text-slate-800 uppercase text-base leading-tight tracking-tight">Pendiente de Cita</h4>
<p class="text-[10px] text-slate-500 font-medium mt-1 mb-4">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-3.5 rounded-xl shadow-lg shadow-blue-600/30 hover:bg-blue-700 transition-all active:scale-95 flex justify-center items-center gap-2 uppercase tracking-widest text-[10px]">
Agendar Visita Ahora <i data-lucide="arrow-right" class="w-3.5 h-3.5"></i>
</button>
</div>
`;
}
// ESTRUCTURA DE LA TARJETA DEL EXPEDIENTE
const cardHtml = `
<div class="bg-white border ${isFinalized ? 'border-slate-100' : 'border-slate-200 shadow-md'} rounded-3xl p-5 mb-4 relative overflow-hidden">
<div class="flex justify-between items-start mb-3">
<div>
<span class="text-[9px] font-black text-slate-400 uppercase tracking-widest">Expediente ${srv.title}</span>
<h3 class="font-black text-slate-800 text-sm mt-0.5 leading-tight">${srv.description}</h3>
</div>
${srv.assigned_worker && srv.assigned_worker !== 'Pendiente' ?
`<div class="bg-slate-50 border border-slate-100 px-2 py-1 rounded-md text-center shrink-0 ml-2">
<p class="text-[8px] uppercase font-black text-slate-400 mb-0.5">Técnico</p>
<p class="text-[10px] font-bold text-blue-600">${srv.assigned_worker.split(' ')[0]}</p>
</div>` : ''
}
</div>
${statusHtml}
</div>
`;
if (isFinalized) {
historyContainer.innerHTML += cardHtml;
hasHistory = true;
} 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');
}
lucide.createIcons();
// Quitar loader
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
setTimeout(() => document.getElementById('loader').classList.add('hidden'), 300);
document.getElementById('mainContent').classList.remove('hidden');
}
function startBooking(serviceId) {
window.location.href = `cita.html?token=${urlToken}&service=${serviceId}`;
}
function requestNewService() {
alert("Módulo de nuevo aviso particular en desarrollo. Próximamente el cliente podrá crear su propia avería desde aquí.");
} }
</script> </script>
</body> </body>