Actualizar index.html
This commit is contained in:
32
index.html
32
index.html
@@ -470,20 +470,26 @@
|
||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||
const km = R * c;
|
||||
|
||||
// Tiempo basado directamente en la distancia (sin restar)
|
||||
// Tiempo total estimado basado en la distancia
|
||||
const totalMins = Math.round((km/35)*60) + 5;
|
||||
let remainingMins = totalMins;
|
||||
|
||||
// Porcentaje visual para la barra animada
|
||||
let progressPercent = 5;
|
||||
// Extraemos la hora exacta en la que el técnico pulsó el botón
|
||||
let startedAt = new Date().getTime();
|
||||
if (data.location.updated_at) {
|
||||
const startedAt = new Date(data.location.updated_at).getTime();
|
||||
if (!isNaN(startedAt)) {
|
||||
const diffMins = Math.floor((new Date().getTime() - startedAt) / 60000);
|
||||
progressPercent = (diffMins / totalMins) * 100;
|
||||
}
|
||||
const parsed = new Date(data.location.updated_at).getTime();
|
||||
if (!isNaN(parsed)) startedAt = parsed;
|
||||
}
|
||||
|
||||
// CREAMOS UNA FUNCIÓN INTERNA PARA ACTUALIZAR EN TIEMPO REAL
|
||||
function renderETA() {
|
||||
const now = new Date().getTime();
|
||||
const diffMins = Math.floor((now - startedAt) / 60000);
|
||||
|
||||
// Restamos el tiempo que ya ha pasado conduciendo
|
||||
let remainingMins = totalMins - diffMins;
|
||||
if (remainingMins < 1) remainingMins = 1; // Nunca bajará de 1 minuto
|
||||
|
||||
let progressPercent = (diffMins / totalMins) * 100;
|
||||
if (progressPercent > 95) progressPercent = 95;
|
||||
if (progressPercent < 5) progressPercent = 5;
|
||||
|
||||
@@ -502,6 +508,14 @@
|
||||
</div>
|
||||
`;
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
// 1. Lo pintamos inmediatamente al cargar
|
||||
renderETA();
|
||||
|
||||
// 2. Lo actualizamos automáticamente cada 60 segundos (Magia en tiempo real)
|
||||
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>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user