Actualizar asignados.html
This commit is contained in:
310
asignados.html
310
asignados.html
@@ -9,7 +9,7 @@
|
|||||||
<style>
|
<style>
|
||||||
/* VARIABLES CORPORATIVAS DINÁMICAS */
|
/* VARIABLES CORPORATIVAS DINÁMICAS */
|
||||||
:root {
|
:root {
|
||||||
--primary: #f59e0b; /* En asignados.html predomina el ambar por defecto */
|
--primary: #f59e0b;
|
||||||
--secondary: #2563eb;
|
--secondary: #2563eb;
|
||||||
--app-bg: #f4f7f9;
|
--app-bg: #f4f7f9;
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,17 @@
|
|||||||
.text-primary-dynamic { color: var(--primary) !important; }
|
.text-primary-dynamic { color: var(--primary) !important; }
|
||||||
.bg-primary-dynamic { background-color: var(--primary) !important; }
|
.bg-primary-dynamic { background-color: var(--primary) !important; }
|
||||||
.border-primary-dynamic { border-color: var(--primary) !important; }
|
.border-primary-dynamic { border-color: var(--primary) !important; }
|
||||||
|
|
||||||
|
/* Carrusel de fechas */
|
||||||
|
.day-chip { transition: all 0.2s; border: 2px solid transparent; }
|
||||||
|
.day-chip.active { background-color: var(--primary) !important; color: white !important; border-color: var(--primary) !important; transform: scale(1.05); shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
|
||||||
|
.day-chip.inactive { background-color: #f8fafc; color: #64748b; border-color: #e2e8f0; }
|
||||||
|
|
||||||
|
/* Chips de Horas */
|
||||||
|
.time-chip { transition: all 0.2s; }
|
||||||
|
.time-chip.active { background-color: var(--primary) !important; color: white !important; font-weight: 900; box-shadow: 0 4px 10px rgba(0,0,0,0.15); border-color: var(--primary) !important; }
|
||||||
|
.time-chip.inactive { background-color: white; color: #475569; border-color: #cbd5e1; }
|
||||||
|
.time-chip:disabled { background-color: #f1f5f9; color: #cbd5e1; border-color: #e2e8f0; text-decoration: line-through; cursor: not-allowed; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="text-slate-800 font-sans antialiased h-screen flex flex-col overflow-hidden relative">
|
<body class="text-slate-800 font-sans antialiased h-screen flex flex-col overflow-hidden relative">
|
||||||
@@ -67,9 +78,9 @@
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="actionModal" class="fixed inset-0 bg-slate-900/60 z-[100] hidden flex-col justify-end transition-opacity duration-300 opacity-0">
|
<div id="actionModal" class="fixed inset-0 bg-slate-900/60 z-[100] hidden flex-col justify-end transition-opacity duration-300 opacity-0">
|
||||||
<div id="modalContent" class="bg-white rounded-t-[2rem] p-6 pb-12 transform translate-y-full transition-transform duration-300 shadow-2xl">
|
<div id="modalContent" class="bg-white rounded-t-[2rem] p-6 pb-12 transform translate-y-full transition-transform duration-300 shadow-2xl max-h-[90vh] flex flex-col">
|
||||||
|
|
||||||
<div class="flex justify-between items-center mb-6">
|
<div class="flex justify-between items-center mb-6 shrink-0">
|
||||||
<div>
|
<div>
|
||||||
<span id="detRef" class="text-[10px] font-black text-slate-400 uppercase tracking-widest"></span>
|
<span id="detRef" class="text-[10px] font-black text-slate-400 uppercase tracking-widest"></span>
|
||||||
<h3 class="font-black text-xl text-slate-800 uppercase leading-none" id="detName"></h3>
|
<h3 class="font-black text-xl text-slate-800 uppercase leading-none" id="detName"></h3>
|
||||||
@@ -77,6 +88,7 @@
|
|||||||
<button onclick="closeModal()" class="w-8 h-8 bg-slate-100 rounded-full flex items-center justify-center text-slate-500 hover:text-red-500"><i data-lucide="x" class="w-4 h-4"></i></button>
|
<button onclick="closeModal()" class="w-8 h-8 bg-slate-100 rounded-full flex items-center justify-center text-slate-500 hover:text-red-500"><i data-lucide="x" class="w-4 h-4"></i></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-y-auto no-scrollbar flex-1 pb-4">
|
||||||
<div class="space-y-1 mb-6 bg-slate-50 p-4 rounded-2xl border border-slate-100">
|
<div class="space-y-1 mb-6 bg-slate-50 p-4 rounded-2xl border border-slate-100">
|
||||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1"><i data-lucide="map-pin" class="w-3 h-3"></i> Dirección</p>
|
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1"><i data-lucide="map-pin" class="w-3 h-3"></i> Dirección</p>
|
||||||
<p id="detAddress" class="font-bold text-slate-700 text-sm uppercase"></p>
|
<p id="detAddress" class="font-bold text-slate-700 text-sm uppercase"></p>
|
||||||
@@ -86,46 +98,63 @@
|
|||||||
<input type="hidden" id="detPhoneRaw">
|
<input type="hidden" id="detPhoneRaw">
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3 mb-6">
|
<div class="grid grid-cols-2 gap-3 mb-6">
|
||||||
<button onclick="callClient()" class="bg-blue-50 border border-blue-100 text-blue-600 font-black py-4 rounded-2xl flex flex-col items-center gap-2 active:scale-95 transition-transform shadow-sm">
|
<button onclick="callClient()" class="bg-blue-50 border border-blue-100 text-blue-600 font-black py-3 rounded-2xl flex items-center justify-center gap-2 active:scale-95 transition-transform shadow-sm">
|
||||||
<i data-lucide="phone" class="w-6 h-6"></i>
|
<i data-lucide="phone" class="w-5 h-5"></i>
|
||||||
<span class="text-[10px] uppercase tracking-widest">Llamar</span>
|
<span class="text-[10px] uppercase tracking-widest">Llamar</span>
|
||||||
</button>
|
</button>
|
||||||
<button onclick="openWhatsApp()" class="bg-emerald-50 border border-emerald-100 text-emerald-600 font-black py-4 rounded-2xl flex flex-col items-center gap-2 active:scale-95 transition-transform shadow-sm">
|
<button onclick="openWhatsApp()" class="bg-emerald-50 border border-emerald-100 text-emerald-600 font-black py-3 rounded-2xl flex items-center justify-center gap-2 active:scale-95 transition-transform shadow-sm">
|
||||||
<i data-lucide="message-circle" class="w-6 h-6"></i>
|
<i data-lucide="message-circle" class="w-5 h-5"></i>
|
||||||
<span class="text-[10px] uppercase tracking-widest">WhatsApp</span>
|
<span class="text-[10px] uppercase tracking-widest">WhatsApp</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="border-slate-100 mb-6">
|
<hr class="border-slate-100 mb-6">
|
||||||
|
|
||||||
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-3 flex items-center gap-1.5"><i data-lucide="calendar-clock" class="w-4 h-4"></i> Establecer Cita</p>
|
<div class="bg-white border border-slate-200 rounded-[1.5rem] p-5 shadow-sm space-y-5">
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3 mb-3">
|
<div>
|
||||||
<input type="date" id="dateInput" class="w-full bg-white border border-slate-200 p-4 rounded-2xl text-sm font-bold text-slate-700 shadow-inner outline-none focus:ring-2 focus:ring-amber-500 transition-all">
|
<div class="flex justify-between items-center mb-2">
|
||||||
<input type="time" id="timeInput" class="w-full bg-white border border-slate-200 p-4 rounded-2xl text-sm font-bold text-slate-700 shadow-inner outline-none focus:ring-2 focus:ring-amber-500 transition-all">
|
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest flex items-center gap-1.5"><i data-lucide="clock" class="w-4 h-4"></i> Duración Estimada</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="relative">
|
||||||
<div class="mb-6 relative">
|
<select id="durationInput" onchange="renderTimeSlots()" class="w-full bg-slate-50 border border-slate-200 p-4 rounded-xl text-sm font-black text-slate-700 shadow-inner outline-none focus:ring-2 focus:ring-amber-500 transition-all appearance-none pr-10 cursor-pointer">
|
||||||
<select id="durationInput" class="w-full bg-white border border-slate-200 p-4 rounded-2xl text-sm font-bold text-slate-700 shadow-inner outline-none focus:ring-2 focus:ring-amber-500 transition-all appearance-none pr-10 cursor-pointer">
|
<option value="15">15 Minutos (Muy rápido)</option>
|
||||||
<option value="15">15 minutos</option>
|
<option value="30">30 Minutos</option>
|
||||||
<option value="30">30 minutos</option>
|
<option value="45">45 Minutos</option>
|
||||||
<option value="45">45 minutos</option>
|
<option value="60" selected>1 Hora (Estándar)</option>
|
||||||
<option value="60" selected>1 hora</option>
|
<option value="90">1 Hora y Media</option>
|
||||||
<option value="75">1 hora 15 min</option>
|
<option value="120">2 Horas</option>
|
||||||
<option value="90">1 hora 30 min</option>
|
<option value="180">3 Horas</option>
|
||||||
<option value="105">1 hora 45 min</option>
|
<option value="240">4 Horas (Media jornada)</option>
|
||||||
<option value="120">2 horas</option>
|
|
||||||
<option value="150">2 horas 30 min</option>
|
|
||||||
<option value="180">3 horas</option>
|
|
||||||
<option value="210">3 horas 30 min</option>
|
|
||||||
<option value="240">4 horas (Máx)</option>
|
|
||||||
</select>
|
</select>
|
||||||
<i data-lucide="clock" class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"></i>
|
<i data-lucide="chevron-down" class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"></i>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button onclick="saveAppointment()" id="btnSaveAppt" class="w-full bg-primary-dynamic text-white font-black py-4 rounded-2xl shadow-lg active:scale-95 transition-transform flex items-center justify-center gap-2 uppercase tracking-widest text-xs">
|
<div>
|
||||||
<i data-lucide="check-circle" class="w-5 h-5"></i> Confirmar Cita
|
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-2 flex items-center gap-1.5"><i data-lucide="calendar" class="w-4 h-4"></i> Seleccionar Día</p>
|
||||||
|
<div id="dayCarousel" class="flex overflow-x-auto gap-2 pb-2 no-scrollbar">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-2 flex items-center gap-1.5"><i data-lucide="watch" class="w-4 h-4"></i> Huecos Disponibles</p>
|
||||||
|
<div id="timeGrid" class="grid grid-cols-4 gap-2">
|
||||||
|
</div>
|
||||||
|
<p id="noSlotsMsg" class="hidden text-xs text-rose-500 font-bold bg-rose-50 p-3 rounded-xl border border-rose-100 text-center mt-2">
|
||||||
|
No hay huecos libres para esta duración.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pt-4 shrink-0 bg-white border-t border-slate-100">
|
||||||
|
<button onclick="saveAppointment()" id="btnSaveAppt" disabled class="w-full bg-slate-300 text-white font-black py-4 rounded-2xl shadow-sm transition-all flex items-center justify-center gap-2 uppercase tracking-widest text-xs cursor-not-allowed">
|
||||||
|
<i data-lucide="calendar-check" class="w-5 h-5"></i> Confirmar Cita
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -140,8 +169,14 @@
|
|||||||
? 'http://localhost:3000'
|
? 'http://localhost:3000'
|
||||||
: 'https://integrarepara-api.integrarepara.es';
|
: 'https://integrarepara-api.integrarepara.es';
|
||||||
|
|
||||||
let localServices = [];
|
let localServices = []; // Solo los "Sin Cita"
|
||||||
|
let globalAllServices = []; // TODOS los servicios para calcular solapamientos
|
||||||
let systemStatuses = [];
|
let systemStatuses = [];
|
||||||
|
let bizHours = { m_start: '09:00', m_end: '14:00', a_start: '16:00', a_end: '19:00' };
|
||||||
|
|
||||||
|
// Variables del Agendador Inteligente
|
||||||
|
let pickerSelectedDate = "";
|
||||||
|
let pickerSelectedTime = "";
|
||||||
|
|
||||||
// --- SISTEMA DE TEMA DINÁMICO ---
|
// --- SISTEMA DE TEMA DINÁMICO ---
|
||||||
async function applyTheme() {
|
async function applyTheme() {
|
||||||
@@ -151,24 +186,30 @@
|
|||||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if(data.ok && data.config && data.config.portal_settings && data.config.portal_settings.app_settings) {
|
|
||||||
theme = data.config.portal_settings.app_settings;
|
if(data.ok && data.config && data.config.portal_settings) {
|
||||||
|
// Extraemos horario comercial
|
||||||
|
const ps = data.config.portal_settings;
|
||||||
|
if(ps.m_start) bizHours = { m_start: ps.m_start, m_end: ps.m_end, a_start: ps.a_start, a_end: ps.a_end };
|
||||||
|
|
||||||
|
// Extraemos colores
|
||||||
|
if(ps.app_settings) {
|
||||||
|
theme = ps.app_settings;
|
||||||
localStorage.setItem('app_theme', JSON.stringify(theme));
|
localStorage.setItem('app_theme', JSON.stringify(theme));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(theme) {
|
if(theme) {
|
||||||
// En asignados solemos destacar el secundario o primary, lo adaptamos:
|
|
||||||
document.documentElement.style.setProperty('--primary', theme.primary);
|
document.documentElement.style.setProperty('--primary', theme.primary);
|
||||||
document.documentElement.style.setProperty('--secondary', theme.secondary);
|
document.documentElement.style.setProperty('--secondary', theme.secondary);
|
||||||
document.documentElement.style.setProperty('--app-bg', theme.bg);
|
document.documentElement.style.setProperty('--app-bg', theme.bg);
|
||||||
}
|
}
|
||||||
} catch (e) { console.warn("Usando tema por defecto"); }
|
} catch (e) { console.warn("Usando tema y horario por defecto"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') {
|
if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') {
|
||||||
window.location.href = "index.html"; return;
|
window.location.href = "index.html"; return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await applyTheme();
|
await applyTheme();
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
loadStatuses();
|
loadStatuses();
|
||||||
@@ -194,21 +235,17 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
// FILTRO MAGICO: Solo nos quedamos con los que NO tienen fecha (scheduled_date vacío)
|
globalAllServices = data.services; // Guardamos TODOS para chequear la agenda real
|
||||||
// y que no sean bloqueos del sistema ni estén terminados.
|
|
||||||
|
// Filtramos los SIN CITA
|
||||||
localServices = data.services.filter(s => {
|
localServices = data.services.filter(s => {
|
||||||
if (s.provider === 'SYSTEM_BLOCK') return false;
|
if (s.provider === 'SYSTEM_BLOCK') return false;
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
|
|
||||||
// Si ya tiene fecha, no sale aquí (sale en calendario)
|
|
||||||
if (raw.scheduled_date && raw.scheduled_date.trim() !== "") return false;
|
if (raw.scheduled_date && raw.scheduled_date.trim() !== "") return false;
|
||||||
|
|
||||||
// Si está terminado/anulado, no sale aquí
|
|
||||||
if (raw.status_operativo) {
|
if (raw.status_operativo) {
|
||||||
const st = systemStatuses.find(x => String(x.id) === String(raw.status_operativo));
|
const st = systemStatuses.find(x => String(x.id) === String(raw.status_operativo));
|
||||||
if (st && st.is_final) return false;
|
if (st && st.is_final) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -250,7 +287,7 @@
|
|||||||
<div onclick="openActionModal(${s.id})" class="bg-white p-5 rounded-3xl border border-slate-200 shadow-sm active:scale-95 transition-transform flex gap-4 items-center relative overflow-hidden">
|
<div onclick="openActionModal(${s.id})" class="bg-white p-5 rounded-3xl border border-slate-200 shadow-sm active:scale-95 transition-transform flex gap-4 items-center relative overflow-hidden">
|
||||||
${isUrgent ? '<div class="absolute top-0 right-0 bg-red-500 text-white text-[8px] font-black px-3 py-1 rounded-bl-xl uppercase tracking-widest shadow-sm z-10">Urgente</div>' : ''}
|
${isUrgent ? '<div class="absolute top-0 right-0 bg-red-500 text-white text-[8px] font-black px-3 py-1 rounded-bl-xl uppercase tracking-widest shadow-sm z-10">Urgente</div>' : ''}
|
||||||
|
|
||||||
<div class="w-12 h-12 bg-amber-50 rounded-2xl flex flex-col items-center justify-center text-amber-500 shrink-0 border border-amber-100">
|
<div class="w-12 h-12 bg-primary-dynamic/10 rounded-2xl flex flex-col items-center justify-center text-primary-dynamic shrink-0 border border-primary-dynamic/20">
|
||||||
<i data-lucide="clock" class="w-5 h-5"></i>
|
<i data-lucide="clock" class="w-5 h-5"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="min-w-0 flex-1">
|
<div class="min-w-0 flex-1">
|
||||||
@@ -271,7 +308,155 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// LÓGICA DEL MODAL DE ACCIONES
|
// LÓGICA DEL MOTOR DE AGENDAMIENTO INTELIGENTE
|
||||||
|
// ==========================================
|
||||||
|
function toISODate(dateObj) {
|
||||||
|
const y = dateObj.getFullYear();
|
||||||
|
const m = String(dateObj.getMonth() + 1).padStart(2, '0');
|
||||||
|
const d = String(dateObj.getDate()).padStart(2, '0');
|
||||||
|
return `${y}-${m}-${d}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function timeToMins(t) {
|
||||||
|
let [h, m] = t.split(':').map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
function minsToTime(m) {
|
||||||
|
let h = Math.floor(m / 60).toString().padStart(2, '0');
|
||||||
|
let min = (m % 60).toString().padStart(2, '0');
|
||||||
|
return `${h}:${min}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildDayCarousel() {
|
||||||
|
const container = document.getElementById('dayCarousel');
|
||||||
|
container.innerHTML = "";
|
||||||
|
let today = new Date();
|
||||||
|
|
||||||
|
for (let i = 0; i < 14; i++) { // 14 días a futuro
|
||||||
|
let d = new Date(today);
|
||||||
|
d.setDate(today.getDate() + i);
|
||||||
|
|
||||||
|
if (d.getDay() === 0) continue; // Saltar domingos
|
||||||
|
|
||||||
|
const isoDate = toISODate(d);
|
||||||
|
const dayName = d.toLocaleDateString('es-ES', { weekday: 'short' }).replace('.', '').substring(0,3);
|
||||||
|
const dayNum = d.getDate();
|
||||||
|
|
||||||
|
// Seleccionar hoy por defecto
|
||||||
|
if (!pickerSelectedDate) pickerSelectedDate = isoDate;
|
||||||
|
|
||||||
|
const isSelected = isoDate === pickerSelectedDate;
|
||||||
|
|
||||||
|
container.innerHTML += `
|
||||||
|
<button type="button" onclick="selectPickerDate('${isoDate}')" class="day-chip flex flex-col items-center justify-center min-w-[3.5rem] p-2 rounded-2xl ${isSelected ? 'active' : 'inactive'}">
|
||||||
|
<span class="text-[9px] font-black uppercase opacity-80">${dayName}</span>
|
||||||
|
<span class="text-lg font-black leading-none mt-1">${dayNum}</span>
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectPickerDate(isoDate) {
|
||||||
|
pickerSelectedDate = isoDate;
|
||||||
|
pickerSelectedTime = ""; // Resetear hora al cambiar de día
|
||||||
|
buildDayCarousel(); // Repintar para actualizar estilos
|
||||||
|
renderTimeSlots();
|
||||||
|
checkSaveButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectPickerTime(timeStr) {
|
||||||
|
pickerSelectedTime = timeStr;
|
||||||
|
renderTimeSlots(); // Repintar para estilos
|
||||||
|
checkSaveButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkSaveButton() {
|
||||||
|
const btn = document.getElementById('btnSaveAppt');
|
||||||
|
if (pickerSelectedDate && pickerSelectedTime) {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.classList.remove('bg-slate-300', 'cursor-not-allowed');
|
||||||
|
btn.classList.add('bg-primary-dynamic', 'active:scale-95', 'shadow-lg');
|
||||||
|
} else {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.classList.add('bg-slate-300', 'cursor-not-allowed');
|
||||||
|
btn.classList.remove('bg-primary-dynamic', 'active:scale-95', 'shadow-lg');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOccupiedRanges(dateStr) {
|
||||||
|
let ranges = [];
|
||||||
|
globalAllServices.forEach(s => {
|
||||||
|
const raw = s.raw_data || {};
|
||||||
|
if (raw.scheduled_date === dateStr && raw.scheduled_time) {
|
||||||
|
const startMin = timeToMins(raw.scheduled_time);
|
||||||
|
const dur = parseInt(raw.duration_minutes || 60);
|
||||||
|
ranges.push({ start: startMin, end: startMin + dur });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isOverlapping(startMins, endMins, occupiedRanges) {
|
||||||
|
for(let r of occupiedRanges) {
|
||||||
|
// Hay solapamiento si mi inicio es antes de que él acabe, Y mi fin es después de que él empiece
|
||||||
|
if(startMins < r.end && endMins > r.start) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTimeSlots() {
|
||||||
|
const grid = document.getElementById('timeGrid');
|
||||||
|
const msg = document.getElementById('noSlotsMsg');
|
||||||
|
const duration = parseInt(document.getElementById('durationInput').value) || 60;
|
||||||
|
const occupied = getOccupiedRanges(pickerSelectedDate);
|
||||||
|
|
||||||
|
grid.innerHTML = "";
|
||||||
|
let slotsGenerated = 0;
|
||||||
|
|
||||||
|
// Función interna para recorrer tramos
|
||||||
|
const genSlotsForPeriod = (startStr, endStr) => {
|
||||||
|
let startMins = timeToMins(startStr);
|
||||||
|
let endMins = timeToMins(endStr);
|
||||||
|
|
||||||
|
// Saltos de 15 minutos
|
||||||
|
for (let m = startMins; m + duration <= endMins; m += 15) {
|
||||||
|
if (!isOverlapping(m, m + duration, occupied)) {
|
||||||
|
const timeStr = minsToTime(m);
|
||||||
|
const isSelected = timeStr === pickerSelectedTime;
|
||||||
|
grid.innerHTML += `
|
||||||
|
<button type="button" onclick="selectPickerTime('${timeStr}')" class="time-chip border rounded-xl py-2.5 text-xs font-bold ${isSelected ? 'active' : 'inactive hover:bg-slate-50'}">
|
||||||
|
${timeStr}
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
slotsGenerated++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generar Mañana y Tarde
|
||||||
|
genSlotsForPeriod(bizHours.m_start, bizHours.m_end);
|
||||||
|
genSlotsForPeriod(bizHours.a_start, bizHours.a_end);
|
||||||
|
|
||||||
|
if (slotsGenerated === 0) {
|
||||||
|
msg.classList.remove('hidden');
|
||||||
|
grid.classList.add('hidden');
|
||||||
|
pickerSelectedTime = ""; // Reset forzado
|
||||||
|
} else {
|
||||||
|
msg.classList.add('hidden');
|
||||||
|
grid.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si la hora que estaba seleccionada ya no sale (porque ampliaron la duración), la borramos
|
||||||
|
if (pickerSelectedTime && !grid.innerHTML.includes(`'${pickerSelectedTime}'`)) {
|
||||||
|
pickerSelectedTime = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSaveButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// APERTURA DE MODAL Y GUARDADO
|
||||||
// ==========================================
|
// ==========================================
|
||||||
function openActionModal(id) {
|
function openActionModal(id) {
|
||||||
const s = localServices.find(x => x.id === id);
|
const s = localServices.find(x => x.id === id);
|
||||||
@@ -283,24 +468,21 @@
|
|||||||
document.getElementById('detName').innerText = raw["Nombre Cliente"] || "Asegurado";
|
document.getElementById('detName').innerText = raw["Nombre Cliente"] || "Asegurado";
|
||||||
document.getElementById('detAddress').innerText = `${raw["Dirección"] || ""}, ${raw["Población"] || ""}`;
|
document.getElementById('detAddress').innerText = `${raw["Dirección"] || ""}, ${raw["Población"] || ""}`;
|
||||||
|
|
||||||
// Extraer teléfono limpio
|
|
||||||
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
|
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
|
||||||
const matchPhone = rawPhone.toString().match(/[6789]\d{8}/);
|
const matchPhone = rawPhone.toString().match(/[6789]\d{8}/);
|
||||||
document.getElementById('detPhoneRaw').value = matchPhone ? matchPhone[0] : "";
|
document.getElementById('detPhoneRaw').value = matchPhone ? matchPhone[0] : "";
|
||||||
|
|
||||||
// Limpiar inputs de fecha y poner duración por defecto
|
// INICIALIZAR EL AGENDADOR
|
||||||
document.getElementById('dateInput').value = "";
|
|
||||||
document.getElementById('timeInput').value = "";
|
|
||||||
document.getElementById('durationInput').value = "60";
|
document.getElementById('durationInput').value = "60";
|
||||||
|
pickerSelectedDate = ""; // Reset
|
||||||
|
pickerSelectedTime = ""; // Reset
|
||||||
|
buildDayCarousel(); // Esto selecciona 'hoy' automáticamente y pinta los huecos
|
||||||
|
checkSaveButton();
|
||||||
|
|
||||||
// Mostrar modal con animación
|
|
||||||
const modal = document.getElementById('actionModal');
|
const modal = document.getElementById('actionModal');
|
||||||
const content = document.getElementById('modalContent');
|
const content = document.getElementById('modalContent');
|
||||||
modal.classList.remove('hidden');
|
modal.classList.remove('hidden');
|
||||||
|
void modal.offsetWidth; // Reflow
|
||||||
// Reflow hack para que aplique la transición
|
|
||||||
void modal.offsetWidth;
|
|
||||||
|
|
||||||
modal.classList.remove('opacity-0');
|
modal.classList.remove('opacity-0');
|
||||||
content.classList.remove('translate-y-full');
|
content.classList.remove('translate-y-full');
|
||||||
}
|
}
|
||||||
@@ -312,9 +494,7 @@
|
|||||||
modal.classList.add('opacity-0');
|
modal.classList.add('opacity-0');
|
||||||
content.classList.add('translate-y-full');
|
content.classList.add('translate-y-full');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => { modal.classList.add('hidden'); }, 300);
|
||||||
modal.classList.add('hidden');
|
|
||||||
}, 300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function callClient() {
|
function callClient() {
|
||||||
@@ -331,33 +511,33 @@
|
|||||||
|
|
||||||
async function saveAppointment() {
|
async function saveAppointment() {
|
||||||
const id = document.getElementById('detId').value;
|
const id = document.getElementById('detId').value;
|
||||||
const date = document.getElementById('dateInput').value;
|
|
||||||
const time = document.getElementById('timeInput').value;
|
|
||||||
const duration = document.getElementById('durationInput').value;
|
const duration = document.getElementById('durationInput').value;
|
||||||
|
|
||||||
if (!date || !time) return alert("Selecciona fecha y hora para agendar.");
|
if (!pickerSelectedDate || !pickerSelectedTime) return alert("Selecciona un hueco disponible.");
|
||||||
|
|
||||||
const btn = document.getElementById('btnSaveAppt');
|
const btn = document.getElementById('btnSaveAppt');
|
||||||
const originalContent = btn.innerHTML;
|
const originalContent = btn.innerHTML;
|
||||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-5 h-5 animate-spin"></i> Guardando...`;
|
btn.innerHTML = `<i data-lucide="loader-2" class="w-5 h-5 animate-spin"></i> Agendando...`;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
// Buscamos el ID del estado "Citado" en el sistema
|
|
||||||
const citadoStatus = systemStatuses.find(st => st.name.toLowerCase().includes('citado'));
|
const citadoStatus = systemStatuses.find(st => st.name.toLowerCase().includes('citado'));
|
||||||
const statusToSave = citadoStatus ? String(citadoStatus.id) : null;
|
const statusToSave = citadoStatus ? String(citadoStatus.id) : null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Al enviar la fecha a esta ruta del server, el server dispara el WhatsApp Automático al cliente
|
|
||||||
const res = await fetch(`${API_URL}/services/set-appointment/${id}`, {
|
const res = await fetch(`${API_URL}/services/set-appointment/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify({ date: date, time: time, duration_minutes: duration, status_operativo: statusToSave })
|
body: JSON.stringify({
|
||||||
|
date: pickerSelectedDate,
|
||||||
|
time: pickerSelectedTime,
|
||||||
|
duration_minutes: duration,
|
||||||
|
status_operativo: statusToSave
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
showToast("Cita guardada correctamente");
|
showToast("Cita Agendada en Calendario");
|
||||||
closeModal();
|
closeModal();
|
||||||
// Como ahora tiene fecha, desaparecerá de esta lista y se irá al calendario
|
|
||||||
refreshData();
|
refreshData();
|
||||||
} else {
|
} else {
|
||||||
alert("Error al guardar la cita.");
|
alert("Error al guardar la cita.");
|
||||||
|
|||||||
Reference in New Issue
Block a user