Actualizar calendario.html
This commit is contained in:
323
calendario.html
323
calendario.html
@@ -14,7 +14,6 @@
|
|||||||
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
||||||
.bottom-nav-safe { padding-bottom: env(safe-area-inset-bottom); }
|
.bottom-nav-safe { padding-bottom: env(safe-area-inset-bottom); }
|
||||||
|
|
||||||
/* Estilos para el selector de días */
|
|
||||||
.day-card { transition: all 0.2s; }
|
.day-card { transition: all 0.2s; }
|
||||||
.day-active { background-color: #2563eb; color: white; border-color: #2563eb; transform: scale(1.05); box-shadow: 0 10px 15px -3px rgba(37,99,235,0.4); }
|
.day-active { background-color: #2563eb; color: white; border-color: #2563eb; transform: scale(1.05); box-shadow: 0 10px 15px -3px rgba(37,99,235,0.4); }
|
||||||
.day-inactive { background-color: white; color: #64748b; border-color: #e2e8f0; }
|
.day-inactive { background-color: white; color: #64748b; border-color: #e2e8f0; }
|
||||||
@@ -39,8 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="overflow-x-auto no-scrollbar py-2 -mx-5 px-5 flex gap-3" id="weekStrip">
|
<div class="overflow-x-auto no-scrollbar py-2 -mx-5 px-5 flex gap-3" id="weekStrip"></div>
|
||||||
</div>
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="flex-1 overflow-y-auto no-scrollbar p-5 relative z-10" id="mainArea">
|
<main class="flex-1 overflow-y-auto no-scrollbar p-5 relative z-10" id="mainArea">
|
||||||
@@ -50,8 +48,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="dayTitle" class="font-black text-slate-400 uppercase tracking-widest text-[10px] mb-4 hidden">Servicios para hoy</div>
|
<div id="dayTitle" class="font-black text-slate-400 uppercase tracking-widest text-[10px] mb-4 hidden">Servicios para hoy</div>
|
||||||
<div id="servicesList" class="space-y-4 pb-24 hidden fade-in">
|
<div id="servicesList" class="space-y-4 pb-24 hidden fade-in"></div>
|
||||||
</div>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
||||||
@@ -72,7 +69,6 @@
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="serviceModal" class="fixed inset-0 bg-slate-50 z-[100] hidden flex-col translate-y-full transition-transform duration-300">
|
<div id="serviceModal" class="fixed inset-0 bg-slate-50 z-[100] hidden flex-col translate-y-full transition-transform duration-300">
|
||||||
|
|
||||||
<div class="p-5 border-b border-slate-200 flex justify-between items-center bg-white shrink-0 shadow-sm relative z-20">
|
<div class="p-5 border-b border-slate-200 flex justify-between items-center bg-white shrink-0 shadow-sm relative z-20">
|
||||||
<button onclick="closeModal()" class="bg-slate-50 p-2.5 rounded-xl border border-slate-200 text-slate-600 active:bg-slate-100"><i data-lucide="chevron-down" class="w-6 h-6"></i></button>
|
<button onclick="closeModal()" class="bg-slate-50 p-2.5 rounded-xl border border-slate-200 text-slate-600 active:bg-slate-100"><i data-lucide="chevron-down" class="w-6 h-6"></i></button>
|
||||||
<h3 class="font-black text-sm uppercase tracking-widest text-slate-800" id="modTime">10:00 - 11:00</h3>
|
<h3 class="font-black text-sm uppercase tracking-widest text-slate-800" id="modTime">10:00 - 11:00</h3>
|
||||||
@@ -85,7 +81,6 @@
|
|||||||
<div class="bg-white p-5 rounded-3xl shadow-sm border border-slate-100">
|
<div class="bg-white p-5 rounded-3xl shadow-sm border border-slate-100">
|
||||||
<span id="detRef" class="bg-slate-100 text-slate-500 px-3 py-1 rounded-lg text-[10px] font-black uppercase tracking-widest mb-3 inline-block"></span>
|
<span id="detRef" class="bg-slate-100 text-slate-500 px-3 py-1 rounded-lg text-[10px] font-black uppercase tracking-widest mb-3 inline-block"></span>
|
||||||
<h2 id="detName" class="text-2xl font-black text-slate-800 uppercase leading-tight"></h2>
|
<h2 id="detName" class="text-2xl font-black text-slate-800 uppercase leading-tight"></h2>
|
||||||
|
|
||||||
<div class="mt-4 pt-4 border-t border-slate-100 flex items-start gap-3">
|
<div class="mt-4 pt-4 border-t border-slate-100 flex items-start gap-3">
|
||||||
<i data-lucide="map-pin" class="w-5 h-5 text-slate-400 shrink-0 mt-0.5"></i>
|
<i data-lucide="map-pin" class="w-5 h-5 text-slate-400 shrink-0 mt-0.5"></i>
|
||||||
<p id="detAddress" class="font-bold text-slate-600 text-sm uppercase leading-snug"></p>
|
<p id="detAddress" class="font-bold text-slate-600 text-sm uppercase leading-snug"></p>
|
||||||
@@ -95,11 +90,9 @@
|
|||||||
<div class="bg-gradient-to-br from-slate-800 to-slate-900 p-5 rounded-3xl shadow-lg text-white relative overflow-hidden">
|
<div class="bg-gradient-to-br from-slate-800 to-slate-900 p-5 rounded-3xl shadow-lg text-white relative overflow-hidden">
|
||||||
<i data-lucide="satellite" class="absolute -right-4 -bottom-4 w-32 h-32 text-white/5"></i>
|
<i data-lucide="satellite" class="absolute -right-4 -bottom-4 w-32 h-32 text-white/5"></i>
|
||||||
<p class="text-[10px] font-black text-blue-300 uppercase tracking-widest mb-2 relative z-10">Navegación GPS</p>
|
<p class="text-[10px] font-black text-blue-300 uppercase tracking-widest mb-2 relative z-10">Navegación GPS</p>
|
||||||
|
|
||||||
<div id="gpsLoading" class="flex items-center gap-2 text-sm font-bold relative z-10">
|
<div id="gpsLoading" class="flex items-center gap-2 text-sm font-bold relative z-10">
|
||||||
<i data-lucide="loader-2" class="w-4 h-4 animate-spin text-blue-400"></i> Calculando ruta...
|
<i data-lucide="loader-2" class="w-4 h-4 animate-spin text-blue-400"></i> Calculando ruta...
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="gpsResult" class="hidden relative z-10">
|
<div id="gpsResult" class="hidden relative z-10">
|
||||||
<div class="flex items-end gap-2">
|
<div class="flex items-end gap-2">
|
||||||
<h3 class="text-3xl font-black leading-none" id="gpsMins">--</h3>
|
<h3 class="text-3xl font-black leading-none" id="gpsMins">--</h3>
|
||||||
@@ -122,7 +115,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 gap-3">
|
<div class="grid grid-cols-1 gap-3">
|
||||||
<button onclick="quickUpdate('finalizado')" class="bg-emerald-500 hover:bg-emerald-600 text-white font-black py-4 rounded-2xl flex justify-center items-center gap-2 active:scale-95 transition-all shadow-md shadow-emerald-200">
|
<button onclick="quickUpdate('finalizado')" class="bg-emerald-500 hover:bg-emerald-600 text-white font-black py-4 rounded-2xl flex justify-center items-center gap-2 active:scale-95 transition-all shadow-md shadow-emerald-200">
|
||||||
<i data-lucide="check-circle" class="w-5 h-5"></i>
|
<i data-lucide="check-circle" class="w-5 h-5"></i>
|
||||||
@@ -133,7 +125,6 @@
|
|||||||
<span class="text-[11px] uppercase tracking-widest">Enviar Encuesta</span>
|
<span class="text-[11px] uppercase tracking-widest">Enviar Encuesta</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -149,15 +140,24 @@
|
|||||||
|
|
||||||
let localServices = [];
|
let localServices = [];
|
||||||
let systemStatuses = [];
|
let systemStatuses = [];
|
||||||
|
|
||||||
let currentWeekStart = new Date();
|
let currentWeekStart = new Date();
|
||||||
let selectedDateStr = "";
|
let selectedDateStr = "";
|
||||||
|
|
||||||
|
// Helper seguro para iconos
|
||||||
|
function safeLoadIcons() {
|
||||||
|
try { if (typeof lucide !== 'undefined') lucide.createIcons(); }
|
||||||
|
catch(e) { console.warn("Iconos no cargados aún"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper seguro para fechas
|
||||||
function toISODate(dateObj) {
|
function toISODate(dateObj) {
|
||||||
const y = dateObj.getFullYear();
|
try {
|
||||||
const m = String(dateObj.getMonth() + 1).padStart(2, '0');
|
if (!dateObj || isNaN(dateObj)) return "";
|
||||||
const d = String(dateObj.getDate()).padStart(2, '0');
|
const y = dateObj.getFullYear();
|
||||||
return `${y}-${m}-${d}`;
|
const m = String(dateObj.getMonth() + 1).padStart(2, '0');
|
||||||
|
const d = String(dateObj.getDate()).padStart(2, '0');
|
||||||
|
return `${y}-${m}-${d}`;
|
||||||
|
} catch(e) { return ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMonday(d) {
|
function getMonday(d) {
|
||||||
@@ -172,46 +172,52 @@
|
|||||||
window.location.href = "index.html"; return;
|
window.location.href = "index.html"; return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lucide.createIcons();
|
safeLoadIcons();
|
||||||
|
|
||||||
const today = new Date();
|
try {
|
||||||
currentWeekStart = getMonday(today);
|
const today = new Date();
|
||||||
selectedDateStr = toISODate(today);
|
currentWeekStart = getMonday(today);
|
||||||
|
selectedDateStr = toISODate(today);
|
||||||
buildWeekCalendar();
|
buildWeekCalendar();
|
||||||
loadStatuses();
|
loadStatuses();
|
||||||
refreshData();
|
refreshData();
|
||||||
|
} catch(error) {
|
||||||
|
alert("Error iniciando calendario: " + error.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function buildWeekCalendar() {
|
function buildWeekCalendar() {
|
||||||
const strip = document.getElementById('weekStrip');
|
try {
|
||||||
strip.innerHTML = '';
|
const strip = document.getElementById('weekStrip');
|
||||||
|
strip.innerHTML = '';
|
||||||
const monthName = currentWeekStart.toLocaleDateString('es-ES', { month: 'long', year: 'numeric' });
|
|
||||||
document.getElementById('monthYearDisplay').innerText = monthName;
|
|
||||||
|
|
||||||
for(let i = 0; i < 7; i++) {
|
|
||||||
let d = new Date(currentWeekStart);
|
|
||||||
d.setDate(currentWeekStart.getDate() + i);
|
|
||||||
|
|
||||||
const isoDate = toISODate(d);
|
const monthName = currentWeekStart.toLocaleDateString('es-ES', { month: 'long', year: 'numeric' });
|
||||||
const dayName = d.toLocaleDateString('es-ES', { weekday: 'short' }).replace('.', '');
|
document.getElementById('monthYearDisplay').innerText = monthName;
|
||||||
const dayNum = d.getDate();
|
|
||||||
|
for(let i = 0; i < 7; i++) {
|
||||||
|
let d = new Date(currentWeekStart);
|
||||||
|
d.setDate(currentWeekStart.getDate() + i);
|
||||||
|
|
||||||
|
const isoDate = toISODate(d);
|
||||||
|
const dayName = d.toLocaleDateString('es-ES', { weekday: 'short' }).replace('.', '');
|
||||||
|
const dayNum = d.getDate();
|
||||||
|
|
||||||
const isSelected = isoDate === selectedDateStr;
|
const isSelected = isoDate === selectedDateStr;
|
||||||
const baseClass = isSelected ? 'day-active' : 'day-inactive';
|
const baseClass = isSelected ? 'day-active' : 'day-inactive';
|
||||||
|
|
||||||
strip.innerHTML += `
|
strip.innerHTML += `
|
||||||
<button onclick="selectDate('${isoDate}')" id="btn-date-${isoDate}" class="day-card ${baseClass} border min-w-[4rem] rounded-2xl p-3 flex flex-col items-center justify-center shrink-0">
|
<button onclick="selectDate('${isoDate}')" id="btn-date-${isoDate}" class="day-card ${baseClass} border min-w-[4rem] rounded-2xl p-3 flex flex-col items-center justify-center shrink-0">
|
||||||
<span class="text-[9px] font-black uppercase tracking-widest opacity-80">${dayName}</span>
|
<span class="text-[9px] font-black uppercase tracking-widest opacity-80">${dayName}</span>
|
||||||
<span class="text-xl font-black leading-none mt-1">${dayNum}</span>
|
<span class="text-xl font-black leading-none mt-1">${dayNum}</span>
|
||||||
<div class="mt-2 w-full flex justify-center h-1.5">
|
<div class="mt-2 w-full flex justify-center h-1.5">
|
||||||
<span id="badge-${isoDate}" class="bg-rose-500 w-1.5 h-1.5 rounded-full hidden"></span>
|
<span id="badge-${isoDate}" class="bg-rose-500 w-1.5 h-1.5 rounded-full hidden"></span>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
if(localServices.length > 0) updateBadges();
|
if(localServices.length > 0) updateBadges();
|
||||||
|
safeLoadIcons();
|
||||||
|
} catch(e) { console.error(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeWeek(offsetWeeks) {
|
function changeWeek(offsetWeeks) {
|
||||||
@@ -246,18 +252,17 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
// Ahora SÍ permitimos los SYSTEM_BLOCK y servicios con fecha
|
|
||||||
localServices = data.services.filter(s => {
|
localServices = data.services.filter(s => {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
const hasDate = raw.scheduled_date && raw.scheduled_date.trim() !== "";
|
const dateStr = String(raw.scheduled_date || "").trim();
|
||||||
return hasDate;
|
return dateStr !== "";
|
||||||
});
|
});
|
||||||
|
|
||||||
buildWeekCalendar();
|
buildWeekCalendar();
|
||||||
renderServices();
|
renderServices();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert("Error de conexión");
|
console.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
document.getElementById('loader').classList.add('hidden');
|
document.getElementById('loader').classList.add('hidden');
|
||||||
document.getElementById('dayTitle').classList.remove('hidden');
|
document.getElementById('dayTitle').classList.remove('hidden');
|
||||||
@@ -270,7 +275,7 @@
|
|||||||
|
|
||||||
const counts = {};
|
const counts = {};
|
||||||
localServices.forEach(s => {
|
localServices.forEach(s => {
|
||||||
const date = (s.raw_data.scheduled_date || "").trim();
|
const date = String(s.raw_data.scheduled_date || "").trim();
|
||||||
if(date) counts[date] = (counts[date] || 0) + 1;
|
if(date) counts[date] = (counts[date] || 0) + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -281,75 +286,74 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderServices() {
|
function renderServices() {
|
||||||
const container = document.getElementById('servicesList');
|
try {
|
||||||
const displayDate = selectedDateStr.split('-').reverse().join('/');
|
const container = document.getElementById('servicesList');
|
||||||
document.getElementById('dayTitle').innerText = `Servicios del ${displayDate}`;
|
const displayDate = selectedDateStr.split('-').reverse().join('/');
|
||||||
|
document.getElementById('dayTitle').innerText = `Servicios del ${displayDate}`;
|
||||||
|
|
||||||
const dayServices = localServices.filter(s => {
|
const dayServices = localServices.filter(s => {
|
||||||
const d = (s.raw_data.scheduled_date || "").trim();
|
const d = String(s.raw_data.scheduled_date || "").trim();
|
||||||
return d === selectedDateStr;
|
return d === selectedDateStr;
|
||||||
});
|
});
|
||||||
|
|
||||||
dayServices.sort((a, b) => {
|
// Ordenación segura a prueba de fallos de formato
|
||||||
const timeA = a.raw_data.scheduled_time || "23:59";
|
dayServices.sort((a, b) => {
|
||||||
const timeB = b.raw_data.scheduled_time || "23:59";
|
const timeA = String(a.raw_data.scheduled_time || "23:59");
|
||||||
return timeA.localeCompare(timeB);
|
const timeB = String(b.raw_data.scheduled_time || "23:59");
|
||||||
});
|
return timeA.localeCompare(timeB);
|
||||||
|
});
|
||||||
|
|
||||||
if (dayServices.length === 0) {
|
if (dayServices.length === 0) {
|
||||||
container.innerHTML = `
|
container.innerHTML = `
|
||||||
<div class="text-center py-10 bg-white rounded-3xl border border-slate-100 shadow-sm mt-4">
|
<div class="text-center py-10 bg-white rounded-3xl border border-slate-100 shadow-sm mt-4 fade-in">
|
||||||
<i data-lucide="party-popper" class="w-12 h-12 text-slate-200 mx-auto mb-3"></i>
|
<i data-lucide="party-popper" class="w-12 h-12 text-slate-200 mx-auto mb-3"></i>
|
||||||
<h3 class="font-black text-slate-800">Día Libre</h3>
|
<h3 class="font-black text-slate-800">Día Libre</h3>
|
||||||
<p class="text-xs text-slate-400 font-medium mt-1">No tienes citas agendadas para hoy.</p>
|
<p class="text-xs text-slate-400 font-medium mt-1">No tienes citas agendadas para hoy.</p>
|
||||||
</div>`;
|
</div>`;
|
||||||
lucide.createIcons();
|
safeLoadIcons();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
container.innerHTML = dayServices.map(s => {
|
|
||||||
const raw = s.raw_data || {};
|
|
||||||
const time = raw.scheduled_time || "A convenir";
|
|
||||||
|
|
||||||
// RENDERIZADO ESPECIAL PARA BLOQUEOS
|
|
||||||
if (s.provider === 'SYSTEM_BLOCK') {
|
|
||||||
const desc = raw["Descripción"] || "Operario no disponible";
|
|
||||||
return `
|
|
||||||
<div class="bg-rose-50/80 p-5 rounded-3xl border border-rose-200 shadow-sm flex gap-4">
|
|
||||||
<div class="flex flex-col items-center justify-center border-r border-rose-200 pr-4 shrink-0">
|
|
||||||
<i data-lucide="lock" class="w-4 h-4 text-rose-500 mb-1"></i>
|
|
||||||
<span class="font-black text-rose-800 text-sm">${time}</span>
|
|
||||||
</div>
|
|
||||||
<div class="min-w-0 flex-1 py-1">
|
|
||||||
<h3 class="font-black text-rose-800 text-sm uppercase leading-tight truncate">Bloqueado</h3>
|
|
||||||
<p class="text-[10px] font-bold text-rose-600 mt-1 truncate uppercase">${desc}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RENDERIZADO NORMAL PARA REPARACIONES
|
container.innerHTML = dayServices.map(s => {
|
||||||
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
|
const raw = s.raw_data || {};
|
||||||
const addr = raw["Dirección"] || "Sin dirección";
|
const time = raw.scheduled_time || "A convenir";
|
||||||
const pop = raw["Población"] || "";
|
|
||||||
const isUrgent = s.is_urgent;
|
if (s.provider === 'SYSTEM_BLOCK') {
|
||||||
|
const desc = raw["Descripción"] || "Operario no disponible";
|
||||||
|
return `
|
||||||
|
<div class="bg-rose-50/80 p-5 rounded-3xl border border-rose-200 shadow-sm flex gap-4 fade-in">
|
||||||
|
<div class="flex flex-col items-center justify-center border-r border-rose-200 pr-4 shrink-0">
|
||||||
|
<i data-lucide="lock" class="w-4 h-4 text-rose-500 mb-1"></i>
|
||||||
|
<span class="font-black text-rose-800 text-sm">${time}</span>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1 py-1">
|
||||||
|
<h3 class="font-black text-rose-800 text-sm uppercase leading-tight truncate">Bloqueado</h3>
|
||||||
|
<p class="text-[10px] font-bold text-rose-600 mt-1 truncate uppercase">${desc}</p>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
return `
|
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
|
||||||
<div onclick="openService(${s.id})" class="bg-white p-5 rounded-3xl border border-slate-200 shadow-sm active:scale-95 transition-transform flex gap-4 cursor-pointer">
|
const addr = raw["Dirección"] || "Sin dirección";
|
||||||
<div class="flex flex-col items-center justify-center border-r border-slate-100 pr-4 shrink-0">
|
const pop = raw["Población"] || "";
|
||||||
<i data-lucide="clock" class="w-4 h-4 text-blue-400 mb-1"></i>
|
const isUrgent = s.is_urgent;
|
||||||
<span class="font-black text-slate-800 text-sm">${time}</span>
|
|
||||||
</div>
|
|
||||||
<div class="min-w-0 flex-1">
|
|
||||||
<h3 class="font-black text-slate-800 text-base uppercase leading-tight truncate">${name}</h3>
|
|
||||||
<p class="text-[10px] font-bold text-slate-500 mt-1 truncate uppercase">${addr}, ${pop}</p>
|
|
||||||
${isUrgent ? '<span class="inline-block mt-2 bg-red-100 text-red-700 text-[9px] font-black px-2 py-0.5 rounded uppercase tracking-widest">Urgente</span>' : ''}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}).join('');
|
|
||||||
|
|
||||||
lucide.createIcons();
|
return `
|
||||||
|
<div onclick="openService(${s.id})" class="bg-white p-5 rounded-3xl border border-slate-200 shadow-sm active:scale-95 transition-transform flex gap-4 cursor-pointer fade-in">
|
||||||
|
<div class="flex flex-col items-center justify-center border-r border-slate-100 pr-4 shrink-0">
|
||||||
|
<i data-lucide="clock" class="w-4 h-4 text-blue-400 mb-1"></i>
|
||||||
|
<span class="font-black text-slate-800 text-sm">${time}</span>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<h3 class="font-black text-slate-800 text-base uppercase leading-tight truncate">${name}</h3>
|
||||||
|
<p class="text-[10px] font-bold text-slate-500 mt-1 truncate uppercase">${addr}, ${pop}</p>
|
||||||
|
${isUrgent ? '<span class="inline-block mt-2 bg-red-100 text-red-700 text-[9px] font-black px-2 py-0.5 rounded uppercase tracking-widest">Urgente</span>' : ''}
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
|
safeLoadIcons();
|
||||||
|
} catch(e) { console.error("Render error:", e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -370,12 +374,10 @@
|
|||||||
const fullAddress = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`;
|
const fullAddress = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`;
|
||||||
document.getElementById('detAddress').innerText = fullAddress;
|
document.getElementById('detAddress').innerText = fullAddress;
|
||||||
|
|
||||||
// Mostrar modal
|
|
||||||
const modal = document.getElementById('serviceModal');
|
const modal = document.getElementById('serviceModal');
|
||||||
modal.classList.remove('hidden');
|
modal.classList.remove('hidden');
|
||||||
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
|
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
|
||||||
|
|
||||||
// Iniciar GPS automático
|
|
||||||
calculateDistance(fullAddress);
|
calculateDistance(fullAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,57 +385,86 @@
|
|||||||
const modal = document.getElementById('serviceModal');
|
const modal = document.getElementById('serviceModal');
|
||||||
modal.classList.add('translate-y-full');
|
modal.classList.add('translate-y-full');
|
||||||
setTimeout(() => modal.classList.add('hidden'), 300);
|
setTimeout(() => modal.classList.add('hidden'), 300);
|
||||||
|
|
||||||
// Reset GPS view
|
|
||||||
document.getElementById('gpsLoading').classList.remove('hidden');
|
document.getElementById('gpsLoading').classList.remove('hidden');
|
||||||
document.getElementById('gpsResult').classList.add('hidden');
|
document.getElementById('gpsResult').classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- SISTEMA GPS INTELIGENTE ---
|
|
||||||
async function calculateDistance(destAddress) {
|
async function calculateDistance(destAddress) {
|
||||||
if(!navigator.geolocation) {
|
if(!navigator.geolocation) { showGpsError("GPS no soportado"); return; }
|
||||||
showGpsError("GPS no soportado"); return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Pedir ubicación al móvil
|
|
||||||
navigator.geolocation.getCurrentPosition(async (position) => {
|
navigator.geolocation.getCurrentPosition(async (position) => {
|
||||||
const userLat = position.coords.latitude;
|
const userLat = position.coords.latitude;
|
||||||
const userLon = position.coords.longitude;
|
const userLon = position.coords.longitude;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 2. Traducir la dirección del cliente a coordenadas (API Gratuita OSM)
|
|
||||||
const res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(destAddress + ', España')}`);
|
const res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(destAddress + ', España')}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
const destLat = parseFloat(data[0].lat);
|
const destLat = parseFloat(data[0].lat);
|
||||||
const destLon = parseFloat(data[0].lon);
|
const destLon = parseFloat(data[0].lon);
|
||||||
|
const R = 6371;
|
||||||
// 3. Fórmula Haversine (Distancia en línea recta)
|
|
||||||
const R = 6371; // Radio de la tierra en KM
|
|
||||||
const dLat = (destLat - userLat) * Math.PI / 180;
|
const dLat = (destLat - userLat) * Math.PI / 180;
|
||||||
const dLon = (destLon - userLon) * Math.PI / 180;
|
const dLon = (destLon - userLon) * Math.PI / 180;
|
||||||
const a = Math.sin(dLat/2) * Math.sin(dLat/2) +
|
const a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(userLat * Math.PI / 180) * Math.cos(destLat * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2);
|
||||||
Math.cos(userLat * Math.PI / 180) * Math.cos(destLat * Math.PI / 180) *
|
|
||||||
Math.sin(dLon/2) * Math.sin(dLon/2);
|
|
||||||
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 distanceKm = R * c;
|
const distanceKm = R * c;
|
||||||
|
const mins = Math.round((distanceKm / 35) * 60) + 5;
|
||||||
|
|
||||||
// Estimación de tiempo (Asumiendo 35 km/h media en ciudad)
|
|
||||||
const mins = Math.round((distanceKm / 35) * 60) + 5; // +5 mins de margen de aparcamiento
|
|
||||||
|
|
||||||
// Pintar en pantalla
|
|
||||||
document.getElementById('gpsLoading').classList.add('hidden');
|
document.getElementById('gpsLoading').classList.add('hidden');
|
||||||
document.getElementById('gpsResult').classList.remove('hidden');
|
document.getElementById('gpsResult').classList.remove('hidden');
|
||||||
document.getElementById('gpsKm').innerText = distanceKm.toFixed(1);
|
document.getElementById('gpsKm').innerText = distanceKm.toFixed(1);
|
||||||
document.getElementById('gpsMins').innerText = mins;
|
document.getElementById('gpsMins').innerText = mins;
|
||||||
|
} else { showGpsError("Dirección no encontrada en el mapa"); }
|
||||||
|
} catch(e) { showGpsError("Error de red GPS"); }
|
||||||
|
}, (err) => { showGpsError("Permiso de GPS denegado"); }, { enableHighAccuracy: true });
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
function showGpsError(msg) {
|
||||||
showGpsError("Dirección no encontrada en el mapa");
|
document.getElementById('gpsLoading').innerHTML = `<i data-lucide="alert-circle" class="w-4 h-4 text-rose-400"></i> ${msg}`;
|
||||||
}
|
safeLoadIcons();
|
||||||
} catch(e) {
|
}
|
||||||
showGpsError("Error de red GPS");
|
|
||||||
}
|
async function quickUpdate(action) {
|
||||||
}, (err) => {
|
if(!currentServiceId) return;
|
||||||
showGpsError("Permiso de GPS denegado");
|
let searchWord = ""; let confirmMsg = "";
|
||||||
}, { enableHigh
|
if(action === 'camino') { searchWord = "camino"; confirmMsg = "¿Avisar al cliente que estás de camino?"; }
|
||||||
|
if(action === 'trabajando') { searchWord = "trabaja"; confirmMsg = "¿Confirmar llegada e iniciar reparación?"; }
|
||||||
|
if(action === 'finalizado') { searchWord = "finaliza"; confirmMsg = "¿Cerrar expediente definitivamente?"; }
|
||||||
|
if(action === 'encuesta') { searchWord = "finaliza"; confirmMsg = "¿Finalizar y mandar encuesta al cliente?"; }
|
||||||
|
|
||||||
|
if(!confirm(confirmMsg)) return;
|
||||||
|
|
||||||
|
const st = systemStatuses.find(s => s.name.toLowerCase().includes(searchWord));
|
||||||
|
if(!st) return alert("Error: El estado no existe en la base de datos.");
|
||||||
|
|
||||||
|
try {
|
||||||
|
showToast("Procesando...");
|
||||||
|
const res = await fetch(`${API_URL}/providers/scraped/${currentServiceId}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
|
body: JSON.stringify({ status_operativo: st.id })
|
||||||
|
});
|
||||||
|
|
||||||
|
if(res.ok) {
|
||||||
|
showToast("Estado actualizado correctamente");
|
||||||
|
closeModal();
|
||||||
|
refreshData();
|
||||||
|
} else { alert("Error guardando estado"); }
|
||||||
|
} catch (e) { alert("Error de conexión al servidor"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function showToast(msg) {
|
||||||
|
const t = document.getElementById('toast');
|
||||||
|
document.getElementById('toastMsg').innerText = msg;
|
||||||
|
t.classList.remove('opacity-0', 'pointer-events-none', '-translate-y-10');
|
||||||
|
t.classList.add('translate-y-0');
|
||||||
|
setTimeout(() => {
|
||||||
|
t.classList.add('opacity-0', 'pointer-events-none', '-translate-y-10');
|
||||||
|
t.classList.remove('translate-y-0');
|
||||||
|
}, 2500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function logout() { localStorage.clear(); window.location.href = "index.html"; }
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user