257 lines
15 KiB
HTML
257 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Servicios - IntegraRepara</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script src="https://unpkg.com/lucide@latest"></script>
|
|
<style>
|
|
.fade-in { animation: fadeIn 0.3s ease-in-out; }
|
|
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
/* Animación para el panel lateral */
|
|
.slide-in { animation: slideIn 0.3s ease-out forwards; }
|
|
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden">
|
|
|
|
<div class="flex h-screen overflow-hidden">
|
|
<div id="sidebar-container" class="h-full"></div>
|
|
<div class="flex-1 flex flex-col overflow-hidden relative">
|
|
<div id="header-container"></div>
|
|
|
|
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-50 p-6 relative">
|
|
|
|
<div id="servicesListView" class="fade-in">
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
|
|
<i data-lucide="briefcase" class="text-blue-600"></i> Servicios Activos
|
|
</h2>
|
|
<button onclick="toggleView('create')" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg shadow-lg flex items-center gap-2">
|
|
<i data-lucide="plus"></i> Nuevo Servicio
|
|
</button>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
|
|
<table class="w-full text-left border-collapse">
|
|
<thead class="bg-gray-50 text-gray-500 text-xs uppercase tracking-wider border-b">
|
|
<tr>
|
|
<th class="p-4">Fecha</th>
|
|
<th class="p-4">Cliente / Dirección</th>
|
|
<th class="p-4">Asunto</th>
|
|
<th class="p-4">Estado Actual</th>
|
|
<th class="p-4 text-right"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="servicesTableBody" class="divide-y divide-gray-100 text-sm">
|
|
<tr><td colspan="5" class="p-6 text-center text-gray-400">Cargando servicios...</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="createServiceView" class="hidden fade-in max-w-5xl mx-auto">
|
|
<button onclick="toggleView('list')" class="mb-4 text-gray-500 hover:text-gray-800 flex items-center gap-2"><i data-lucide="arrow-left"></i> Volver al listado</button>
|
|
<div class="bg-white p-8 rounded-xl shadow-lg border border-gray-100">
|
|
<h2 class="text-xl font-bold mb-6">Nuevo Servicio</h2>
|
|
<form onsubmit="createService(event)" class="space-y-6">
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div><label class="text-xs font-bold block mb-1">Teléfono</label><input type="tel" id="sPhone" class="w-full border rounded p-2" onblur="searchClientByPhone()" required></div>
|
|
<div><label class="text-xs font-bold block mb-1">Nombre</label><input type="text" id="sName" class="w-full border rounded p-2" required></div>
|
|
<div class="col-span-2"><label class="text-xs font-bold block mb-1">Dirección</label><input type="text" id="sAddress" class="w-full border rounded p-2" required></div>
|
|
<div><label class="text-xs font-bold block mb-1">Email</label><input type="email" id="sEmail" class="w-full border rounded p-2"></div>
|
|
<div class="col-span-2"><label class="text-xs font-bold block mb-1">Descripción</label><textarea id="sDesc" class="w-full border rounded p-2"></textarea></div>
|
|
<input type="hidden" id="sDate"><input type="hidden" id="sTime"><input type="hidden" id="sDuration"><input type="checkbox" id="sUrgent" class="hidden"><input type="checkbox" id="sIsCompany" class="hidden">
|
|
</div>
|
|
<button type="submit" id="btnSave" class="w-full bg-blue-600 text-white font-bold py-3 rounded mt-4">Crear Servicio</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="serviceDetailPanel" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex justify-end">
|
|
<div class="w-full max-w-md bg-white h-full shadow-2xl p-6 overflow-y-auto slide-in">
|
|
<button onclick="closeDetailPanel()" class="mb-4 text-gray-500 hover:text-black flex items-center gap-2"><i data-lucide="x"></i> Cerrar</button>
|
|
|
|
<div class="border-b pb-4 mb-6">
|
|
<span id="detailStatusBadge" class="px-2 py-1 rounded text-xs font-bold bg-gray-200 text-gray-700 uppercase mb-2 inline-block">Estado</span>
|
|
<h2 class="text-xl font-bold text-gray-900" id="detailTitle">Servicio #ID</h2>
|
|
<p class="text-sm text-gray-500" id="detailClient">Cliente</p>
|
|
</div>
|
|
|
|
<div class="bg-gray-50 p-4 rounded-lg border border-gray-200 mb-8">
|
|
<label class="block text-xs font-bold text-gray-500 uppercase mb-2">Cambiar Estado</label>
|
|
<div class="flex gap-2">
|
|
<select id="newStatusSelect" class="flex-1 border rounded px-2 text-sm outline-none focus:border-blue-500 bg-white"></select>
|
|
<button onclick="updateStatus()" class="bg-slate-800 text-white px-4 py-2 rounded text-sm hover:bg-slate-700 font-medium">Actualizar</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<h3 class="font-bold text-gray-800 mb-4 flex items-center gap-2"><i data-lucide="history"></i> Mapa de Cambios</h3>
|
|
<div class="relative border-l-2 border-gray-200 ml-3 space-y-8 pb-8" id="statusTimeline">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="toast" class="fixed bottom-5 right-5 bg-slate-800 text-white px-6 py-3 rounded-lg shadow-2xl transform translate-y-20 opacity-0 transition-all duration-300 z-50 flex items-center gap-3"><span id="toastMsg">Msg</span></div>
|
|
|
|
<script src="js/layout.js"></script>
|
|
<script>
|
|
let allStatuses = [];
|
|
let currentServiceId = null;
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const token = localStorage.getItem("token");
|
|
if (!token) window.location.href = "index.html";
|
|
fetchStatuses();
|
|
fetchServices();
|
|
});
|
|
|
|
function toggleView(view) {
|
|
document.getElementById('servicesListView').classList.add('hidden');
|
|
document.getElementById('createServiceView').classList.add('hidden');
|
|
if(view === 'list') {
|
|
document.getElementById('servicesListView').classList.remove('hidden');
|
|
fetchServices();
|
|
} else {
|
|
document.getElementById('createServiceView').classList.remove('hidden');
|
|
}
|
|
}
|
|
|
|
async function fetchStatuses() {
|
|
try {
|
|
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
if(data.ok) allStatuses = data.statuses;
|
|
} catch(e) {}
|
|
}
|
|
|
|
async function fetchServices() {
|
|
try {
|
|
const res = await fetch(`${API_URL}/services`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
const tbody = document.getElementById('servicesTableBody');
|
|
tbody.innerHTML = "";
|
|
|
|
if(data.services.length === 0) { tbody.innerHTML = `<tr><td colspan="5" class="p-6 text-center text-gray-400">No hay servicios registrados.</td></tr>`; return; }
|
|
|
|
data.services.forEach(s => {
|
|
const color = s.status_color || 'gray';
|
|
tbody.innerHTML += `
|
|
<tr class="hover:bg-gray-50 cursor-pointer transition" onclick="openDetail(${s.id}, '${s.contact_name}', '${s.title}', '${s.status_name}', '${color}')">
|
|
<td class="p-4 text-gray-500">${new Date(s.created_at).toLocaleDateString()}</td>
|
|
<td class="p-4 font-medium text-gray-900">${s.contact_name}<br><span class="text-xs text-gray-400 font-normal">${s.address}</span></td>
|
|
<td class="p-4 text-gray-600">${s.title}</td>
|
|
<td class="p-4"><span class="px-2 py-1 rounded text-xs font-bold text-white bg-${color}-500 shadow-sm">${s.status_name || 'Nuevo'}</span></td>
|
|
<td class="p-4 text-right"><i data-lucide="chevron-right" class="w-5 h-5 text-gray-300"></i></td>
|
|
</tr>
|
|
`;
|
|
});
|
|
lucide.createIcons();
|
|
} catch (e) { console.error(e); }
|
|
}
|
|
|
|
async function openDetail(id, client, title, statusName, statusColor) {
|
|
currentServiceId = id;
|
|
document.getElementById('serviceDetailPanel').classList.remove('hidden');
|
|
document.getElementById('detailTitle').innerText = title;
|
|
document.getElementById('detailClient').innerText = client;
|
|
const badge = document.getElementById('detailStatusBadge');
|
|
badge.innerText = statusName;
|
|
badge.className = `px-2 py-1 rounded text-xs font-bold text-white mb-2 inline-block bg-${statusColor}-500`;
|
|
|
|
// Llenar select
|
|
const sel = document.getElementById('newStatusSelect');
|
|
sel.innerHTML = "";
|
|
allStatuses.forEach(s => {
|
|
sel.innerHTML += `<option value="${s.id}">${s.name}</option>`;
|
|
});
|
|
|
|
// Cargar Mapa de Estados
|
|
loadTimeline(id);
|
|
}
|
|
|
|
async function loadTimeline(id) {
|
|
const timeline = document.getElementById('statusTimeline');
|
|
timeline.innerHTML = '<p class="text-xs text-gray-400 ml-4">Cargando historial...</p>';
|
|
|
|
const res = await fetch(`${API_URL}/services/${id}/logs`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
|
|
timeline.innerHTML = "";
|
|
data.logs.forEach(log => {
|
|
const color = log.new_color || 'gray';
|
|
timeline.innerHTML += `
|
|
<div class="mb-6 ml-6 relative group">
|
|
<span class="absolute -left-9 flex items-center justify-center w-6 h-6 bg-${color}-100 rounded-full ring-4 ring-white group-hover:bg-${color}-200 transition">
|
|
<div class="w-2 h-2 bg-${color}-600 rounded-full"></div>
|
|
</span>
|
|
<h3 class="flex items-center mb-1 text-sm font-bold text-gray-800">${log.new_status}</h3>
|
|
<time class="block mb-2 text-xs font-medium text-gray-400 uppercase tracking-wide">${new Date(log.created_at).toLocaleString()}</time>
|
|
<div class="bg-gray-50 p-3 rounded-lg border border-gray-100 text-sm text-gray-600">
|
|
<p>${log.comment || 'Cambio de estado'}</p>
|
|
<p class="text-xs text-gray-400 mt-2 text-right italic">Por: ${log.user_name || 'Sistema'}</p>
|
|
</div>
|
|
</div>
|
|
`;
|
|
});
|
|
}
|
|
|
|
async function updateStatus() {
|
|
const statusId = document.getElementById('newStatusSelect').value;
|
|
const comment = prompt("Añade un comentario sobre este cambio (opcional):");
|
|
|
|
try {
|
|
await fetch(`${API_URL}/services/${currentServiceId}/status`, {
|
|
method: 'PUT',
|
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify({ status_id: statusId, comment: comment })
|
|
});
|
|
showToast("Estado actualizado");
|
|
loadTimeline(currentServiceId);
|
|
fetchServices(); // Refrescar lista de fondo
|
|
} catch(e) { showToast("Error", true); }
|
|
}
|
|
|
|
function closeDetailPanel() { document.getElementById('serviceDetailPanel').classList.add('hidden'); }
|
|
|
|
// --- TU LÓGICA DE CREAR SERVICIO (RESUMIDA) ---
|
|
async function createService(e) {
|
|
e.preventDefault();
|
|
// ... (Aquí iría la lógica completa de tu formulario anterior para recoger los datos) ...
|
|
// Simulación simple para este ejemplo:
|
|
const data = {
|
|
phone: document.getElementById('sPhone').value,
|
|
name: document.getElementById('sName').value,
|
|
address: document.getElementById('sAddress').value,
|
|
email: document.getElementById('sEmail').value,
|
|
description: document.getElementById('sDesc').value
|
|
};
|
|
|
|
try {
|
|
const res = await fetch(`${API_URL}/services`, {
|
|
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify(data)
|
|
});
|
|
if(res.ok) { showToast("Creado"); toggleView('list'); }
|
|
} catch(e) { showToast("Error", true); }
|
|
}
|
|
|
|
// --- HELPERS (Buscador clientes, etc) ---
|
|
// (Pega aquí searchClientByPhone, loadCompanies, etc. del código anterior)
|
|
|
|
function showToast(msg, isError = false) {
|
|
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
|
t.className = `fixed bottom-5 right-5 px-6 py-3 rounded-lg shadow-2xl transition-all duration-300 z-50 flex items-center gap-3 ${isError ? 'bg-red-600' : 'bg-slate-800'} text-white`;
|
|
m.innerText = msg; t.classList.remove('translate-y-20', 'opacity-0');
|
|
setTimeout(() => t.classList.add('translate-y-20', 'opacity-0'), 3000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |