661 lines
41 KiB
HTML
661 lines
41 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Validación - IntegraReparaPro</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; } }
|
|
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
|
.no-scrollbar::-webkit-scrollbar { display: none; }
|
|
.service-card { cursor: pointer; transition: all 0.2s ease; position: relative; }
|
|
.service-card:hover:not(.archived):not(.locked) { transform: translateY(-2px); border-color: #3b82f6; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }
|
|
.archived { opacity: 0.7; filter: grayscale(100%); }
|
|
.locked { cursor: not-allowed; }
|
|
|
|
/* Animación suave para el icono de esperando */
|
|
.pulse-slow { animation: pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
|
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
|
|
|
|
/* Animación de temblor para las tarjetas bloqueadas */
|
|
.shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }
|
|
@keyframes shake {
|
|
10%, 90% { transform: translate3d(-1px, 0, 0); }
|
|
20%, 80% { transform: translate3d(2px, 0, 0); }
|
|
30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
|
|
40%, 60% { transform: translate3d(4px, 0, 0); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden text-left">
|
|
|
|
<div class="flex h-screen overflow-hidden text-left">
|
|
<div id="sidebar-container" class="h-full shrink-0"></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="automationView" class="fade-in max-w-6xl mx-auto">
|
|
<div class="flex justify-between items-center mb-8">
|
|
<div>
|
|
<h2 class="text-2xl font-black text-slate-800 flex items-center gap-3">
|
|
<span class="bg-blue-600 p-2.5 rounded-xl text-white shadow-lg"><i data-lucide="building-2"></i></span>
|
|
Buzón de Proveedores
|
|
</h2>
|
|
<p class="text-sm text-slate-500 mt-1 font-medium">Filtra por proveedor, compañía o cualquier dato del asegurado.</p>
|
|
</div>
|
|
<button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 text-slate-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95 shadow-sm">
|
|
<i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar
|
|
</button>
|
|
</div>
|
|
|
|
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm mb-4 flex flex-wrap gap-4 items-center">
|
|
<div class="flex-1 min-w-[280px] relative text-left">
|
|
<i data-lucide="search" class="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>
|
|
<input type="text" id="searchBox" oninput="renderFilteredInbox()" placeholder="Buscar por Nombre, REF, Dirección, Teléfono..." class="w-full pl-11 pr-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 outline-none transition-all">
|
|
</div>
|
|
<div class="flex gap-2">
|
|
<select id="filterStatus" onchange="renderFilteredInbox()" class="bg-slate-50 border border-slate-200 text-[10px] font-black px-4 py-2.5 rounded-xl outline-none focus:ring-2 focus:ring-blue-500 uppercase tracking-widest">
|
|
<option value="ALL">TODOS LOS ESTADOS</option>
|
|
<option value="pending">SOLO ACTIVOS</option>
|
|
<option value="archived">SOLO ARCHIVADOS</option>
|
|
</select>
|
|
<select id="filterProvider" onchange="renderFilteredInbox()" class="bg-slate-50 border border-slate-200 text-[10px] font-black px-4 py-2.5 rounded-xl outline-none focus:ring-2 focus:ring-blue-500 uppercase tracking-widest">
|
|
<option value="ALL">PROVEEDORES</option>
|
|
<option value="homeserve">HOME (HOMESERVE)</option>
|
|
<option value="multiasistencia">MULTI (MULTIASISTENCIA)</option>
|
|
</select>
|
|
<select id="filterCompany" onchange="renderFilteredInbox()" class="bg-slate-50 border border-slate-200 text-[10px] font-black px-4 py-2.5 rounded-xl outline-none focus:ring-2 focus:ring-blue-500 uppercase tracking-widest max-w-[200px]">
|
|
<option value="ALL">COMPAÑÍAS</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex gap-4 mb-6 text-left">
|
|
<div class="bg-emerald-50 border border-emerald-100 px-4 py-2 rounded-xl flex items-center gap-2">
|
|
<span class="text-[10px] font-black text-emerald-600 uppercase tracking-widest">Activos:</span>
|
|
<span id="countActive" class="text-sm font-black text-emerald-700">0</span>
|
|
</div>
|
|
<div class="bg-slate-100 border border-slate-200 px-4 py-2 rounded-xl flex items-center gap-2 text-left">
|
|
<span class="text-[10px] font-black text-slate-500 uppercase tracking-widest">Archivados:</span>
|
|
<span id="countArchived" class="text-sm font-black text-slate-700">0</span>
|
|
</div>
|
|
<div class="bg-blue-50 border border-blue-100 px-4 py-2 rounded-xl flex items-center gap-2 text-left">
|
|
<span class="text-[10px] font-black text-blue-600 uppercase tracking-widest">Total:</span>
|
|
<span id="countTotal" class="text-sm font-black text-blue-700">0</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="inboxContainer" class="space-y-4 text-left"></div>
|
|
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="importModal" class="fixed inset-0 bg-slate-900/75 hidden z-[100] flex items-center justify-center backdrop-blur-md p-2 text-left">
|
|
<div class="bg-white rounded-[2.5rem] shadow-2xl w-full max-w-4xl flex flex-col max-h-[95vh] overflow-hidden border border-slate-200 fade-in text-left">
|
|
<div class="px-8 pt-6 pb-4 flex justify-between items-center border-b border-slate-50 text-left">
|
|
<div class="flex items-center gap-4 text-left">
|
|
<div id="modalCompanyLogo" class="w-12 h-12 rounded-xl bg-slate-50 border border-slate-100 p-2 flex items-center justify-center shadow-sm overflow-hidden"></div>
|
|
<div>
|
|
<div class="flex items-center gap-2 text-left">
|
|
<h3 class="text-xl font-black text-slate-800 tracking-tight">Validación de Expediente</h3>
|
|
<div id="modalStatusBadge"></div>
|
|
</div>
|
|
<div class="flex items-center gap-2 mt-0.5 text-left">
|
|
<span id="displayRef" class="text-[10px] bg-slate-100 text-slate-500 px-2 py-0.5 rounded-lg font-bold border border-slate-200 uppercase">REF: --</span>
|
|
<span id="displayCompany" class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded-lg font-bold border border-blue-100 uppercase truncate max-w-[250px]">--</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex items-center gap-4 text-left">
|
|
<div class="flex flex-col items-end mr-4 text-left">
|
|
<span class="text-[9px] font-black text-slate-400 uppercase mb-1">Prioridad</span>
|
|
<select id="impUrgent" class="bg-slate-50 border border-slate-200 text-xs font-black px-3 py-1.5 rounded-xl outline-none focus:border-red-400 cursor-pointer">
|
|
<option value="false">BAJA (Normal)</option>
|
|
<option value="true">🚨 MUY URGENTE</option>
|
|
</select>
|
|
</div>
|
|
<button onclick="closeModal()" class="bg-slate-50 p-2 rounded-full hover:bg-red-50 hover:text-red-500 transition-all text-left">
|
|
<i data-lucide="x" class="w-5 h-5"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="importForm" onsubmit="handleFinalImport(event)" class="px-8 py-6 space-y-5 overflow-y-auto no-scrollbar text-left">
|
|
<input type="hidden" id="impScrapedId">
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div class="bg-slate-50/50 p-3 rounded-2xl border border-slate-100 flex items-center gap-3 text-left">
|
|
<div class="bg-white p-2 rounded-xl shadow-sm text-slate-400 text-left"><i data-lucide="user" class="w-4 h-4"></i></div>
|
|
<div class="flex flex-col min-w-0 w-full text-left">
|
|
<span class="text-[9px] font-black text-slate-400 uppercase mb-0.5 text-left">Asegurado</span>
|
|
<input type="text" id="impName" class="bg-transparent border-none p-0 text-sm font-bold text-slate-700 outline-none w-full text-left">
|
|
</div>
|
|
</div>
|
|
<div class="bg-slate-50/50 p-3 rounded-2xl border border-slate-100 flex items-center gap-3 text-left">
|
|
<div class="bg-white p-2 rounded-xl shadow-sm text-emerald-500 text-left"><i data-lucide="phone" class="w-4 h-4 text-left"></i></div>
|
|
<div class="flex flex-col min-w-0 w-full text-left">
|
|
<span class="text-[9px] font-black text-slate-400 uppercase mb-0.5 text-left">Teléfono</span>
|
|
<input type="text" id="impPhone" class="bg-transparent border-none p-0 text-sm font-black text-emerald-600 outline-none w-full text-left">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="grid grid-cols-1 md:grid-cols-5 gap-3 text-left">
|
|
<div class="md:col-span-4 space-y-1 text-left">
|
|
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 flex items-center gap-1 text-left"><i data-lucide="map-pin" class="w-3 h-3 text-left"></i> Dirección</label>
|
|
<input type="text" id="impAddress" required class="w-full border-2 border-slate-100 bg-white px-4 py-2.5 rounded-2xl text-sm font-medium outline-none focus:border-blue-500 shadow-sm text-left">
|
|
</div>
|
|
<div class="space-y-1 text-center">
|
|
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest block text-left ml-2">C.P.</label>
|
|
<input type="text" id="impCP" required class="w-full border-2 border-slate-100 bg-white py-2.5 rounded-2xl text-sm font-black text-center outline-none focus:border-blue-500 shadow-sm">
|
|
</div>
|
|
</div>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 p-5 rounded-[1.8rem] border-2 border-blue-50 bg-blue-50/30 text-left">
|
|
<div class="space-y-1 text-left">
|
|
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 text-left">Gremio Especialista *</label>
|
|
<select id="impGuild" required onchange="loadOpsForGuild(this.value)" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-blue-400 text-left">
|
|
<option value="">-- Seleccionar Gremio --</option>
|
|
</select>
|
|
</div>
|
|
<div class="space-y-1 text-left">
|
|
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2 text-left">Asignación Operario</label>
|
|
<select id="impOperator" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-blue-400 text-left">
|
|
<option value="">-- Automática --</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="space-y-3 text-left">
|
|
<div class="space-y-1 text-left">
|
|
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2 text-left">Avería Detectada</label>
|
|
<textarea id="impDesc" rows="2" class="w-full border border-slate-200 bg-white px-4 py-2 rounded-2xl text-sm font-medium text-slate-600 outline-none focus:border-blue-400 resize-none shadow-sm text-left"></textarea>
|
|
</div>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-left">
|
|
<div class="text-left">
|
|
<label class="text-[9px] font-black text-amber-600 uppercase ml-2 mb-1 block text-left">Notas Oficina</label>
|
|
<textarea id="impNotesInt" rows="1" class="w-full border border-amber-100 bg-amber-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white text-left"></textarea>
|
|
</div>
|
|
<div class="text-left">
|
|
<label class="text-[9px] font-black text-blue-500 uppercase ml-2 mb-1 block text-left">Instrucciones Operario</label>
|
|
<textarea id="impNotesExt" rows="1" class="w-full border border-blue-100 bg-blue-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white text-left"></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap items-center gap-3 pt-4 border-t text-left">
|
|
<button type="button" onclick="saveDraftChanges(event)" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-black px-4 py-4 rounded-[1.5rem] transition-all flex items-center justify-center gap-2 active:scale-95 text-[10px] uppercase tracking-widest">
|
|
<i data-lucide="save" class="w-4 h-4"></i> <span>Guardar</span>
|
|
</button>
|
|
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-black px-6 py-4 rounded-[1.5rem] shadow-lg transition-all flex items-center justify-center gap-2 active:scale-95 text-[10px] uppercase tracking-widest">
|
|
<i data-lucide="send" class="w-4 h-4"></i> <span>Traspaso Manual</span>
|
|
</button>
|
|
<button type="button" onclick="sendToQueue()" class="flex-1 bg-emerald-600 hover:bg-emerald-700 text-white font-black py-4 rounded-[1.5rem] shadow-xl shadow-emerald-200 transition-all flex items-center justify-center gap-3 active:scale-95 text-xs uppercase tracking-[0.15em]">
|
|
<i data-lucide="zap" class="w-5 h-5"></i> <span>MANDAR A LA COLA (AUTO)</span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="toast" class="fixed bottom-8 right-8 bg-slate-900 text-white px-8 py-4 rounded-2xl shadow-2xl hidden z-[200] border border-white/10 text-left"><span id="toastMsg" class="font-bold text-sm text-left"></span></div>
|
|
|
|
<script src="js/layout.js"></script>
|
|
<script>
|
|
let allGuilds = [];
|
|
let scrapedData = [];
|
|
let pollingInterval = null;
|
|
|
|
const companyLogos = {
|
|
'REPSOL': 'https://cdn.sanity.io/images/rn4tswnp/production/1bc5be0207b732bd18dd0fc38e063d5701267068-1000x832.png?rect=6,0,994,832&h=320&auto=format&dpr=2',
|
|
'MUTUA': 'https://www.google.com/s2/favicons?domain=mutua.es&sz=128',
|
|
'ALLIANZ': 'https://www.google.com/s2/favicons?domain=allianz.es&sz=128',
|
|
'CASER': 'https://www.google.com/s2/favicons?domain=caser.es&sz=128',
|
|
'SEGURCAIXA': 'https://unijepol.eu/wp-content/uploads/2021/01/Segur-Caixa-Adeslas.jpg',
|
|
'LA CAIXA': 'https://www.google.com/s2/favicons?domain=segurcaixaadeslas.es&sz=128',
|
|
'AXA': 'https://www.google.com/s2/favicons?domain=axa.es&sz=128',
|
|
'LDA': 'https://www.google.com/s2/favicons?domain=lineadirecta.com&sz=128',
|
|
'HOMESERVE SINIESTROS': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTeO7TsnpOYqLGgJm0puUyUMLi657od4mGWKQ&s',
|
|
'HOMESERVE REPARACIONES': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTeO7TsnpOYqLGgJm0puUyUMLi657od4mGWKQ&s',
|
|
'RGA': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRemEVB4iYmTGoZL0nrBQJkZ1vNlDNtKfGEug&s',
|
|
'RURAL GRUPO': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRemEVB4iYmTGoZL0nrBQJkZ1vNlDNtKfGEug&s',
|
|
'SANTANDER': 'https://www.google.com/s2/favicons?domain=santander.com&sz=128',
|
|
'BANSABADELL': 'https://play-lh.googleusercontent.com/-XAFeiDTzqTwRMfT6ggZO3raXI1VPmmvc5JDm2BeGsUA1MUF7X4Y-eeDPMp8BsEgBw=w240-h480-rw',
|
|
'GENERALI': 'https://cdn.worldvectorlogo.com/logos/generali-logo.svg',
|
|
'DEFAULT': 'https://cdn-icons-png.flaticon.com/512/2875/2875438.png'
|
|
};
|
|
|
|
function getLogoUrl(companyName) {
|
|
if (!companyName) return companyLogos['DEFAULT'];
|
|
const name = companyName.toString().toUpperCase();
|
|
const keyFound = Object.keys(companyLogos).find(key => name.includes(key));
|
|
return keyFound ? companyLogos[keyFound] : companyLogos['DEFAULT'];
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", async () => {
|
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
|
setTimeout(async () => {
|
|
await loadGuilds();
|
|
await loadInbox();
|
|
}, 200);
|
|
startPolling();
|
|
});
|
|
|
|
function startPolling() {
|
|
if (pollingInterval) clearInterval(pollingInterval);
|
|
pollingInterval = setInterval(async () => {
|
|
const modal = document.getElementById('importModal');
|
|
if (modal.classList.contains('hidden')) {
|
|
await loadInbox();
|
|
}
|
|
}, 30000);
|
|
}
|
|
|
|
async function loadGuilds() {
|
|
try {
|
|
const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
allGuilds = data.guilds || [];
|
|
const sel = document.getElementById('impGuild');
|
|
sel.innerHTML = '<option value="">-- Seleccionar Gremio --</option>';
|
|
allGuilds.forEach(g => sel.innerHTML += `<option value="${g.id}">${g.name}</option>`);
|
|
} catch(e) {}
|
|
}
|
|
|
|
async function loadOpsForGuild(guildId) {
|
|
const sel = document.getElementById('impOperator');
|
|
if(!guildId) { sel.innerHTML = '<option value="">-- Automática --</option>'; return; }
|
|
try {
|
|
const res = await fetch(`${API_URL}/operators?guild_id=${guildId}`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
sel.innerHTML = '<option value="">-- Automática --</option>';
|
|
data.operators.forEach(op => sel.innerHTML += `<option value="${op.id}">${op.full_name}</option>`);
|
|
} catch(e) {}
|
|
}
|
|
|
|
async function loadInbox() {
|
|
try {
|
|
const resSvc = await fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const dataSvc = await resSvc.json();
|
|
scrapedData = dataSvc.services || [];
|
|
|
|
const compSelect = document.getElementById('filterCompany');
|
|
const currentVal = compSelect.value;
|
|
const uniqueCompanies = [...new Set(scrapedData.map(s => {
|
|
const raw = s.raw_data || {};
|
|
return (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "S/C").toString().toUpperCase().trim();
|
|
}))].sort();
|
|
|
|
compSelect.innerHTML = '<option value="ALL">COMPAÑÍAS</option>';
|
|
uniqueCompanies.forEach(c => compSelect.innerHTML += `<option value="${c}">${c}</option>`);
|
|
compSelect.value = currentVal;
|
|
|
|
const active = scrapedData.filter(s => s.status === 'pending').length;
|
|
const archived = scrapedData.filter(s => s.status === 'archived').length;
|
|
document.getElementById('countActive').innerText = active;
|
|
document.getElementById('countArchived').innerText = archived;
|
|
document.getElementById('countTotal').innerText = scrapedData.length;
|
|
|
|
renderFilteredInbox();
|
|
} catch (e) { console.error("Error en loadInbox:", e); }
|
|
}
|
|
|
|
// ====== 🔥 DETECCIÓN DE URGENCIA AÑADIDA AQUÍ ======
|
|
function buildServiceCard(svc) {
|
|
const raw = svc.raw_data || {};
|
|
const isArchived = svc.status === 'archived';
|
|
|
|
const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
|
|
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
|
|
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
|
|
const fullAddr = `${addr} ${pop}`.trim();
|
|
const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || "";
|
|
const guildName = allGuilds.find(g => g.id == raw['guild_id'])?.name || null;
|
|
const opName = raw['assigned_to_name'] || null;
|
|
|
|
let badgeEstado = '';
|
|
let bgClass = 'bg-white';
|
|
let isLocked = false;
|
|
let lockedMsg = '';
|
|
|
|
const autoStatus = (svc.automation_status || '').toLowerCase();
|
|
const sysStatus = (svc.status || '').toLowerCase();
|
|
const linkedStatus = (raw['estado'] || raw['status'] || '').toLowerCase();
|
|
|
|
// DETECCIÓN DE URGENCIA (Ya sea por la BD o por el raw_data)
|
|
const isUrgent = svc.is_urgent === true || (raw['Urgente'] && raw['Urgente'].toLowerCase() === 'sí') || (raw['URGENTE'] && raw['URGENTE'].toLowerCase() === 'si');
|
|
const urgentBadge = isUrgent ? `<span class="bg-red-500 text-white px-2 py-0.5 rounded-md text-[9px] font-black uppercase shadow-sm animate-pulse ml-3">🔥 Urgente</span>` : '';
|
|
|
|
if (!isArchived) {
|
|
if (autoStatus.includes('bolsa') || autoStatus === 'in_progress' || sysStatus.includes('bolsa') || linkedStatus.includes('bolsa')) {
|
|
bgClass = 'bg-orange-50/40 border-orange-200 hover:border-orange-400';
|
|
isLocked = true;
|
|
lockedMsg = 'Este servicio está en la BOLSA buscando operario.';
|
|
badgeEstado = `
|
|
<div class="flex flex-col items-end gap-1">
|
|
<span class="bg-orange-100 text-orange-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-orange-200 shadow-sm">
|
|
<span class="w-1.5 h-1.5 bg-orange-500 rounded-full pulse-slow"></span> En Bolsa
|
|
</span>
|
|
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">Buscando operario...</span>
|
|
</div>`;
|
|
} else if (raw['assigned_to'] || (sysStatus === 'imported' && opName)) {
|
|
bgClass = 'bg-emerald-50/40 border-emerald-200 hover:border-emerald-400';
|
|
isLocked = true;
|
|
lockedMsg = 'Servicio ASIGNADO. Ve al Panel Operativo para gestionarlo.';
|
|
badgeEstado = `
|
|
<div class="flex flex-col items-end gap-1">
|
|
<span class="bg-emerald-100 text-emerald-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-emerald-200 shadow-sm">
|
|
<i data-lucide="check-circle-2" class="w-3 h-3"></i> Asignado
|
|
</span>
|
|
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">${opName || 'Operario'}</span>
|
|
</div>`;
|
|
} else if (sysStatus === 'imported') {
|
|
bgClass = 'bg-blue-50/40 border-blue-200 hover:border-blue-400';
|
|
isLocked = true;
|
|
lockedMsg = 'Este servicio ya se traspasó al Panel Operativo.';
|
|
badgeEstado = `
|
|
<div class="flex flex-col items-end gap-1">
|
|
<span class="bg-blue-100 text-blue-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-blue-200 shadow-sm">
|
|
<i data-lucide="clipboard-list" class="w-3 h-3"></i> En Panel
|
|
</span>
|
|
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">Esperando acción</span>
|
|
</div>`;
|
|
} else if (autoStatus === 'failed') {
|
|
bgClass = 'bg-red-50/40 border-red-200 hover:border-red-400';
|
|
isLocked = false;
|
|
badgeEstado = `
|
|
<div class="flex flex-col items-end gap-1">
|
|
<span class="bg-red-100 text-red-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-red-200 shadow-sm">
|
|
<i data-lucide="alert-triangle" class="w-3 h-3"></i> Fallo Bolsa
|
|
</span>
|
|
<span class="text-[8px] font-bold text-red-400">Nadie aceptó</span>
|
|
</div>`;
|
|
} else {
|
|
bgClass = isUrgent ? 'bg-red-50/20 border-red-300 hover:border-red-500 shadow-[0_0_15px_rgba(239,68,68,0.15)]' : 'bg-white border-slate-200';
|
|
badgeEstado = `
|
|
<div class="flex flex-col items-end gap-1">
|
|
<span class="bg-slate-100 text-slate-500 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-slate-200">
|
|
<i data-lucide="user-minus" class="w-3 h-3"></i> Sin Asignar
|
|
</span>
|
|
</div>`;
|
|
}
|
|
} else {
|
|
bgClass = 'bg-gray-50 border-gray-200 archived';
|
|
badgeEstado = `
|
|
<div class="flex flex-col items-end gap-1">
|
|
<span class="bg-gray-200 text-gray-500 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-gray-300">
|
|
<i data-lucide="archive" class="w-3 h-3"></i> Archivado
|
|
</span>
|
|
</div>`;
|
|
}
|
|
|
|
const card = document.createElement('div');
|
|
card.id = `card-${svc.id}`;
|
|
card.className = `service-card p-5 rounded-2xl border ${bgClass} flex items-center justify-between transition-all group fade-in ${isLocked ? 'locked' : ''}`;
|
|
|
|
card.onclick = (e) => {
|
|
if (e.target.closest('a') || e.target.closest('button')) return;
|
|
if (isArchived) {
|
|
showToast("⚠️ Este servicio está ARCHIVADO.", true);
|
|
} else if (isLocked) {
|
|
card.classList.remove('shake');
|
|
void card.offsetWidth;
|
|
card.classList.add('shake');
|
|
showToast(`🔒 ${lockedMsg}`, true);
|
|
} else {
|
|
openEditor(svc.id);
|
|
}
|
|
};
|
|
|
|
card.innerHTML = `
|
|
<div class="flex items-center gap-4 min-w-0 flex-1">
|
|
<div class="w-16 h-16 rounded-2xl flex flex-col items-center justify-center shrink-0 shadow-sm border border-slate-100 ${isArchived ? 'bg-gray-200 text-gray-400' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
|
|
<span class="text-[9px] font-black uppercase tracking-tighter">${svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'}</span>
|
|
<i data-lucide="${isArchived ? 'lock' : 'file-text'}" class="w-5 h-5 mt-0.5"></i>
|
|
</div>
|
|
<div class="w-12 h-12 rounded-xl bg-white border border-slate-100 p-2 flex items-center justify-center shrink-0 shadow-inner">
|
|
<img src="${getLogoUrl(raw['Compañía'] || raw['COMPAÑIA'])}" onerror="this.src='${companyLogos['DEFAULT']}'" class="max-w-full max-h-full object-contain">
|
|
</div>
|
|
<div class="min-w-0 flex-1">
|
|
<div class="flex items-center">
|
|
<h3 class="font-black text-slate-800 truncate uppercase text-lg leading-tight">${name}</h3>
|
|
${urgentBadge}
|
|
</div>
|
|
<p class="text-xs text-slate-400 truncate italic mt-0.5">${fullAddr}</p>
|
|
<div class="flex flex-wrap gap-2 mt-2">
|
|
<span class="text-[10px] bg-slate-100 text-slate-500 px-2 py-0.5 rounded-lg font-bold border">#${svc.service_ref}</span>
|
|
${guildName ? `<span class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded-lg font-bold border border-blue-100"><i data-lucide="hammer" class="w-2.5 h-2.5 inline mr-1"></i>${guildName}</span>` : ''}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex items-center gap-4 shrink-0 pl-4">
|
|
${badgeEstado}
|
|
</div>`;
|
|
|
|
return card;
|
|
}
|
|
|
|
function renderFilteredInbox() {
|
|
const container = document.getElementById('inboxContainer');
|
|
const search = document.getElementById('searchBox').value.toUpperCase();
|
|
const provider = document.getElementById('filterProvider').value;
|
|
const company = document.getElementById('filterCompany').value;
|
|
const status = document.getElementById('filterStatus').value;
|
|
|
|
const filtered = scrapedData.filter(svc => {
|
|
const raw = svc.raw_data || {};
|
|
const name = (raw['Nombre Cliente'] || raw['CLIENTE'] || "").toUpperCase();
|
|
const ref = (svc.service_ref || "").toUpperCase();
|
|
const addr = (raw['Dirección'] || raw['DOMICILIO'] || "").toUpperCase();
|
|
const phone = (raw['Teléfono'] || raw['TELEFONO'] || "").toUpperCase();
|
|
const comp = (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "").toUpperCase();
|
|
|
|
const matchesSearch = name.includes(search) || ref.includes(search) || addr.includes(search) || phone.includes(search);
|
|
const matchesProvider = provider === 'ALL' || svc.provider === provider;
|
|
const matchesCompany = company === 'ALL' || comp === company;
|
|
const matchesStatus = status === 'ALL' || svc.status === status;
|
|
|
|
return matchesSearch && matchesProvider && matchesCompany && matchesStatus;
|
|
});
|
|
|
|
container.innerHTML = "";
|
|
|
|
if(filtered.length === 0) {
|
|
container.innerHTML = '<div class="p-12 text-center text-slate-400 bg-white rounded-3xl border-2 border-dashed">No se encontraron expedientes con estos filtros.</div>';
|
|
return;
|
|
}
|
|
|
|
// SEPARAR ACTIVOS Y ARCHIVADOS
|
|
const activeServices = filtered.filter(svc => svc.status !== 'archived');
|
|
const archivedServices = filtered.filter(svc => svc.status === 'archived');
|
|
|
|
// 1. RENDERIZAR ACTIVOS
|
|
activeServices.forEach(svc => container.appendChild(buildServiceCard(svc)));
|
|
|
|
// 2. RENDERIZAR ARCHIVADOS AL FINAL (CON ACORDEÓN)
|
|
if (archivedServices.length > 0) {
|
|
// Si el usuario busca algo específico o filtra solo archivados, abrimos el acordeón automáticamente
|
|
const isAutoExpanded = (search.length > 0 || status === 'archived');
|
|
|
|
const divider = document.createElement('div');
|
|
divider.className = "mt-10 mb-4 border-t border-slate-200 pt-8 fade-in";
|
|
divider.innerHTML = `
|
|
<button onclick="document.getElementById('archivedCardsContainer').classList.toggle('hidden'); document.getElementById('archivedChevron').classList.toggle('rotate-180');"
|
|
class="w-full flex items-center justify-between bg-slate-200/50 hover:bg-slate-200 text-slate-500 px-6 py-4 rounded-[1.5rem] transition-all group border border-slate-200 shadow-sm">
|
|
<span class="font-black text-xs uppercase tracking-[0.15em] flex items-center gap-3">
|
|
<i data-lucide="archive" class="w-5 h-5 text-slate-400"></i> Expedientes Archivados (${archivedServices.length})
|
|
</span>
|
|
<i data-lucide="chevron-down" id="archivedChevron" class="w-5 h-5 transition-transform duration-300 ${isAutoExpanded ? 'rotate-180' : ''}"></i>
|
|
</button>
|
|
`;
|
|
container.appendChild(divider);
|
|
|
|
const archContainer = document.createElement('div');
|
|
archContainer.id = 'archivedCardsContainer';
|
|
archContainer.className = `space-y-4 fade-in ${isAutoExpanded ? '' : 'hidden'}`;
|
|
|
|
archivedServices.forEach(svc => archContainer.appendChild(buildServiceCard(svc)));
|
|
container.appendChild(archContainer);
|
|
}
|
|
|
|
lucide.createIcons();
|
|
}
|
|
|
|
async function openEditor(id) {
|
|
const svc = scrapedData.find(s => s.id === id);
|
|
if(!svc) return;
|
|
const raw = svc.raw_data;
|
|
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
|
|
|
|
document.getElementById('modalCompanyLogo').innerHTML = `<img src="${getLogoUrl(companyName)}" class="max-w-full max-h-full object-contain">`;
|
|
document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
|
|
document.getElementById('displayCompany').innerText = companyName;
|
|
document.getElementById('modalStatusBadge').innerHTML = `<span class="text-[9px] bg-emerald-50 text-emerald-600 px-3 py-1 rounded-full font-black border border-emerald-100">SERVICIO ACTIVO</span>`;
|
|
|
|
document.getElementById('impScrapedId').value = id;
|
|
document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
|
|
|
|
const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
|
|
document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
|
|
|
|
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
|
|
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
|
|
document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
|
|
document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
|
|
document.getElementById('impDesc').value = raw['Descripción'] || "";
|
|
|
|
const isUrgent = svc.is_urgent === true || raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
|
|
document.getElementById('impUrgent').value = isUrgent.toString();
|
|
document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
|
|
document.getElementById('impNotesExt').value = raw['client_notes'] || "";
|
|
|
|
const savedGuild = raw['guild_id'] || "";
|
|
document.getElementById('impGuild').value = savedGuild;
|
|
|
|
if(savedGuild) {
|
|
await loadOpsForGuild(savedGuild);
|
|
document.getElementById('impOperator').value = raw['assigned_to'] || "";
|
|
} else {
|
|
document.getElementById('impOperator').innerHTML = '<option value="">-- Automática --</option>';
|
|
}
|
|
|
|
document.getElementById('importModal').classList.remove('hidden');
|
|
lucide.createIcons();
|
|
}
|
|
|
|
function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
|
|
|
|
function getFormPayload() {
|
|
const opSelect = document.getElementById('impOperator');
|
|
const opName = opSelect.options[opSelect.selectedIndex]?.text.includes('--') ? null : opSelect.options[opSelect.selectedIndex]?.text;
|
|
|
|
return {
|
|
name: document.getElementById('impName').value,
|
|
phone: document.getElementById('impPhone').value,
|
|
address: document.getElementById('impAddress').value,
|
|
cp: document.getElementById('impCP').value,
|
|
description: document.getElementById('impDesc').value,
|
|
is_urgent: document.getElementById('impUrgent').value === 'true',
|
|
guild_id: document.getElementById('impGuild').value,
|
|
assigned_to: document.getElementById('impOperator').value,
|
|
assigned_to_name: opName,
|
|
internal_notes: document.getElementById('impNotesInt').value,
|
|
client_notes: document.getElementById('impNotesExt').value
|
|
};
|
|
}
|
|
|
|
async function saveFormToDB(id, payload) {
|
|
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
return res.ok;
|
|
}
|
|
|
|
async function saveDraftChanges(e) {
|
|
const id = document.getElementById('impScrapedId').value;
|
|
const btn = e.currentTarget;
|
|
btn.disabled = true;
|
|
try {
|
|
const ok = await saveFormToDB(id, getFormPayload());
|
|
if(ok) {
|
|
showToast("✅ Cambios guardados correctamente");
|
|
closeModal();
|
|
loadInbox();
|
|
}
|
|
else { showToast("❌ Error al guardar", true); }
|
|
} catch (err) { showToast("❌ Error de red", true); }
|
|
finally { btn.disabled = false; }
|
|
}
|
|
|
|
async function handleFinalImport(event) {
|
|
event.preventDefault();
|
|
const btn = event.submitter;
|
|
if(btn.type === 'button') return;
|
|
|
|
const id = document.getElementById('impScrapedId').value;
|
|
const payload = getFormPayload();
|
|
|
|
if (!payload.assigned_to) {
|
|
showToast("⚠️ ERROR: Selecciona un operario para hacer el traspaso manual.", true);
|
|
return;
|
|
}
|
|
|
|
btn.disabled = true;
|
|
payload.company_ref = document.getElementById('displayRef').innerText.replace('REF: ', '');
|
|
|
|
try {
|
|
await saveFormToDB(id, payload);
|
|
|
|
const res = await fetch(`${API_URL}/providers/import/${id}`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
const result = await res.json();
|
|
if(result.ok) { showToast("✅ Expediente traspasado con éxito"); closeModal(); loadInbox(); }
|
|
else { showToast("❌ Error al importar", true); }
|
|
} catch (e) { showToast("❌ Error de red", true); }
|
|
finally { btn.disabled = false; }
|
|
}
|
|
|
|
async function sendToQueue() {
|
|
const id = document.getElementById('impScrapedId').value;
|
|
const payload = getFormPayload();
|
|
|
|
if (!payload.guild_id) {
|
|
showToast("⚠️ Debes seleccionar un Gremio Especialista", true);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await saveFormToDB(id, payload);
|
|
|
|
showToast("🚀 Iniciando automatismo...");
|
|
const res = await fetch(`${API_URL}/providers/automate/${id}`, {
|
|
method: 'POST',
|
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify({ guild_id: payload.guild_id, cp: payload.cp })
|
|
});
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
showToast("✅ ¡En cola! Se ha enviado a los operarios.");
|
|
closeModal();
|
|
loadInbox();
|
|
} else { showToast("❌ " + data.error, true); }
|
|
} catch (e) { showToast("❌ Error de conexión", true); }
|
|
}
|
|
|
|
function showToast(msg, isError = false) {
|
|
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
|
t.className = `fixed bottom-8 right-8 px-8 py-4 rounded-2xl shadow-2xl z-[200] flex items-center gap-3 transition-all ${isError ? 'bg-red-600' : 'bg-slate-900'} text-white`;
|
|
m.innerText = msg; t.classList.remove('hidden');
|
|
setTimeout(() => t.classList.add('hidden'), 4000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |