Actualizar index.html
This commit is contained in:
522
index.html
522
index.html
@@ -8,15 +8,29 @@
|
|||||||
<script src="https://unpkg.com/lucide@latest"></script>
|
<script src="https://unpkg.com/lucide@latest"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body { background-color: #f4f7f9; background-image: radial-gradient(#e2e8f0 1px, transparent 1px); background-size: 24px 24px; }
|
/* Fondo Marsalva Style */
|
||||||
|
body {
|
||||||
|
background-color: #f8fafc;
|
||||||
|
background-image: radial-gradient(#cbd5e1 1.5px, transparent 1.5px);
|
||||||
|
background-size: 24px 24px;
|
||||||
|
}
|
||||||
.fade-in { animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
|
.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); } }
|
@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; }
|
.blob { position: absolute; filter: blur(60px); z-index: -1; opacity: 0.4; }
|
||||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||||
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
||||||
|
|
||||||
|
/* Contenedor principal estilo formulario */
|
||||||
|
.main-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 2.5rem;
|
||||||
|
box-shadow: 0 25px 50px -12px rgba(203, 213, 225, 0.6);
|
||||||
|
border: 1px solid #f1f5f9;
|
||||||
|
}
|
||||||
</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 py-10 px-4">
|
||||||
|
|
||||||
<div class="blob bg-blue-300 w-64 h-64 rounded-full top-[-50px] left-[-50px]"></div>
|
<div class="blob bg-blue-300 w-64 h-64 rounded-full top-[-50px] left-[-50px]"></div>
|
||||||
<div class="blob bg-emerald-200 w-64 h-64 rounded-full top-[20%] right-[-100px]"></div>
|
<div class="blob bg-emerald-200 w-64 h-64 rounded-full top-[20%] right-[-100px]"></div>
|
||||||
@@ -29,101 +43,88 @@
|
|||||||
<p class="text-sm font-black tracking-widest uppercase text-slate-500 animate-pulse">Conectando...</p>
|
<p class="text-sm font-black tracking-widest uppercase text-slate-500 animate-pulse">Conectando...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="errorScreen" class="hidden w-full max-w-md mx-auto p-6 flex-col items-center justify-center min-h-screen text-center fade-in z-10 relative">
|
<div id="errorScreen" class="hidden w-full max-w-md mx-auto p-6 flex-col items-center justify-center min-h-[60vh] 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">
|
<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>
|
<i data-lucide="shield-alert" class="w-12 h-12"></i>
|
||||||
</div>
|
</div>
|
||||||
<h2 class="text-3xl font-black text-slate-800 mb-3 tracking-tight">Enlace no válido</h2>
|
<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>
|
<p class="text-slate-500 font-medium leading-relaxed">Este enlace ha caducado o es incorrecto.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<main id="mainContent" class="hidden w-full max-w-md mx-auto min-h-screen flex flex-col relative pb-10 z-10">
|
<main id="mainContent" class="hidden w-full max-w-md mx-auto flex flex-col relative z-10">
|
||||||
<div class="pt-10 pb-6 px-6 flex flex-col items-center text-center fade-in" style="animation-delay: 0.1s;">
|
|
||||||
<div id="companyLogoContainer" class="hidden relative mb-5">
|
<div class="flex flex-col items-center text-center mb-10 fade-in" style="animation-delay: 0.1s;">
|
||||||
<div class="absolute inset-0 bg-blue-500 rounded-3xl blur-xl opacity-20"></div>
|
<div id="companyLogoContainer" class="hidden relative mb-6">
|
||||||
<div class="relative w-28 h-28 bg-white rounded-3xl shadow-lg border border-slate-100 flex items-center justify-center overflow-hidden p-3">
|
<div class="absolute inset-0 bg-blue-500 rounded-[2rem] blur-xl opacity-20"></div>
|
||||||
|
<div class="relative w-28 h-28 bg-white rounded-[2rem] shadow-2xl shadow-slate-200 flex items-center justify-center overflow-hidden p-4 border border-white">
|
||||||
<img id="companyLogo" src="" class="w-full h-full object-contain">
|
<img id="companyLogo" src="" class="w-full h-full object-contain">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-[10px] font-black text-blue-600 uppercase tracking-widest mb-1.5 opacity-80">Portal del Cliente</p>
|
<p class="text-[10px] font-black text-blue-600 uppercase tracking-[0.2em] mb-1 opacity-80">Portal del Cliente</p>
|
||||||
<h1 id="companyName" class="text-2xl font-black tracking-tight text-slate-900 uppercase leading-none">Empresa</h1>
|
<h1 id="companyName" class="text-2xl font-black tracking-tight text-slate-800 uppercase leading-none">Empresa</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="px-5 flex-1 flex flex-col gap-6 fade-in" style="animation-delay: 0.2s;">
|
<div class="px-2 mb-8 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-5xl font-black text-slate-800 tracking-tight leading-none italic">Hola, <br><span id="clientName" class="text-blue-600 not-italic">Cliente</span></h2>
|
||||||
<div id="activeServicesContainer" class="space-y-6 mt-2"></div>
|
</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">
|
<div class="main-card p-6 md:p-8 space-y-6 fade-in" style="animation-delay: 0.3s;">
|
||||||
|
<div id="activeServicesContainer" class="space-y-6"></div>
|
||||||
|
|
||||||
|
<div id="noActiveServices" class="hidden text-center py-10">
|
||||||
|
<div class="w-16 h-16 bg-slate-50 text-slate-300 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||||
<i data-lucide="check-circle" class="w-8 h-8"></i>
|
<i data-lucide="check-circle" class="w-8 h-8"></i>
|
||||||
</div>
|
</div>
|
||||||
<h3 class="text-lg font-black text-slate-800 tracking-tight">Todo al día</h3>
|
<h3 class="text-lg font-black text-slate-400 tracking-tight uppercase">Todo al día</h3>
|
||||||
</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</h3>
|
<div id="historyContainerWrapper" class="hidden pt-6 border-t border-slate-50">
|
||||||
|
<h3 class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-4 ml-2">Historial reciente</h3>
|
||||||
<div id="historyServicesContainer" class="space-y-4"></div>
|
<div id="historyServicesContainer" class="space-y-4"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
const API_URL = "https://integrarepara-api.integrarepara.es";
|
||||||
? 'http://localhost:3000'
|
|
||||||
: 'https://integrarepara-api.integrarepara.es';
|
|
||||||
|
|
||||||
let urlToken = "";
|
let urlToken = "";
|
||||||
let etasToInit = [];
|
let etasToInit = [];
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
lucide.createIcons();
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
urlToken = urlParams.get('token');
|
urlToken = urlParams.get('token');
|
||||||
const serviceParam = urlParams.get('service');
|
const serviceParam = urlParams.get('service');
|
||||||
|
|
||||||
if (!urlToken) {
|
if (!urlToken) { showError(); return; }
|
||||||
showError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let fetchUrl = `${API_URL}/public/portal/${urlToken}`;
|
let fetchUrl = `${API_URL}/public/portal/${urlToken}`;
|
||||||
if (serviceParam) {
|
if (serviceParam) fetchUrl += `?service=${serviceParam}`;
|
||||||
fetchUrl += `?service=${serviceParam}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch(fetchUrl);
|
const res = await fetch(fetchUrl);
|
||||||
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");
|
||||||
|
renderPortal(data.client, data.company, data.services || []);
|
||||||
const servicesList = data.services || [];
|
} catch (e) { showError(); }
|
||||||
renderPortal(data.client, data.company, servicesList);
|
lucide.createIcons();
|
||||||
} catch (e) {
|
|
||||||
console.error("Error cargando portal:", e);
|
|
||||||
showError();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function showError() {
|
function showError() {
|
||||||
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
|
document.getElementById('loader').classList.add('hidden');
|
||||||
setTimeout(() => {
|
document.getElementById('errorScreen').classList.remove('hidden');
|
||||||
document.getElementById('loader').classList.add('hidden');
|
document.getElementById('errorScreen').classList.add('flex');
|
||||||
document.getElementById('errorScreen').classList.remove('hidden');
|
|
||||||
document.getElementById('errorScreen').classList.add('flex');
|
|
||||||
}, 300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function summarizeDescription(rawText) {
|
function summarizeDescription(rawText) {
|
||||||
if (!rawText) return "Avería reportada.";
|
if (!rawText) return "Asistencia técnica solicitada.";
|
||||||
let text = rawText.replace(/\n/g, ' ');
|
let text = rawText.replace(/\n/g, ' ');
|
||||||
const regexCorte = /(\(|\bM\.O\b|\bMATERIAL\b|\bASEGURADO\b|\bTELEFONO\b|\bURGENTE\b)/i;
|
const regexCorte = /(\(|\bM\.O\b|\bMATERIAL\b|\bASEGURADO\b|\bTELEFONO\b|\bURGENTE\b)/i;
|
||||||
let cutPos = text.search(regexCorte);
|
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.trim();
|
||||||
text = text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
|
text = text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
|
||||||
let words = text.split(/\s+/);
|
return text.length > 100 ? text.substring(0, 100) + "..." : text;
|
||||||
if (words.length > 10) return words.slice(0, 10).join(" ") + "...";
|
|
||||||
if (text.length < 5) return "Reparación general solicitada.";
|
|
||||||
return text.endsWith('.') ? text : text + ".";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addOneHour(timeStr) {
|
function addOneHour(timeStr) {
|
||||||
@@ -135,406 +136,137 @@
|
|||||||
|
|
||||||
function formatDate(dateStr) {
|
function formatDate(dateStr) {
|
||||||
if (!dateStr) return "";
|
if (!dateStr) return "";
|
||||||
try {
|
const d = new Date(dateStr);
|
||||||
const parts = dateStr.split('-');
|
return d.toLocaleDateString('es-ES', { weekday: 'long', day: 'numeric', month: 'long' });
|
||||||
if(parts.length !== 3) return dateStr;
|
|
||||||
const d = new Date(parts[0], parts[1]-1, parts[2]);
|
|
||||||
return d.toLocaleDateString('es-ES', { weekday: 'long', day: 'numeric', month: 'long' });
|
|
||||||
} catch(e) { return dateStr; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderPortal(client, company, allServices) {
|
function renderPortal(client, company, allServices) {
|
||||||
document.getElementById('companyName').innerText = company.name || "Empresa";
|
document.getElementById('companyName').innerText = company.name || "Empresa";
|
||||||
if (company.logo) {
|
if (company.logo) {
|
||||||
document.getElementById('companyLogo').src = company.logo;
|
document.getElementById('companyLogo').src = company.logo;
|
||||||
document.getElementById('companyLogoContainer').classList.remove('hidden');
|
document.getElementById('companyLogoContainer').classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
let cName = "Cliente";
|
let cName = client?.name?.split(' ')[0] || "Cliente";
|
||||||
if (client && client.name) {
|
|
||||||
cName = client.name.split(' ')[0];
|
|
||||||
}
|
|
||||||
document.getElementById('clientName').innerText = cName.toUpperCase();
|
document.getElementById('clientName').innerText = cName.toUpperCase();
|
||||||
|
|
||||||
const activeContainer = document.getElementById('activeServicesContainer');
|
const activeContainer = document.getElementById('activeServicesContainer');
|
||||||
const historyContainerWrapper = document.getElementById('historyContainerWrapper');
|
|
||||||
const historyContainer = document.getElementById('historyServicesContainer');
|
const historyContainer = document.getElementById('historyServicesContainer');
|
||||||
|
|
||||||
activeContainer.innerHTML = '';
|
let hasActive = false; let hasHistory = false;
|
||||||
historyContainer.innerHTML = '';
|
|
||||||
|
|
||||||
let hasActive = false;
|
|
||||||
let hasHistory = false;
|
|
||||||
|
|
||||||
allServices.forEach(srv => {
|
allServices.forEach(srv => {
|
||||||
let isFinalized = srv.is_final === true;
|
let isFinalized = srv.is_final === true;
|
||||||
let raw = srv.raw_data || {};
|
let raw = srv.raw_data || {};
|
||||||
let descLimpia = summarizeDescription(srv.description);
|
let descLimpia = summarizeDescription(srv.description);
|
||||||
|
let stNameLower = (srv.status_name || "").toLowerCase();
|
||||||
let stNameLower = "";
|
let isUrgent = srv.is_urgent === true || (raw['Urgente'] && ["sí","si","true"].includes(raw['Urgente'].toLowerCase()));
|
||||||
if (srv.status_name) {
|
let hasWorker = srv.assigned_worker && !["Pendiente", "Sin asignar"].includes(srv.assigned_worker);
|
||||||
stNameLower = srv.status_name.toLowerCase();
|
let hasDate = srv.scheduled_date && srv.scheduled_time;
|
||||||
}
|
|
||||||
|
|
||||||
let hasDate = false;
|
|
||||||
if (srv.scheduled_date && srv.scheduled_time) {
|
|
||||||
hasDate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let hasWorker = false;
|
|
||||||
if (srv.assigned_worker && srv.assigned_worker !== 'Pendiente' && srv.assigned_worker !== 'Sin asignar') {
|
|
||||||
hasWorker = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 🚨 DETECTAMOS SI ES URGENCIA 🚨
|
|
||||||
let isUrgent = srv.is_urgent === true || (raw['Urgente'] && (raw['Urgente'].toLowerCase() === 'sí' || raw['Urgente'].toLowerCase() === 'si' || raw['Urgente'].toLowerCase() === 'true'));
|
|
||||||
|
|
||||||
let statusHtml = '';
|
let statusHtml = '';
|
||||||
|
|
||||||
|
// LÓGICA DE ESTADOS (CAMINO, TRABAJANDO, CITA, URGENCIA...)
|
||||||
if (isFinalized || stNameLower.includes('finalizado') || stNameLower.includes('anulado')) {
|
if (isFinalized || stNameLower.includes('finalizado') || stNameLower.includes('anulado')) {
|
||||||
statusHtml = `<div class="bg-slate-50 border border-slate-200 p-4 rounded-2xl flex items-center justify-between opacity-70 grayscale">
|
statusHtml = `<div class="bg-slate-50 border border-slate-100 p-4 rounded-2xl flex items-center justify-between opacity-60 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 || 'Cerrado'}</span>
|
<span class="text-[10px] font-black text-slate-400 uppercase flex items-center gap-1.5"><i data-lucide="archive" class="w-3 h-3"></i> Finalizado</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
else if (stNameLower.includes('camino')) {
|
else if (stNameLower.includes('camino')) {
|
||||||
let fullAddr = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`;
|
etasToInit.push({ id: srv.id, address: `${raw["Dirección"] || ""}, ${raw["Población"] || ""}` });
|
||||||
etasToInit.push({ id: srv.id, address: fullAddr });
|
statusHtml = `<div class="bg-indigo-50 border border-indigo-100 p-5 rounded-[2rem]">
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
statusHtml = `<div class="bg-indigo-50 border border-indigo-200 p-6 rounded-3xl relative overflow-hidden shadow-inner">
|
<div class="w-12 h-12 bg-indigo-600 text-white rounded-2xl flex items-center justify-center shadow-lg animate-pulse shrink-0"><i data-lucide="truck" class="w-6 h-6"></i></div>
|
||||||
<div class="flex items-center gap-5 relative z-10">
|
<div class="flex-1"><h4 class="font-black text-indigo-900 uppercase text-sm tracking-tight">¡En camino!</h4>
|
||||||
<div class="w-14 h-14 bg-indigo-500 text-white rounded-2xl flex items-center justify-center shadow-lg shadow-indigo-500/30 animate-pulse shrink-0">
|
<div id="eta-container-${srv.id}"><p class="text-[10px] font-bold text-indigo-400 animate-pulse">Calculando llegada...</p></div></div>
|
||||||
<i data-lucide="truck" class="w-7 h-7"></i>
|
</div>
|
||||||
</div>
|
</div>`;
|
||||||
<div class="flex-1 min-w-0">
|
|
||||||
<h4 class="font-black text-indigo-900 uppercase text-lg leading-none mb-1.5 tracking-tight">¡En camino!</h4>
|
|
||||||
<div id="eta-container-${srv.id}">
|
|
||||||
<p class="text-[10px] font-bold text-indigo-500 flex items-center gap-1.5"><i data-lucide="loader-2" class="w-3 h-3 animate-spin"></i> Calculando ruta...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
}
|
||||||
else if (stNameLower.includes('trabajando') || stNameLower.includes('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>
|
|
||||||
<h4 class="font-black text-orange-800 uppercase text-base tracking-tight">Trabajando</h4>
|
|
||||||
<p class="text-[10px] text-orange-600 font-bold mt-1.5 leading-tight">El técnico está realizando la reparación en tu domicilio.</p>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
else if (stNameLower.includes('incidencia')) {
|
|
||||||
statusHtml = `<div class="bg-rose-50 border border-rose-200 p-6 rounded-3xl flex items-center gap-5 shadow-inner">
|
|
||||||
<div class="w-14 h-14 bg-rose-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0 animate-pulse">
|
|
||||||
<i data-lucide="alert-triangle" class="w-7 h-7"></i>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h4 class="font-black text-rose-800 uppercase text-base tracking-tight">En Incidencia</h4>
|
|
||||||
<p class="text-[10px] text-rose-600 font-bold mt-1.5 leading-tight">Ha surgido un contratiempo técnico. Estamos gestionándolo para solucionarlo lo antes posible.</p>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
else if (raw.appointment_status === 'pending' && raw.requested_date) {
|
|
||||||
statusHtml = `<div class="bg-purple-50 border border-purple-200 p-6 rounded-3xl relative overflow-hidden shadow-inner">
|
|
||||||
<div class="flex items-center gap-4 relative z-10">
|
|
||||||
<div class="w-14 h-14 bg-purple-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0">
|
|
||||||
<i data-lucide="hourglass" class="w-7 h-7 animate-pulse"></i>
|
|
||||||
</div>
|
|
||||||
<div class="flex-1 min-w-0">
|
|
||||||
<p class="text-[9px] font-black uppercase tracking-widest text-purple-500 mb-0.5">En Revisión</p>
|
|
||||||
<h4 class="font-black text-purple-900 uppercase text-lg leading-none mb-1.5 tracking-tight">Cita Solicitada</h4>
|
|
||||||
<p class="text-[10px] font-bold text-purple-700 leading-tight">Has solicitado cita para el <b>${formatDate(raw.requested_date)} a las ${raw.requested_time}</b>. El técnico está revisando su ruta para confirmarla.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
else if (hasDate && !stNameLower.includes('anulado') && !stNameLower.includes('desasignado')) {
|
|
||||||
let endT = addOneHour(srv.scheduled_time);
|
|
||||||
let now = new Date();
|
|
||||||
let schedParts = srv.scheduled_date.split('-');
|
|
||||||
let endTimeParts = endT.split(':');
|
|
||||||
|
|
||||||
let isLate = false;
|
|
||||||
if (schedParts.length === 3 && endTimeParts.length === 2) {
|
|
||||||
let limitDate = new Date(schedParts[0], schedParts[1] - 1, schedParts[2], endTimeParts[0], endTimeParts[1], 0);
|
|
||||||
if (now > limitDate) isLate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLate) {
|
|
||||||
statusHtml = `<div class="bg-amber-50 border border-amber-200 p-6 rounded-3xl relative overflow-hidden shadow-inner">
|
|
||||||
<div class="flex items-center gap-4 relative z-10">
|
|
||||||
<div class="w-14 h-14 bg-amber-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0">
|
|
||||||
<i data-lucide="clock-4" class="w-7 h-7"></i>
|
|
||||||
</div>
|
|
||||||
<div class="flex-1 min-w-0">
|
|
||||||
<p class="text-[9px] font-black uppercase tracking-widest text-amber-500 mb-0.5">Disculpe el retraso</p>
|
|
||||||
<h4 class="font-black text-amber-900 uppercase text-lg leading-none mb-1.5 tracking-tight">Técnico Demorado</h4>
|
|
||||||
<p class="text-[10px] font-bold text-amber-700 leading-tight">La cita estaba prevista entre las <b>${srv.scheduled_time} y las ${endT}</b>. El técnico llegará lo antes posible.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mt-4 pt-4 border-t border-amber-200/60 relative z-10">
|
|
||||||
<a href="cita.html?token=${urlToken}&service=${srv.id}" class="w-full bg-white border border-amber-200 text-amber-700 hover:bg-amber-100 font-black py-3 rounded-xl flex items-center justify-center gap-2 transition-colors text-[10px] uppercase tracking-widest shadow-sm">
|
|
||||||
<i data-lucide="calendar-clock" class="w-4 h-4"></i> Prefiero Modificar la Cita
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
} else {
|
|
||||||
statusHtml = `<div class="bg-gradient-to-br from-emerald-400 to-emerald-600 p-6 rounded-3xl text-white shadow-lg shadow-emerald-500/30 relative overflow-hidden">
|
|
||||||
<div class="flex items-center gap-5 mb-4">
|
|
||||||
<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 flex-1">
|
|
||||||
<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> ${srv.scheduled_time} - ${endT}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="cita.html?token=${urlToken}&service=${srv.id}" class="w-full bg-white/20 hover:bg-white/30 text-white border border-white/30 backdrop-blur-md font-black py-3 rounded-xl flex items-center justify-center gap-2 transition-colors text-[10px] uppercase tracking-widest relative z-10">
|
|
||||||
<i data-lucide="calendar-clock" class="w-4 h-4"></i> Modificar Cita
|
|
||||||
</a>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 🚨 NUEVO BLOQUE: SI ES URGENCIA, MOSTRAMOS ESTO EN VEZ DE "ELEGIR CITA"
|
|
||||||
else if (isUrgent) {
|
else if (isUrgent) {
|
||||||
statusHtml = `<div class="bg-red-50 border border-red-200 p-6 rounded-3xl relative overflow-hidden shadow-inner">
|
statusHtml = `<div class="bg-red-50 border border-red-100 p-6 rounded-[2rem] relative overflow-hidden shadow-inner">
|
||||||
<div class="flex items-center gap-4 relative z-10">
|
<div class="flex items-center gap-4 relative z-10">
|
||||||
<div class="w-14 h-14 bg-red-600 text-white rounded-2xl flex items-center justify-center shadow-lg shadow-red-500/40 shrink-0 animate-pulse">
|
<div class="w-14 h-14 bg-red-600 text-white rounded-2xl flex items-center justify-center shadow-lg shadow-red-200 shrink-0 animate-pulse"><i data-lucide="flame" class="w-7 h-7"></i></div>
|
||||||
<i data-lucide="flame" class="w-7 h-7"></i>
|
<div class="flex-1">
|
||||||
</div>
|
<p class="text-[9px] font-black uppercase tracking-widest text-red-500 mb-0.5">Atención Inmediata</p>
|
||||||
<div class="flex-1 min-w-0">
|
<h4 class="font-black text-red-900 uppercase text-lg leading-none mb-1 tracking-tight">Aviso Urgente</h4>
|
||||||
<p class="text-[9px] font-black uppercase tracking-widest text-red-500 mb-0.5">Prioridad Máxima</p>
|
<p class="text-[10px] font-bold text-red-700 leading-tight">${hasWorker ? 'Técnico asignado. Acudirá de inmediato.' : 'Localizando técnico de guardia...'}</p>
|
||||||
<h4 class="font-black text-red-900 uppercase text-lg leading-none mb-1.5 tracking-tight">Aviso Urgente</h4>
|
|
||||||
<p class="text-[10px] font-bold text-red-700 leading-tight">
|
|
||||||
${hasWorker ? 'Técnico de urgencia asignado. Acudirá a tu domicilio lo antes posible.' : 'Estamos localizando al técnico de urgencia más cercano para que acuda de inmediato.'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
// Si NO es urgente, entonces sí mostramos el botón de Elegir cita
|
else if (hasDate) {
|
||||||
else if (stNameLower.includes('esperando') || stNameLower.includes('asignado') || (hasWorker && !hasDate)) {
|
let endT = addOneHour(srv.scheduled_time);
|
||||||
statusHtml = `<div class="bg-blue-50 border border-blue-200 p-6 rounded-3xl relative overflow-hidden shadow-inner">
|
statusHtml = `<div class="bg-emerald-50 border border-emerald-100 p-6 rounded-[2rem] shadow-sm">
|
||||||
<div class="flex items-center gap-4 relative z-10">
|
<div class="flex items-center gap-4 mb-4">
|
||||||
<div class="w-14 h-14 bg-blue-500 text-white rounded-2xl flex items-center justify-center shadow-md shrink-0">
|
<div class="w-12 h-12 bg-emerald-500 text-white rounded-2xl flex items-center justify-center shrink-0"><i data-lucide="calendar-check" class="w-6 h-6"></i></div>
|
||||||
<i data-lucide="calendar-plus" class="w-7 h-7"></i>
|
<div class="flex-1"><p class="text-[9px] font-black uppercase text-emerald-600 mb-0.5">Visita Agendada</p>
|
||||||
</div>
|
<p class="font-black text-emerald-900 uppercase text-base">${formatDate(srv.scheduled_date)}</p>
|
||||||
<div class="flex-1 min-w-0">
|
<p class="text-xs font-bold text-emerald-700">${srv.scheduled_time} - ${endT}</p></div>
|
||||||
<p class="text-[9px] font-black uppercase tracking-widest text-blue-500 mb-0.5">Acción Requerida</p>
|
</div>
|
||||||
<h4 class="font-black text-blue-900 uppercase text-lg leading-none mb-1.5 tracking-tight">Elige tu cita</h4>
|
<a href="cita.html?token=${urlToken}&service=${srv.id}" class="w-full bg-white/60 hover:bg-emerald-100 text-emerald-700 border border-emerald-200 font-black py-3 rounded-xl flex items-center justify-center gap-2 transition-all text-[10px] uppercase tracking-widest">Modificar Cita</a>
|
||||||
<p class="text-[10px] font-bold text-blue-700 leading-tight">Tu técnico ya está asignado. Por favor, selecciona cuándo quieres que vayamos a tu domicilio.</p>
|
</div>`;
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mt-4 pt-4 border-t border-blue-200/60 relative z-10">
|
|
||||||
<a href="cita.html?token=${urlToken}&service=${srv.id}" class="w-full bg-blue-600 text-white hover:bg-blue-700 font-black py-3 rounded-xl flex items-center justify-center gap-2 transition-colors text-[10px] uppercase tracking-widest shadow-md">
|
|
||||||
<i data-lucide="calendar" class="w-4 h-4"></i> Agendar Cita Ahora
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
}
|
||||||
else if (stNameLower.includes('desasignado')) {
|
else if (hasWorker) {
|
||||||
statusHtml = `<div class="bg-slate-100 border border-slate-200 p-6 rounded-3xl flex items-center gap-4 shadow-inner">
|
statusHtml = `<div class="bg-blue-50 border border-blue-100 p-6 rounded-[2rem]">
|
||||||
<div class="w-12 h-12 bg-slate-300 text-slate-600 rounded-2xl flex items-center justify-center shrink-0">
|
<div class="flex items-center gap-4 mb-4">
|
||||||
<i data-lucide="user-x" class="w-6 h-6"></i>
|
<div class="w-12 h-12 bg-blue-600 text-white rounded-2xl flex items-center justify-center shrink-0"><i data-lucide="calendar-plus" class="w-6 h-6"></i></div>
|
||||||
</div>
|
<div class="flex-1"><p class="text-[9px] font-black text-blue-500 uppercase mb-0.5">Acción Requerida</p>
|
||||||
<div>
|
<h4 class="font-black text-blue-900 uppercase text-base leading-tight">Elige tu cita</h4></div>
|
||||||
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-1">Reorganizando</p>
|
</div>
|
||||||
<h4 class="font-black text-slate-700 uppercase text-sm tracking-tight">Desasignado</h4>
|
<a href="cita.html?token=${urlToken}&service=${srv.id}" class="w-full bg-blue-600 text-white font-black py-4 rounded-2xl flex items-center justify-center gap-2 text-[10px] uppercase tracking-widest shadow-lg shadow-blue-100">Agendar Ahora</a>
|
||||||
<p class="text-[10px] text-slate-500 font-bold mt-1 leading-tight">Buscando un nuevo técnico para tu zona.</p>
|
</div>`;
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
statusHtml = `<div class="bg-slate-100 border border-slate-200 p-6 rounded-3xl flex items-center gap-4 shadow-inner">
|
statusHtml = `<div class="bg-slate-50 border border-slate-100 p-5 rounded-[2rem] flex items-center gap-4">
|
||||||
<div class="w-12 h-12 bg-slate-200 text-slate-500 rounded-2xl flex items-center justify-center shrink-0">
|
<div class="w-10 h-10 bg-slate-200 text-slate-500 rounded-xl flex items-center justify-center shrink-0"><i data-lucide="clock" class="w-5 h-5 animate-pulse"></i></div>
|
||||||
<i data-lucide="search" class="w-6 h-6 animate-pulse"></i>
|
<div><h4 class="font-black text-slate-700 uppercase text-xs">Pendiente de Técnico</h4>
|
||||||
</div>
|
<p class="text-[10px] text-slate-400 font-bold">Asignando profesional en tu zona...</p></div>
|
||||||
<div>
|
|
||||||
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-1">Estado actual</p>
|
|
||||||
<h4 class="font-black text-slate-700 uppercase text-sm tracking-tight">${srv.status_name || 'Pendiente de Asignar'}</h4>
|
|
||||||
<p class="text-[10px] text-slate-500 font-bold mt-1 leading-tight">Buscando al técnico adecuado para tu avería...</p>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let contactHtml = '';
|
|
||||||
if (hasWorker && !isFinalized) {
|
|
||||||
let workerPhone = "34000000000";
|
|
||||||
if (srv.worker_phone) {
|
|
||||||
workerPhone = srv.worker_phone.replace('+', '');
|
|
||||||
}
|
|
||||||
contactHtml = `<div class="flex gap-2 mt-5">
|
|
||||||
<a href="tel:+${workerPhone}" class="flex-1 bg-blue-50 hover:bg-blue-100 border border-blue-200 text-blue-600 font-black py-3 rounded-xl flex items-center justify-center gap-1.5 active:scale-95 transition-transform shadow-sm text-[10px] uppercase tracking-widest">
|
|
||||||
<i data-lucide="phone" class="w-4 h-4"></i> Llamar Técnico
|
|
||||||
</a>
|
|
||||||
<a href="https://wa.me/${workerPhone}" target="_blank" class="flex-1 bg-emerald-50 hover:bg-emerald-100 border border-emerald-200 text-emerald-600 font-black py-3 rounded-xl flex items-center justify-center gap-1.5 active:scale-95 transition-transform shadow-sm text-[10px] uppercase tracking-widest">
|
|
||||||
<i data-lucide="message-circle" class="w-4 h-4"></i> WhatsApp
|
|
||||||
</a>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cNameClient = raw["Nombre Cliente"] || raw["CLIENTE"] || cName;
|
|
||||||
let cAddr = raw["Dirección"] || raw["DOMICILIO"] || "Dirección no especificada";
|
|
||||||
let cCP = raw["Código Postal"] || "";
|
|
||||||
let cPop = raw["Población"] || raw["POBLACION-PROVINCIA"] || "";
|
|
||||||
let cComp = raw["Compañía"] || raw["COMPAÑIA"] || "Particular";
|
|
||||||
|
|
||||||
let clientDataHtml = `<div class="bg-slate-50/50 rounded-2xl p-4 mt-5 border border-slate-100 text-left">
|
|
||||||
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-3 border-b border-slate-100 pb-2">Información del Siniestro</p>
|
|
||||||
<div class="space-y-3">
|
|
||||||
<div class="flex items-start gap-2.5">
|
|
||||||
<i data-lucide="user" class="w-4 h-4 text-slate-400 mt-0.5"></i>
|
|
||||||
<p class="text-xs font-bold text-slate-700 leading-tight">${cNameClient}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-start gap-2.5">
|
|
||||||
<i data-lucide="map-pin" class="w-4 h-4 text-slate-400 mt-0.5"></i>
|
|
||||||
<p class="text-xs font-bold text-slate-700 leading-tight">
|
|
||||||
${cAddr}<br>
|
|
||||||
<span class="text-[10px] text-slate-500 font-medium">${cCP} ${cPop}</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-start gap-2.5">
|
|
||||||
<i data-lucide="building" class="w-4 h-4 text-slate-400 mt-0.5"></i>
|
|
||||||
<p class="text-xs font-bold text-slate-700 leading-tight">${cComp}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
let workerNameBox = '';
|
|
||||||
if (hasWorker) {
|
|
||||||
let wNameShort = srv.assigned_worker.split(' ')[0];
|
|
||||||
workerNameBox = `<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>
|
|
||||||
<p class="text-[10px] font-bold text-blue-600">${wNameShort}</p>
|
|
||||||
</div>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let srvTitle = srv.title || "Aviso";
|
let contactHtml = (hasWorker && !isFinalized) ? `<div class="flex gap-2 mt-4">
|
||||||
|
<a href="tel:+${srv.worker_phone}" class="flex-1 bg-white border border-slate-100 text-slate-600 font-black py-3 rounded-xl flex items-center justify-center gap-1.5 text-[9px] uppercase tracking-widest shadow-sm"><i data-lucide="phone" class="w-3.5 h-3.5"></i> Llamar</a>
|
||||||
|
<a href="https://wa.me/${srv.worker_phone}" target="_blank" class="flex-1 bg-emerald-50 text-emerald-600 border border-emerald-100 font-black py-3 rounded-xl flex items-center justify-center gap-1.5 text-[9px] uppercase tracking-widest shadow-sm"><i data-lucide="message-circle" class="w-3.5 h-3.5"></i> WhatsApp</a>
|
||||||
|
</div>` : '';
|
||||||
|
|
||||||
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 text-left">
|
let cardHtml = `<div class="fade-in">
|
||||||
<div class="flex justify-between items-start mb-5">
|
<div class="flex justify-between items-center mb-3 px-2">
|
||||||
<span class="text-[10px] font-black text-slate-400 uppercase tracking-widest">${srvTitle}</span>
|
<span class="text-[9px] font-black text-slate-400 uppercase tracking-widest">${srv.title || 'Aviso'} #${srv.service_ref || '---'}</span>
|
||||||
${workerNameBox}
|
${hasWorker ? `<span class="text-[9px] font-black text-blue-500 bg-blue-50 px-2 py-1 rounded-lg">TÉCNICO: ${srv.assigned_worker.split(' ')[0].toUpperCase()}</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-5">${statusHtml}</div>
|
${statusHtml}
|
||||||
${contactHtml}
|
${contactHtml}
|
||||||
${clientDataHtml}
|
<div class="mt-4 px-2">
|
||||||
<div class="pt-5 mt-5 border-t border-slate-100">
|
<p class="text-[9px] font-black text-slate-300 uppercase tracking-widest mb-1">Motivo de la visita</p>
|
||||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5">Motivo de la Visita</p>
|
<p class="text-sm font-bold text-slate-600 leading-snug">${descLimpia}</p>
|
||||||
<h3 class="font-black text-slate-800 text-sm leading-relaxed">${descLimpia}</h3>
|
</div>
|
||||||
</div>
|
</div>`;
|
||||||
</div>`;
|
|
||||||
|
|
||||||
if (isFinalized) {
|
if (isFinalized) { historyContainer.innerHTML += cardHtml; hasHistory = true; }
|
||||||
historyContainer.innerHTML += cardHtml;
|
else { activeContainer.innerHTML += cardHtml; hasActive = true; }
|
||||||
hasHistory = true;
|
|
||||||
} else {
|
|
||||||
activeContainer.innerHTML += cardHtml;
|
|
||||||
hasActive = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hasActive) document.getElementById('noActiveServices').classList.remove('hidden');
|
if (!hasActive) document.getElementById('noActiveServices').classList.remove('hidden');
|
||||||
else document.getElementById('noActiveServices').classList.add('hidden');
|
|
||||||
|
|
||||||
if (hasHistory) document.getElementById('historyContainerWrapper').classList.remove('hidden');
|
if (hasHistory) document.getElementById('historyContainerWrapper').classList.remove('hidden');
|
||||||
else document.getElementById('historyContainerWrapper').classList.add('hidden');
|
|
||||||
|
|
||||||
lucide.createIcons();
|
document.getElementById('loader').classList.add('opacity-0');
|
||||||
|
|
||||||
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.getElementById('loader').classList.add('hidden');
|
document.getElementById('loader').classList.add('hidden');
|
||||||
document.getElementById('mainContent').classList.remove('hidden');
|
document.getElementById('mainContent').classList.remove('hidden');
|
||||||
|
|
||||||
etasToInit.forEach(item => calculateClientETA(item.id, item.address));
|
etasToInit.forEach(item => calculateClientETA(item.id, item.address));
|
||||||
|
lucide.createIcons();
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function calculateClientETA(serviceId, destAddress) {
|
async function calculateClientETA(serviceId, destAddress) {
|
||||||
const container = document.getElementById(`eta-container-${serviceId}`);
|
const container = document.getElementById(`eta-container-${serviceId}`);
|
||||||
if (!container) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/public/portal/${urlToken}/location/${serviceId}`);
|
const res = await fetch(`${API_URL}/public/portal/${urlToken}/location/${serviceId}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
if (data.ok && data.location) {
|
||||||
if (!data.ok || !data.location) {
|
container.innerHTML = `<p class="text-xs font-black text-indigo-600">El técnico llegará pronto.</p>`;
|
||||||
container.innerHTML = `<p class="text-xs font-bold text-indigo-600 leading-tight">El técnico está en camino hacia tu domicilio.</p>`;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} catch(e) { }
|
||||||
const wLat = parseFloat(data.location.lat);
|
|
||||||
const wLon = parseFloat(data.location.lng);
|
|
||||||
|
|
||||||
let geoRes = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(destAddress + ', España')}`);
|
|
||||||
let geoData = await geoRes.json();
|
|
||||||
|
|
||||||
if (!geoData || geoData.length === 0) {
|
|
||||||
const parts = destAddress.split(',');
|
|
||||||
const fallbackDest = parts.length > 1 ? parts[parts.length - 1].trim() : destAddress;
|
|
||||||
geoRes = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(fallbackDest + ', España')}`);
|
|
||||||
geoData = await geoRes.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (geoData && geoData.length > 0) {
|
|
||||||
const cLat = parseFloat(geoData[0].lat);
|
|
||||||
const cLon = parseFloat(geoData[0].lon);
|
|
||||||
|
|
||||||
const R = 6371;
|
|
||||||
const dLat = (cLat - wLat) * Math.PI / 180;
|
|
||||||
const dLon = (cLon - wLon) * Math.PI / 180;
|
|
||||||
const a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(wLat * Math.PI / 180) * Math.cos(cLat * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2);
|
|
||||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
||||||
const km = R * c;
|
|
||||||
|
|
||||||
const totalMins = Math.round((km/35)*60) + 5;
|
|
||||||
|
|
||||||
let startedAt = new Date().getTime();
|
|
||||||
if (data.location.updated_at) {
|
|
||||||
const parsed = new Date(data.location.updated_at).getTime();
|
|
||||||
if (!isNaN(parsed)) startedAt = parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderETA() {
|
|
||||||
const now = new Date().getTime();
|
|
||||||
const diffMins = Math.floor((now - startedAt) / 60000);
|
|
||||||
|
|
||||||
let remainingMins = totalMins - diffMins;
|
|
||||||
if (remainingMins < 1) remainingMins = 1;
|
|
||||||
|
|
||||||
let progressPercent = (diffMins / totalMins) * 100;
|
|
||||||
if (progressPercent > 95) progressPercent = 95;
|
|
||||||
if (progressPercent < 5) progressPercent = 5;
|
|
||||||
|
|
||||||
container.innerHTML = `
|
|
||||||
<p class="text-[10px] font-black text-indigo-500 uppercase tracking-widest mb-1.5 flex items-center gap-1.5">
|
|
||||||
<i data-lucide="clock" class="w-3.5 h-3.5"></i> Llegada en aprox. <span class="text-indigo-700 text-sm ml-0.5">${remainingMins} min</span>
|
|
||||||
</p>
|
|
||||||
<div class="w-full bg-indigo-100 rounded-full h-2.5 overflow-hidden shadow-inner">
|
|
||||||
<div class="bg-indigo-500 h-full rounded-full transition-all duration-1000 relative" style="width: ${progressPercent}%">
|
|
||||||
<div class="absolute right-0 top-0 bottom-0 w-4 bg-white/40 animate-pulse"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between items-center mt-1 px-1">
|
|
||||||
<p class="text-[8px] font-black uppercase text-indigo-300">Saliendo</p>
|
|
||||||
<p class="text-[8px] font-black uppercase text-indigo-400">A ${km.toFixed(1)} km</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
lucide.createIcons();
|
|
||||||
}
|
|
||||||
|
|
||||||
renderETA();
|
|
||||||
setInterval(renderETA, 60000);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
container.innerHTML = `<p class="text-xs font-bold text-indigo-600 leading-tight">El técnico está en camino hacia tu domicilio.</p>`;
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
console.error("Error de GPS: ", e);
|
|
||||||
if (container) container.innerHTML = `<p class="text-xs font-bold text-indigo-600 leading-tight">El técnico está de camino.</p>`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user