Actualizar index.html
This commit is contained in:
31
index.html
31
index.html
@@ -435,13 +435,14 @@
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
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-bold text-indigo-600 leading-tight">El técnico está conduciendo hacia tu domicilio.</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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,19 +470,20 @@
|
|||||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||||
const km = R * c;
|
const km = R * c;
|
||||||
|
|
||||||
const totalMins = Math.round((km/35)*60) + 5;
|
// Tiempo basado directamente en la distancia (sin restar)
|
||||||
|
const totalMins = Math.round((km/35)*60) + 5;
|
||||||
|
let remainingMins = totalMins;
|
||||||
|
|
||||||
// Simplemente asignamos el tiempo basado en la distancia real
|
// Porcentaje visual para la barra animada
|
||||||
let remainingMins = totalMins;
|
let progressPercent = 5;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calculamos el tiempo transcurrido solo para animar la barra de progreso
|
|
||||||
const startedAt = new Date(data.location.updated_at).getTime();
|
|
||||||
const diffMins = Math.floor((new Date().getTime() - startedAt) / 60000);
|
|
||||||
|
|
||||||
let progressPercent = (diffMins / totalMins) * 100;
|
|
||||||
if (remainingMins < 1) remainingMins = 1;
|
|
||||||
|
|
||||||
let progressPercent = (diffMins / totalMins) * 100;
|
|
||||||
if (progressPercent > 95) progressPercent = 95;
|
if (progressPercent > 95) progressPercent = 95;
|
||||||
if (progressPercent < 5) progressPercent = 5;
|
if (progressPercent < 5) progressPercent = 5;
|
||||||
|
|
||||||
@@ -501,10 +503,11 @@ let progressPercent = (diffMins / totalMins) * 100;
|
|||||||
`;
|
`;
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
} else {
|
} else {
|
||||||
container.innerHTML = `<p class="text-xs font-bold text-indigo-600 leading-tight">El técnico está conduciendo hacia tu domicilio.</p>`;
|
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) {
|
} catch(e) {
|
||||||
container.innerHTML = `<p class="text-xs font-bold text-indigo-600 leading-tight">El técnico está conduciendo hacia tu domicilio.</p>`;
|
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>
|
||||||
|
|||||||
Reference in New Issue
Block a user