Actualizar index.html
This commit is contained in:
421
index.html
421
index.html
@@ -2,290 +2,241 @@
|
|||||||
<html lang="es">
|
<html lang="es">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<title>Mi Área de Cliente | IntegraRepara</title>
|
<title>Portal del Cliente - IntegraRepara</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<script src="https://unpkg.com/lucide@latest"></script>
|
<script src="https://unpkg.com/lucide@latest"></script>
|
||||||
<style>
|
<style>
|
||||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700;900&display=swap');
|
body { background-color: #f8fafc; }
|
||||||
body { font-family: 'Inter', sans-serif; background-color: #f8fafc; }
|
|
||||||
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
|
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
|
||||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
|
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
|
||||||
.pulse-soft { animation: pulseSoft 2s infinite; }
|
.glass-panel { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); }
|
||||||
@keyframes pulseSoft { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
|
|
||||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="text-slate-800 antialiased min-h-screen flex flex-col relative pb-24">
|
<body class="text-slate-800 font-sans antialiased min-h-screen flex flex-col items-center">
|
||||||
|
|
||||||
<div id="loader" class="fixed inset-0 bg-slate-50 z-50 flex flex-col items-center justify-center transition-opacity duration-300">
|
<div id="loader" class="fixed inset-0 bg-slate-50 z-50 flex flex-col items-center justify-center transition-opacity duration-300">
|
||||||
<i data-lucide="loader-2" class="w-10 h-10 text-blue-600 animate-spin mb-4"></i>
|
<div class="w-12 h-12 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin mb-4"></div>
|
||||||
<p class="text-slate-500 font-bold text-sm tracking-widest uppercase animate-pulse">Cargando tu portal...</p>
|
<p class="text-sm font-bold text-slate-500 animate-pulse">Cargando tu expediente...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="errorScreen" class="fixed inset-0 bg-slate-50 z-40 hidden flex-col items-center justify-center p-6 text-center">
|
<div id="errorScreen" class="hidden w-full max-w-md mx-auto p-6 flex flex-col items-center justify-center min-h-screen text-center fade-in">
|
||||||
<div class="bg-red-100 p-4 rounded-full text-red-500 mb-4 shadow-sm">
|
<div class="w-20 h-20 bg-red-100 text-red-500 rounded-full flex items-center justify-center mb-6 shadow-inner">
|
||||||
<i data-lucide="shield-alert" class="w-10 h-10"></i>
|
<i data-lucide="shield-alert" class="w-10 h-10"></i>
|
||||||
</div>
|
</div>
|
||||||
<h2 class="text-2xl font-black text-slate-800 mb-2">Enlace no válido</h2>
|
<h2 class="text-2xl font-black text-slate-800 mb-2">Enlace no válido</h2>
|
||||||
<p class="text-slate-500 max-w-sm mb-6">Parece que este enlace ha caducado o no es correcto. Por favor, solicita un nuevo acceso a tu empresa de reparaciones.</p>
|
<p class="text-slate-500 font-medium">Parece que este enlace ha caducado o no es correcto. Por favor, solicita un nuevo acceso a tu empresa de reparaciones.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<header class="bg-slate-900 text-white pt-10 pb-6 px-6 rounded-b-[2.5rem] shadow-xl relative overflow-hidden shrink-0 z-10">
|
<main id="mainContent" class="hidden w-full max-w-md mx-auto min-h-screen flex flex-col relative pb-24">
|
||||||
<div class="absolute -top-24 -right-24 w-48 h-48 bg-blue-500 rounded-full mix-blend-multiply filter blur-3xl opacity-20 pulse-soft"></div>
|
|
||||||
<div class="absolute top-10 -left-10 w-32 h-32 bg-purple-500 rounded-full mix-blend-multiply filter blur-3xl opacity-20 pulse-soft" style="animation-delay: 1s;"></div>
|
|
||||||
|
|
||||||
<div class="relative z-10 flex justify-between items-center max-w-3xl mx-auto">
|
<header class="bg-slate-900 text-white p-6 pt-10 rounded-b-[2.5rem] shadow-lg relative z-10 shrink-0">
|
||||||
<div>
|
<div class="flex items-center justify-between">
|
||||||
<p class="text-[10px] text-slate-400 font-bold uppercase tracking-widest mb-1">Área Privada</p>
|
<div>
|
||||||
<h1 id="uiCompanyName" class="text-xl font-black tracking-tight text-white flex items-center gap-2">
|
<p class="text-[10px] font-black text-blue-400 uppercase tracking-widest mb-1">Gestión de Siniestro</p>
|
||||||
<div class="w-2 h-2 bg-blue-500 rounded-full"></div> Cargando...
|
<h1 id="companyName" class="text-xl font-black tracking-tight leading-none uppercase">Empresa Reparadora</h1>
|
||||||
</h1>
|
</div>
|
||||||
|
<div class="bg-white/10 p-3 rounded-2xl backdrop-blur-sm">
|
||||||
|
<i data-lucide="home" class="w-6 h-6 text-white"></i>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-white/10 p-2.5 rounded-2xl backdrop-blur-md border border-white/10">
|
</header>
|
||||||
<i data-lucide="user" class="w-5 h-5 text-blue-300"></i>
|
|
||||||
|
<div class="px-5 -mt-6 relative z-20 flex-1 flex flex-col gap-5 fade-in">
|
||||||
|
|
||||||
|
<div class="bg-white p-6 rounded-[2rem] shadow-xl shadow-slate-200/50 border border-slate-100">
|
||||||
|
<h2 class="text-2xl font-black text-slate-800 mb-1">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2>
|
||||||
|
<p class="text-sm text-slate-500 font-medium mb-5">Aquí tienes los detalles de tu reparación.</p>
|
||||||
|
|
||||||
|
<div id="dateContainer">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="workerCard" class="bg-gradient-to-br from-blue-50 to-indigo-50 p-6 rounded-[2rem] border border-blue-100 shadow-sm hidden">
|
||||||
|
<p class="text-[10px] font-black text-blue-500 uppercase tracking-widest mb-4">Técnico Asignado</p>
|
||||||
|
<div class="flex items-center gap-4 mb-5">
|
||||||
|
<div class="w-14 h-14 bg-white rounded-full flex items-center justify-center shadow-md text-blue-600 shrink-0">
|
||||||
|
<i data-lucide="user-check" class="w-7 h-7"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3 id="workerName" class="font-black text-slate-800 text-lg uppercase leading-tight">Juan Pérez</h3>
|
||||||
|
<p class="text-xs text-slate-500 font-medium mt-0.5">Operario Especialista</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-2 gap-3">
|
||||||
|
<a href="#" id="btnCall" class="bg-white border border-blue-200 text-blue-700 font-black py-3 rounded-xl flex justify-center items-center gap-2 shadow-sm hover:bg-blue-50 transition active:scale-95 text-xs uppercase tracking-wider">
|
||||||
|
<i data-lucide="phone" class="w-4 h-4"></i> Llamar
|
||||||
|
</a>
|
||||||
|
<a href="#" id="btnWa" class="bg-emerald-500 text-white font-black py-3 rounded-xl flex justify-center items-center gap-2 shadow-md shadow-emerald-200 hover:bg-emerald-600 transition active:scale-95 text-xs uppercase tracking-wider">
|
||||||
|
<i data-lucide="message-circle" class="w-4 h-4"></i> WhatsApp
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 space-y-5">
|
||||||
|
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-2">Detalles del Aviso <span id="serviceRef" class="float-right text-slate-300">#0000</span></p>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="bg-slate-50 p-2 rounded-lg text-slate-400 mt-0.5"><i data-lucide="map-pin" class="w-4 h-4"></i></div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs font-bold text-slate-400 uppercase">Dirección</p>
|
||||||
|
<p id="serviceAddress" class="font-bold text-slate-700 text-sm mt-0.5 uppercase"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="bg-slate-50 p-2 rounded-lg text-slate-400 mt-0.5"><i data-lucide="phone" class="w-4 h-4"></i></div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs font-bold text-slate-400 uppercase">Teléfono de Contacto</p>
|
||||||
|
<p id="servicePhone" class="font-bold text-slate-700 text-sm mt-0.5"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="bg-amber-50 p-2 rounded-lg text-amber-500 mt-0.5"><i data-lucide="alert-triangle" class="w-4 h-4"></i></div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs font-bold text-amber-500 uppercase">Avería Reportada</p>
|
||||||
|
<p id="serviceDesc" class="font-medium text-slate-600 text-sm mt-1 bg-slate-50 p-3 rounded-xl leading-relaxed"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
|
||||||
|
|
||||||
<main id="mainContent" class="flex-1 px-6 pt-6 max-w-3xl mx-auto w-full hidden flex-col gap-6">
|
|
||||||
|
|
||||||
<div class="fade-in" style="animation-delay: 0.1s;">
|
|
||||||
<h2 class="text-3xl font-black text-slate-800 tracking-tight leading-none mb-1">Hola, <span id="uiClientName" class="text-blue-600"></span>👋</h2>
|
|
||||||
<p class="text-sm text-slate-500 font-medium mb-6">Aquí tienes el estado en tiempo real de tus reparaciones.</p>
|
|
||||||
|
|
||||||
<button onclick="openNewRequestModal()" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-black py-4 px-6 rounded-[1.5rem] shadow-[0_8px_20px_-6px_rgba(37,99,235,0.5)] transition-all active:scale-95 flex items-center justify-between group">
|
|
||||||
<div class="flex items-center gap-3">
|
|
||||||
<div class="bg-white/20 p-2 rounded-xl group-hover:scale-110 transition-transform"><i data-lucide="wrench" class="w-5 h-5"></i></div>
|
|
||||||
<span class="uppercase tracking-wide text-sm">Solicitar Reparación</span>
|
|
||||||
</div>
|
|
||||||
<i data-lucide="arrow-right" class="w-5 h-5 opacity-70 group-hover:opacity-100 group-hover:translate-x-1 transition-all"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="fade-in flex flex-col gap-4" style="animation-delay: 0.2s;">
|
|
||||||
<h3 class="font-black text-xs uppercase tracking-widest text-slate-400 ml-2 mt-4 flex items-center gap-2">
|
|
||||||
<i data-lucide="history" class="w-3.5 h-3.5"></i> Tu Historial
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div id="servicesContainer" class="flex flex-col gap-4">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<div id="newRequestModal" class="fixed inset-0 bg-slate-900/60 z-[100] hidden flex items-end sm:items-center justify-center backdrop-blur-sm sm:p-4">
|
<script>
|
||||||
<div class="bg-white w-full max-w-lg rounded-t-[2.5rem] sm:rounded-[2.5rem] shadow-2xl overflow-hidden flex flex-col fade-in max-h-[90vh]">
|
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||||
<div class="p-6 border-b border-slate-100 flex justify-between items-center sticky top-0 bg-white/90 backdrop-blur z-10">
|
? 'http://localhost:3000'
|
||||||
<div>
|
: 'https://integrarepara-api.integrarepara.es'; // <-- Asegúrate de que esta URL es correcta
|
||||||
<h3 class="font-black text-slate-800 uppercase tracking-tight text-lg">Nuevo Aviso</h3>
|
</script>
|
||||||
<p class="text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-0.5">Envío directo a la central</p>
|
|
||||||
</div>
|
|
||||||
<button onclick="closeNewRequestModal()" class="bg-slate-100 text-slate-500 hover:text-red-500 p-2 rounded-full transition-colors active:scale-95"><i data-lucide="x" class="w-5 h-5"></i></button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form onsubmit="submitNewRequest(event)" class="p-6 overflow-y-auto no-scrollbar flex flex-col gap-5">
|
|
||||||
<div class="space-y-2">
|
|
||||||
<label class="text-[10px] font-black uppercase tracking-widest text-slate-500 ml-1">Dirección de la avería</label>
|
|
||||||
<div class="relative">
|
|
||||||
<i data-lucide="map-pin" class="w-4 h-4 absolute left-4 top-4 text-slate-400"></i>
|
|
||||||
<input type="text" id="reqAddress" required placeholder="Ej: Calle Mayor 12, Piso 2A" class="w-full bg-slate-50 border border-slate-200 text-sm font-bold p-4 pl-11 rounded-[1.2rem] outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all text-slate-700 shadow-inner">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-2">
|
|
||||||
<label class="text-[10px] font-black uppercase tracking-widest text-slate-500 ml-1">¿Qué ha ocurrido?</label>
|
|
||||||
<textarea id="reqDescription" required rows="4" placeholder="Explícanos brevemente qué se ha roto o qué necesitas..." class="w-full bg-slate-50 border border-slate-200 text-sm font-medium p-4 rounded-[1.2rem] outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all text-slate-700 shadow-inner resize-none"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" id="btnSubmitRequest" class="w-full mt-2 bg-slate-900 text-white font-black py-4 rounded-[1.2rem] text-sm uppercase tracking-wider hover:bg-slate-800 transition-colors active:scale-95 shadow-lg flex justify-center items-center gap-2">
|
|
||||||
<i data-lucide="send" class="w-4 h-4"></i> Enviar Aviso Ahora
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="toast" class="fixed bottom-6 left-1/2 -translate-x-1/2 bg-slate-800 text-white px-6 py-3.5 rounded-full shadow-2xl hidden z-[200] font-bold text-sm flex items-center gap-3 transition-all transform whitespace-nowrap">
|
|
||||||
<i data-lucide="check-circle" class="w-4 h-4 text-emerald-400"></i>
|
|
||||||
<span id="toastMsg">Aviso enviado con éxito</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// ==========================================
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
// ⚙️ CONFIGURACIÓN - ¡PON TU API AQUÍ!
|
|
||||||
// ==========================================
|
|
||||||
const API_URL = "https://integrarepara-api.integrarepara.es";// <--- CAMBIAR POR LA URL REAL DEL BACKEND
|
|
||||||
|
|
||||||
let clientData = null;
|
|
||||||
let apiToken = new URLSearchParams(window.location.search).get('token');
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
if (!apiToken) {
|
|
||||||
|
// 1. Extraer variables de la URL
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const token = urlParams.get('token');
|
||||||
|
const serviceId = urlParams.get('service');
|
||||||
|
|
||||||
|
if (!token || !serviceId) {
|
||||||
showError();
|
showError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadPortalData();
|
|
||||||
|
try {
|
||||||
|
// 2. Pedir datos al servidor usando el token
|
||||||
|
const res = await fetch(`${API_URL}/public/portal/${token}`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
if (!data.ok) throw new Error("Token inválido");
|
||||||
|
|
||||||
|
// 3. Buscar el servicio específico
|
||||||
|
const service = data.services.find(s => String(s.id) === String(serviceId));
|
||||||
|
if (!service) throw new Error("Servicio no encontrado");
|
||||||
|
|
||||||
|
// 4. Renderizar datos en pantalla
|
||||||
|
renderPortal(data.client, data.company, service);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
showError();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function loadPortalData() {
|
function showError() {
|
||||||
try {
|
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
|
||||||
const response = await fetch(`${API_URL}/public/portal/${apiToken}`);
|
setTimeout(() => {
|
||||||
const data = await response.json();
|
document.getElementById('loader').classList.add('hidden');
|
||||||
|
document.getElementById('errorScreen').classList.remove('hidden');
|
||||||
if (!data.ok) throw new Error("Invalid token");
|
document.getElementById('errorScreen').classList.add('flex');
|
||||||
|
}, 300);
|
||||||
clientData = data.client;
|
|
||||||
|
|
||||||
// Rellenar UI
|
|
||||||
document.getElementById('uiCompanyName').innerHTML = `<div class="w-2 h-2 bg-emerald-400 shadow-[0_0_8px_rgba(52,211,153,0.8)] rounded-full animate-pulse"></div> ${data.company.name}`;
|
|
||||||
document.getElementById('uiClientName').innerText = data.client.name.split(' ')[0]; // Solo el primer nombre
|
|
||||||
|
|
||||||
// Pre-rellenar formulario
|
|
||||||
if(data.client.addresses && data.client.addresses.length > 0) {
|
|
||||||
document.getElementById('reqAddress').value = data.client.addresses[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
renderServices(data.services);
|
|
||||||
|
|
||||||
// Mostrar pantalla
|
|
||||||
document.getElementById('loader').classList.add('opacity-0');
|
|
||||||
setTimeout(() => {
|
|
||||||
document.getElementById('loader').classList.add('hidden');
|
|
||||||
document.getElementById('mainContent').classList.remove('hidden');
|
|
||||||
document.getElementById('mainContent').classList.add('flex');
|
|
||||||
}, 300);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
showError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderServices(services) {
|
function renderPortal(client, company, service) {
|
||||||
const container = document.getElementById('servicesContainer');
|
// Textos básicos
|
||||||
|
document.getElementById('companyName').innerText = company.name || "Empresa Reparadora";
|
||||||
|
document.getElementById('clientName').innerText = client.name.split(' ')[0]; // Solo el primer nombre
|
||||||
|
document.getElementById('serviceRef').innerText = "#" + (service.title.replace('Expediente #', '') || service.id);
|
||||||
|
|
||||||
if (!services || services.length === 0) {
|
// Dirección, Teléfono y Descripción
|
||||||
container.innerHTML = `
|
// NOTA: Como la API no devuelve la dirección dentro de service directamente en public/portal, usamos la del cliente por ahora.
|
||||||
<div class="bg-white border-2 border-dashed border-slate-200 p-8 rounded-[2rem] text-center">
|
// Si quieres la exacta del parte, tendremos que añadirla a la API después.
|
||||||
<div class="bg-slate-50 w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-3">
|
document.getElementById('serviceAddress').innerText = client.addresses[0] || "Dirección no especificada";
|
||||||
<i data-lucide="inbox" class="w-8 h-8 text-slate-300"></i>
|
document.getElementById('servicePhone').innerText = client.phone;
|
||||||
</div>
|
document.getElementById('serviceDesc').innerText = service.description || "Avería general reportada.";
|
||||||
<h4 class="font-black text-slate-700 text-sm uppercase">Sin reparaciones</h4>
|
|
||||||
<p class="text-xs text-slate-400 mt-1">Aún no tienes historiales con nosotros.</p>
|
// ¿Hay un técnico asignado?
|
||||||
</div>`;
|
if (service.assigned_worker && service.assigned_worker !== "Pendiente") {
|
||||||
lucide.createIcons();
|
document.getElementById('workerCard').classList.remove('hidden');
|
||||||
return;
|
document.getElementById('workerName').innerText = service.assigned_worker;
|
||||||
|
|
||||||
|
// NOTA TÉCNICA: De momento el servidor no devuelve el teléfono del operario.
|
||||||
|
// Ponemos los botones con un alert temporal hasta que actualicemos server.js
|
||||||
|
document.getElementById('btnCall').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); };
|
||||||
|
document.getElementById('btnWa').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); };
|
||||||
}
|
}
|
||||||
|
|
||||||
const colorMap = {
|
// ¿Hay cita o está pendiente de agendar?
|
||||||
'gray': 'bg-slate-100 text-slate-600 border-slate-200',
|
const dateContainer = document.getElementById('dateContainer');
|
||||||
'blue': 'bg-blue-100 text-blue-700 border-blue-200 shadow-[0_0_15px_rgba(59,130,246,0.15)]',
|
|
||||||
'emerald': 'bg-emerald-100 text-emerald-700 border-emerald-200 shadow-[0_0_15px_rgba(16,185,129,0.15)]',
|
|
||||||
'indigo': 'bg-indigo-100 text-indigo-700 border-indigo-200 shadow-[0_0_15px_rgba(99,102,241,0.15)]',
|
|
||||||
'amber': 'bg-amber-100 text-amber-700 border-amber-200 shadow-[0_0_15px_rgba(245,158,11,0.15)]',
|
|
||||||
'red': 'bg-rose-100 text-rose-700 border-rose-200',
|
|
||||||
'purple': 'bg-purple-100 text-purple-700 border-purple-200'
|
|
||||||
};
|
|
||||||
|
|
||||||
const iconMap = {
|
if (service.scheduled_date) {
|
||||||
'gray': 'clock',
|
// Ya tiene cita
|
||||||
'blue': 'user-check',
|
dateContainer.innerHTML = `
|
||||||
'emerald': 'calendar-check',
|
<div class="bg-emerald-50 border border-emerald-200 p-4 rounded-2xl flex items-center gap-4">
|
||||||
'indigo': 'car',
|
<div class="w-12 h-12 bg-white rounded-xl flex flex-col items-center justify-center shadow-sm shrink-0 border border-emerald-100">
|
||||||
'amber': 'wrench',
|
<span class="text-[10px] font-black text-emerald-500 uppercase leading-none">Cita</span>
|
||||||
'red': 'alert-triangle',
|
<i data-lucide="check" class="w-5 h-5 text-emerald-600 mt-1"></i>
|
||||||
'purple': 'check-circle'
|
</div>
|
||||||
};
|
<div>
|
||||||
|
<p class="font-black text-slate-800 uppercase text-sm">${formatDate(service.scheduled_date)}</p>
|
||||||
container.innerHTML = services.map(s => {
|
<p class="text-xs font-bold text-emerald-600 mt-0.5 flex items-center gap-1"><i data-lucide="clock" class="w-3 h-3"></i> Turno: ${service.scheduled_time || 'A convenir'}</p>
|
||||||
const badgeClass = colorMap[s.status_color] || colorMap['gray'];
|
|
||||||
const badgeIcon = iconMap[s.status_color] || 'info';
|
|
||||||
|
|
||||||
const fechaCita = s.scheduled_date ? `<div class="flex items-center gap-1.5 text-xs font-bold text-slate-600 bg-slate-50 px-3 py-1.5 rounded-lg border border-slate-100"><i data-lucide="calendar" class="w-3.5 h-3.5 text-slate-400"></i> ${s.scheduled_date} ${s.scheduled_time ? `| ${s.scheduled_time}` : ''}</div>` : '';
|
|
||||||
|
|
||||||
const tecnico = s.assigned_worker !== "Pendiente" ? `<div class="flex items-center gap-1.5 text-[10px] font-black uppercase text-slate-500 mt-3 pt-3 border-t border-slate-100"><i data-lucide="hard-hat" class="w-3.5 h-3.5"></i> Técnico: ${s.assigned_worker}</div>` : '';
|
|
||||||
|
|
||||||
return `
|
|
||||||
<div class="bg-white p-5 rounded-[1.5rem] shadow-sm border border-slate-200 flex flex-col gap-3 relative overflow-hidden">
|
|
||||||
${s.status_color !== 'purple' && s.status_color !== 'red' && s.status_color !== 'gray' ? `<div class="absolute top-0 left-0 w-1 h-full bg-${s.status_color}-500"></div>` : ''}
|
|
||||||
|
|
||||||
<div class="flex justify-between items-start gap-2">
|
|
||||||
<div class="${badgeClass} px-3 py-1.5 rounded-xl border flex items-center gap-1.5 w-max">
|
|
||||||
<i data-lucide="${badgeIcon}" class="w-3.5 h-3.5"></i>
|
|
||||||
<span class="text-[10px] font-black uppercase tracking-wider">${s.status_name}</span>
|
|
||||||
</div>
|
</div>
|
||||||
<span class="text-[9px] font-black text-slate-300 uppercase tracking-widest bg-slate-50 px-2 py-1 rounded-md border border-slate-100">${s.title}</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
// NO tiene cita (Mostrar botón de Agendar)
|
||||||
|
dateContainer.innerHTML = `
|
||||||
|
<div class="bg-amber-50 border border-amber-200 p-5 rounded-2xl text-center">
|
||||||
|
<div class="w-12 h-12 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto mb-3">
|
||||||
|
<i data-lucide="calendar-plus" class="w-6 h-6"></i>
|
||||||
|
</div>
|
||||||
|
<h4 class="font-black text-slate-800 uppercase text-lg leading-tight">Pendiente de Cita</h4>
|
||||||
|
<p class="text-xs text-slate-600 font-medium mt-1 mb-4">El técnico necesita saber cuándo puede pasar por tu domicilio.</p>
|
||||||
|
|
||||||
<p class="text-sm font-medium text-slate-700 leading-snug mt-1">${s.description.replace(/\n/g, '<br>')}</p>
|
<button onclick="startBooking()" class="w-full bg-slate-900 text-white font-black py-4 rounded-xl shadow-lg hover:bg-blue-600 transition-all active:scale-95 flex justify-center items-center gap-2 uppercase tracking-widest text-xs">
|
||||||
|
<i data-lucide="calendar-check" class="w-4 h-4"></i> Agendar Visita Ahora
|
||||||
${fechaCita}
|
</button>
|
||||||
${tecnico}
|
</div>
|
||||||
</div>`;
|
`;
|
||||||
}).join('');
|
}
|
||||||
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
|
// Quitar loader
|
||||||
|
document.getElementById('loader').classList.add('opacity-0', 'pointer-events-none');
|
||||||
|
setTimeout(() => document.getElementById('loader').classList.add('hidden'), 300);
|
||||||
|
document.getElementById('mainContent').classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitNewRequest(e) {
|
// Formateador de fechas simple
|
||||||
e.preventDefault();
|
function formatDate(dateStr) {
|
||||||
const btn = document.getElementById('btnSubmitRequest');
|
if (!dateStr) return "";
|
||||||
const originalContent = btn.innerHTML;
|
|
||||||
const address = document.getElementById('reqAddress').value;
|
|
||||||
const desc = document.getElementById('reqDescription').value;
|
|
||||||
|
|
||||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Procesando...`;
|
|
||||||
btn.disabled = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/public/portal/${apiToken}/request`, {
|
const parts = dateStr.split('-');
|
||||||
method: 'POST',
|
if(parts.length !== 3) return dateStr;
|
||||||
headers: { 'Content-Type': 'application/json' },
|
const d = new Date(parts[0], parts[1]-1, parts[2]);
|
||||||
body: JSON.stringify({ address: address, description: desc })
|
const opciones = { weekday: 'long', day: 'numeric', month: 'long' };
|
||||||
});
|
return d.toLocaleDateString('es-ES', opciones);
|
||||||
|
} catch(e) { return dateStr; }
|
||||||
if(res.ok) {
|
|
||||||
closeNewRequestModal();
|
|
||||||
document.getElementById('reqDescription').value = ""; // limpiar
|
|
||||||
showToast();
|
|
||||||
loadPortalData(); // Recargar para mostrar la nueva petición
|
|
||||||
} else {
|
|
||||||
alert("Error al enviar el aviso. Inténtalo de nuevo.");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
alert("Error de conexión con el servidor.");
|
|
||||||
} finally {
|
|
||||||
btn.innerHTML = originalContent;
|
|
||||||
btn.disabled = false;
|
|
||||||
lucide.createIcons();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showError() {
|
// Función que se dispara al pulsar "Agendar Visita Ahora"
|
||||||
document.getElementById('loader').classList.add('hidden');
|
function startBooking() {
|
||||||
document.getElementById('errorScreen').classList.remove('hidden');
|
// Aquí abriremos la ventana modal o el siguiente paso para elegir el día.
|
||||||
document.getElementById('errorScreen').classList.add('flex');
|
alert("¡Perfecto! Aquí abriremos el calendario para que el cliente elija el día. Seguimos cuando me confirmes que el diseño te gusta.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function openNewRequestModal() {
|
|
||||||
document.getElementById('newRequestModal').classList.remove('hidden');
|
|
||||||
document.body.style.overflow = 'hidden'; // Evitar scroll de fondo en móvil
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeNewRequestModal() {
|
|
||||||
document.getElementById('newRequestModal').classList.add('hidden');
|
|
||||||
document.body.style.overflow = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function showToast() {
|
|
||||||
const t = document.getElementById('toast');
|
|
||||||
t.classList.remove('hidden');
|
|
||||||
setTimeout(() => { t.classList.add('translate-y-[-20px]', 'opacity-0'); }, 3000);
|
|
||||||
setTimeout(() => {
|
|
||||||
t.classList.add('hidden');
|
|
||||||
t.classList.remove('translate-y-[-20px]', 'opacity-0');
|
|
||||||
}, 3500);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user