Actualizar configuracion.html
This commit is contained in:
@@ -31,38 +31,29 @@
|
|||||||
<button onclick="showTab('zones')" id="tab-zones" class="tab-btn px-6 py-3 text-sm font-bold text-blue-600 border-b-2 border-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
<button onclick="showTab('zones')" id="tab-zones" class="tab-btn px-6 py-3 text-sm font-bold text-blue-600 border-b-2 border-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
||||||
<i data-lucide="map" class="inline w-4 h-4 mr-1"></i> Zonas de Actuación
|
<i data-lucide="map" class="inline w-4 h-4 mr-1"></i> Zonas de Actuación
|
||||||
</button>
|
</button>
|
||||||
<button onclick="showTab('templates')" id="tab-templates" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
|
||||||
<i data-lucide="file-text" class="inline w-4 h-4 mr-1"></i> Plantillas
|
|
||||||
</button>
|
|
||||||
<button onclick="showTab('whatsapp')" id="tab-whatsapp" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
|
||||||
<i data-lucide="message-circle" class="inline w-4 h-4 mr-1"></i> WhatsApp
|
|
||||||
</button>
|
|
||||||
<button onclick="showTab('providers')" id="tab-providers" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
|
||||||
<i data-lucide="truck" class="inline w-4 h-4 mr-1"></i> Proveedores
|
|
||||||
</button>
|
|
||||||
<button onclick="showTab('portal')" id="tab-portal" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
|
||||||
<i data-lucide="globe" class="inline w-4 h-4 mr-1"></i> Portal Cliente
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-1 overflow-hidden relative">
|
<div class="flex-1 overflow-hidden relative">
|
||||||
|
|
||||||
<div id="view-zones" class="tab-content h-full flex flex-col">
|
<div id="view-zones" class="tab-content h-full flex flex-col">
|
||||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 h-full">
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 h-full">
|
||||||
|
|
||||||
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden">
|
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden">
|
||||||
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700">1. Selecciona Provincia</div>
|
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700">1. Selecciona Provincia</div>
|
||||||
<div class="p-2 border-b"><input type="text" id="searchProv" placeholder="Filtrar..." class="w-full text-xs p-2 border rounded" onkeyup="filterProvinces()"></div>
|
<div class="p-2 border-b"><input type="text" id="searchProv" placeholder="Filtrar..." class="w-full text-xs p-2 border rounded" onkeyup="filterProvinces()"></div>
|
||||||
<div id="listProvinces" class="flex-1 overflow-y-auto scroller p-2 space-y-1"></div>
|
<div id="listProvinces" class="flex-1 overflow-y-auto scroller p-2 space-y-1"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden opacity-50 pointer-events-none transition-opacity" id="colZones">
|
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden opacity-50 pointer-events-none transition-opacity" id="colZones">
|
||||||
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700 flex justify-between items-center">
|
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700 flex justify-between items-center">
|
||||||
<span>2. Crear/Elegir Zona</span>
|
<span>2. Zonas Definidas</span>
|
||||||
<button onclick="addZonePrompt()" class="text-blue-600 hover:bg-blue-100 p-1 rounded"><i data-lucide="plus" class="w-4 h-4"></i></button>
|
<button onclick="openZoneModal()" class="text-blue-600 hover:bg-blue-100 p-1 rounded font-bold flex items-center gap-1 text-xs"><i data-lucide="plus" class="w-3 h-3"></i> Nueva</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="listZones" class="flex-1 overflow-y-auto scroller p-2 space-y-1 text-sm">
|
<div id="listZones" class="flex-1 overflow-y-auto scroller p-2 space-y-1 text-sm">
|
||||||
<p class="text-center text-gray-400 mt-10">Selecciona una provincia</p>
|
<p class="text-center text-gray-400 mt-10">Selecciona una provincia</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden opacity-50 pointer-events-none transition-opacity" id="colOperators">
|
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden opacity-50 pointer-events-none transition-opacity" id="colOperators">
|
||||||
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700 flex justify-between items-center">
|
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700 flex justify-between items-center">
|
||||||
<span>3. Asignar Operarios</span>
|
<span>3. Asignar Operarios</span>
|
||||||
@@ -75,80 +66,46 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="view-templates" class="tab-content hidden h-full">
|
|
||||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
|
||||||
<i data-lucide="file-text" class="w-12 h-12 text-gray-300 mx-auto mb-4"></i>
|
|
||||||
<h3 class="text-lg font-bold text-gray-700">Gestor de Plantillas</h3>
|
|
||||||
<p class="text-gray-500 mb-4">Configura aquí los textos predefinidos para partes de trabajo y correos.</p>
|
|
||||||
<button class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm">Nueva Plantilla</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="view-whatsapp" class="tab-content hidden h-full">
|
|
||||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
|
||||||
<i data-lucide="message-circle" class="w-12 h-12 text-green-500 mx-auto mb-4"></i>
|
|
||||||
<h3 class="text-lg font-bold text-gray-700">Conexión WhatsApp</h3>
|
|
||||||
<p class="text-gray-500 mb-4">Estado de la conexión con Evolution API.</p>
|
|
||||||
<span class="bg-green-100 text-green-700 px-3 py-1 rounded-full text-xs font-bold">Conectado</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="view-providers" class="tab-content hidden h-full">
|
|
||||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
|
||||||
<i data-lucide="truck" class="w-12 h-12 text-gray-300 mx-auto mb-4"></i>
|
|
||||||
<h3 class="text-lg font-bold text-gray-700">Proveedores</h3>
|
|
||||||
<p class="text-gray-500 mb-4">Gestión de proveedores de material y servicios externos.</p>
|
|
||||||
<button class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm">Añadir Proveedor</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="view-portal" class="tab-content hidden h-full">
|
|
||||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
|
||||||
<i data-lucide="globe" class="w-12 h-12 text-blue-300 mx-auto mb-4"></i>
|
|
||||||
<h3 class="text-lg font-bold text-gray-700">Portal del Cliente</h3>
|
|
||||||
<p class="text-gray-500 mb-4">Configura qué pueden ver tus clientes al acceder con su enlace.</p>
|
|
||||||
<div class="inline-flex items-center gap-2 border p-2 rounded bg-gray-50">
|
|
||||||
<input type="checkbox" checked class="text-blue-600"> <span>Permitir ver fotos</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="zoneModal" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50 flex items-center justify-center backdrop-blur-sm">
|
||||||
|
<div class="bg-white rounded-xl shadow-2xl w-full max-w-lg p-6 animate-slide-in flex flex-col max-h-[80vh]">
|
||||||
|
<h3 class="text-xl font-bold mb-4">Nueva Zona / Ruta</h3>
|
||||||
|
<input type="text" id="newZoneName" placeholder="Nombre de la zona (Ej: Ruta Bahía)" class="w-full border p-2 rounded mb-4">
|
||||||
|
|
||||||
|
<p class="text-xs font-bold text-gray-500 mb-2">Selecciona las Poblaciones incluidas:</p>
|
||||||
|
<div id="townsList" class="border p-3 rounded overflow-y-auto flex-1 grid grid-cols-2 gap-2 text-sm bg-gray-50">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-2 mt-4 pt-4 border-t">
|
||||||
|
<button onclick="document.getElementById('zoneModal').classList.add('hidden')" class="px-4 py-2 text-gray-500 hover:text-gray-700">Cancelar</button>
|
||||||
|
<button onclick="createZone()" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">Crear Zona</button>
|
||||||
|
</div>
|
||||||
|
</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>
|
<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 src="js/layout.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// VARIABLES GLOBALES (Solo para Zonas por ahora)
|
|
||||||
let provinces = [], currentProvId = null, currentZoneId = null;
|
let provinces = [], currentProvId = null, currentZoneId = null;
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
||||||
loadProvinces(); // Carga inicial para la pestaña de zonas
|
showTab('zones');
|
||||||
|
loadProvinces();
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- SISTEMA DE PESTAÑAS ---
|
|
||||||
function showTab(tabId) {
|
function showTab(tabId) {
|
||||||
// Ocultar todo
|
|
||||||
document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
|
document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
|
||||||
// Mostrar seleccionado
|
|
||||||
document.getElementById(`view-${tabId}`).classList.remove('hidden');
|
document.getElementById(`view-${tabId}`).classList.remove('hidden');
|
||||||
|
|
||||||
// Estilos botones
|
|
||||||
document.querySelectorAll('.tab-btn').forEach(el => {
|
|
||||||
el.classList.remove('text-blue-600', 'border-b-2', 'border-blue-600', 'font-bold');
|
|
||||||
el.classList.add('text-gray-500', 'font-medium');
|
|
||||||
});
|
|
||||||
const btn = document.getElementById(`tab-${tabId}`);
|
|
||||||
btn.classList.add('text-blue-600', 'border-b-2', 'border-blue-600', 'font-bold');
|
|
||||||
btn.classList.remove('text-gray-500', 'font-medium');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================
|
// ============================
|
||||||
// LÓGICA DE ZONAS (Completa)
|
// LÓGICA DE ZONAS
|
||||||
// ============================
|
// ============================
|
||||||
async function loadProvinces() {
|
async function loadProvinces() {
|
||||||
try {
|
try {
|
||||||
@@ -193,31 +150,71 @@
|
|||||||
const list = document.getElementById('listZones');
|
const list = document.getElementById('listZones');
|
||||||
list.innerHTML = "";
|
list.innerHTML = "";
|
||||||
|
|
||||||
|
if(data.zones.length === 0) list.innerHTML = '<p class="text-center text-xs text-gray-400 p-4">No hay zonas. Crea una.</p>';
|
||||||
|
|
||||||
data.zones.forEach(z => {
|
data.zones.forEach(z => {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.className = "p-3 border border-gray-100 rounded hover:border-blue-300 cursor-pointer bg-white mb-2 flex justify-between items-center zone-item";
|
div.className = "p-3 border border-gray-100 rounded hover:border-blue-300 cursor-pointer bg-white mb-2 zone-item";
|
||||||
div.innerHTML = `<span class="font-medium text-gray-700">${z.name}</span>`;
|
|
||||||
|
|
||||||
if (z.owner_id) {
|
// Mostrar pueblos agrupados (si existen)
|
||||||
const btn = document.createElement('button');
|
let townsText = "Sin poblaciones";
|
||||||
btn.innerHTML = '<i data-lucide="trash" class="w-3 h-3"></i>';
|
if(z.towns_names && z.towns_names.length > 0) {
|
||||||
btn.className = "text-red-300 hover:text-red-500";
|
townsText = z.towns_names.join(", ");
|
||||||
btn.onclick = (e) => { e.stopPropagation(); deleteZone(z.id); };
|
|
||||||
div.appendChild(btn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.innerHTML = `
|
||||||
|
<div class="flex justify-between items-start">
|
||||||
|
<span class="font-bold text-gray-700 block">${z.name}</span>
|
||||||
|
${z.owner_id ? `<button onclick="event.stopPropagation(); deleteZone(${z.id})" class="text-red-300 hover:text-red-500"><i data-lucide="trash" class="w-3 h-3"></i></button>` : ''}
|
||||||
|
</div>
|
||||||
|
<p class="text-xs text-gray-400 mt-1 truncate">${townsText}</p>
|
||||||
|
`;
|
||||||
|
|
||||||
div.onclick = () => selectZone(z.id, div);
|
div.onclick = () => selectZone(z.id, div);
|
||||||
list.appendChild(div);
|
list.appendChild(div);
|
||||||
});
|
});
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addZonePrompt() {
|
// --- CREACIÓN DE ZONAS (NUEVO) ---
|
||||||
const name = prompt("Nombre de la nueva zona (ej: Zona Norte):");
|
async function openZoneModal() {
|
||||||
if(!name) return;
|
if(!currentProvId) return;
|
||||||
await fetch(`${API_URL}/zones`, {
|
document.getElementById('newZoneName').value = "";
|
||||||
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
||||||
body: JSON.stringify({ province_id: currentProvId, name })
|
// Cargar pueblos de la provincia
|
||||||
|
const res = await fetch(`${API_URL}/provinces/${currentProvId}/towns`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
|
const data = await res.json();
|
||||||
|
const list = document.getElementById('townsList');
|
||||||
|
list.innerHTML = "";
|
||||||
|
|
||||||
|
if(data.towns.length === 0) list.innerHTML = '<p class="col-span-2 text-center text-gray-400">No hay poblaciones cargadas.</p>';
|
||||||
|
|
||||||
|
data.towns.forEach(t => {
|
||||||
|
list.innerHTML += `
|
||||||
|
<label class="flex items-center gap-2 p-1 hover:bg-blue-50 rounded">
|
||||||
|
<input type="checkbox" value="${t.id}" class="town-check text-blue-600 rounded">
|
||||||
|
<span class="truncate">${t.name}</span>
|
||||||
|
</label>
|
||||||
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('zoneModal').classList.remove('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createZone() {
|
||||||
|
const name = document.getElementById('newZoneName').value;
|
||||||
|
const checks = document.querySelectorAll('.town-check:checked');
|
||||||
|
const townIds = Array.from(checks).map(c => c.value);
|
||||||
|
|
||||||
|
if(!name) { alert("Pon un nombre a la zona"); return; }
|
||||||
|
|
||||||
|
await fetch(`${API_URL}/zones`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
|
body: JSON.stringify({ province_id: currentProvId, name, town_ids: townIds })
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('zoneModal').classList.add('hidden');
|
||||||
loadZones(currentProvId);
|
loadZones(currentProvId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user