From 8e6471ac86e9a6905b2f758d1b3a82c01a232c71 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 28 Mar 2026 21:30:17 +0000 Subject: [PATCH] Actualizar calendario.html --- calendario.html | 183 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/calendario.html b/calendario.html index b196b5c..c598eb6 100644 --- a/calendario.html +++ b/calendario.html @@ -48,6 +48,10 @@ /* Estilos para el chat */ .msg-me { background-color: #dcfce7; border-bottom-right-radius: 4px; border: 1px solid #bbf7d0; align-self: flex-end; } .msg-other { background-color: #f1f5f9; border-bottom-left-radius: 4px; border: 1px solid #e2e8f0; align-self: flex-start; } + + /* Modal Nuevo Servicio */ + .input-modern { @apply w-full bg-slate-50 border border-slate-200 px-4 py-3 rounded-xl text-sm font-semibold text-slate-700 outline-none transition-all focus:border-blue-500 focus:bg-white focus:ring-2 focus:ring-blue-100; } + .label-modern { @apply block text-[10px] font-black text-slate-500 uppercase tracking-widest mb-1.5 ml-1; } @@ -64,6 +68,9 @@ +
@@ -282,6 +289,69 @@
+ +
Guardado @@ -1262,6 +1332,119 @@ setTimeout(() => { t.classList.add('opacity-0', 'pointer-events-none', '-translate-y-10'); t.classList.remove('translate-y-0'); }, 2000); } + // ===================================== + // FUNCIONES DE ALTA RÁPIDA (OPERARIO) + // ===================================== + function openNewServiceModal() { + document.getElementById('nsPhone').value = ""; + document.getElementById('nsName').value = ""; + document.getElementById('nsAddress').value = ""; + document.getElementById('nsDesc').value = ""; + document.getElementById('nsTime').value = ""; + document.getElementById('nsDate').value = selectedDateStr; + + const modal = document.getElementById('newServiceModal'); + modal.style.display = 'flex'; + setTimeout(() => modal.classList.remove('translate-y-full'), 10); + safeLoadIcons(); + } + + function closeNewServiceModal() { + const modal = document.getElementById('newServiceModal'); + modal.classList.add('translate-y-full'); + setTimeout(() => modal.style.display = 'none', 300); + } + + async function searchClientApp(phone) { + if (phone.length < 9) { + document.getElementById('nsName').classList.remove('bg-emerald-50'); + return; + } + try { + const res = await fetch(`${API_URL}/clients/search?phone=${phone}`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); + if (data.ok && data.client) { + const nameInput = document.getElementById('nsName'); + if (!nameInput.value) { + nameInput.value = data.client.full_name; + nameInput.classList.add('bg-emerald-50'); + } + if (!document.getElementById('nsAddress').value && data.client.addresses?.length > 0) { + document.getElementById('nsAddress').value = data.client.addresses[0]; + } + } + } catch (e) {} + } + + async function saveNewServiceApp(e) { + e.preventDefault(); + const btn = document.getElementById('btnSaveNewApp'); + const originalHTML = btn.innerHTML; + btn.innerHTML = ` Procesando...`; + btn.disabled = true; + + try { + const token = localStorage.getItem("token"); + const payloadDecoded = JSON.parse(atob(token.split('.')[1])); + const myWorkerId = payloadDecoded.sub; + + const createData = { + phone: document.getElementById('nsPhone').value, + name: document.getElementById('nsName').value, + address: document.getElementById('nsAddress').value, + description: document.getElementById('nsDesc').value, + guild_id: null, + assigned_to: myWorkerId, + duration_minutes: document.getElementById('nsDuration').value, + is_urgent: false, + is_company: false, + company_name: 'Particular', + company_ref: null, + mode: 'manual' + }; + + const resCreate = await fetch(`${API_URL}/services/manual-high`, { + method: 'POST', + headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` }, + body: JSON.stringify(createData) + }); + const dataCreate = await resCreate.json(); + + if (!dataCreate.ok || !dataCreate.id) throw new Error("No se pudo crear el servicio"); + + const citadoSt = systemStatuses.find(st => st.name.toLowerCase().includes('citado')); + const statusMapId = citadoSt ? String(citadoSt.id) : null; + + const date = document.getElementById('nsDate').value; + const time = document.getElementById('nsTime').value; + const duration = document.getElementById('nsDuration').value; + + await fetch(`${API_URL}/services/set-appointment/${dataCreate.id}`, { + method: 'PUT', + headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` }, + body: JSON.stringify({ + date: date, + time: time, + duration_minutes: duration, + status_operativo: statusMapId + }) + }); + + closeNewServiceModal(); + showToast("¡Aviso Creado y Citado!"); + refreshData(); + + } catch (err) { + showToast("Error al guardar", true); + } finally { + btn.innerHTML = originalHTML; + btn.disabled = false; + safeLoadIcons(); + } + } + function logout() { localStorage.clear(); window.location.href = "index.html"; }