Compare commits
1 Commits
feature/co
...
fix/mostra
| Author | SHA1 | Date | |
|---|---|---|---|
| 184b490d5a |
@@ -496,11 +496,12 @@
|
|||||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify({ duration: duration, date: date, time: time })
|
body: JSON.stringify({ duration: duration, date: date, time: time })
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
const data = await res.json().catch(() => ({}));
|
||||||
|
if (res.ok && data.ok !== false) {
|
||||||
showToast("Cita Aceptada");
|
showToast("Cita Aceptada");
|
||||||
closeModal('approveModal', 'approveModalContent');
|
closeModal('approveModal', 'approveModalContent');
|
||||||
refreshData();
|
refreshData();
|
||||||
} else { alert("Error al confirmar."); }
|
} else { alert(data.error || "Error al confirmar."); }
|
||||||
} catch (e) { alert("Error de conexión"); }
|
} catch (e) { alert("Error de conexión"); }
|
||||||
finally { btn.innerHTML = originalContent; btn.disabled = false; lucide.createIcons(); }
|
finally { btn.innerHTML = originalContent; btn.disabled = false; lucide.createIcons(); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,401 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="es">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
|
||||||
<title>Comparador de Luz - IntegraRepara</title>
|
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
|
||||||
<script src="https://unpkg.com/lucide@latest"></script>
|
|
||||||
<script src="js/layout.js"></script>
|
|
||||||
<style>
|
|
||||||
:root { --primary: #2563eb; --app-bg: #f4f7f9; }
|
|
||||||
body { background-color: var(--app-bg); -webkit-tap-highlight-color: transparent; }
|
|
||||||
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
|
|
||||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
|
|
||||||
|
|
||||||
/* Estilo Toggle Pro */
|
|
||||||
.toggle-dot { transition: all 0.3s ease-in-out; }
|
|
||||||
input:checked ~ .toggle-bg { background-color: #10b981; }
|
|
||||||
input:checked ~ .toggle-dot { transform: translateX(1.5rem); }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body class="text-slate-800 font-sans antialiased h-screen flex flex-col overflow-hidden relative text-left">
|
|
||||||
|
|
||||||
<header class="bg-white px-5 pt-safe mt-6 pb-4 shadow-sm z-20 shrink-0 border-b border-slate-200">
|
|
||||||
<div class="flex items-center gap-3">
|
|
||||||
<a href="configuracion.html" class="w-10 h-10 shrink-0 bg-slate-50 rounded-full flex items-center justify-center text-slate-600 border border-slate-200 active:scale-95 transition-transform">
|
|
||||||
<i data-lucide="arrow-left" class="w-5 h-5"></i>
|
|
||||||
</a>
|
|
||||||
<h1 class="text-xl font-black tracking-tight text-slate-900">Comparador de Luz</h1>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main class="flex-1 overflow-y-auto p-5 fade-in">
|
|
||||||
<div class="space-y-6">
|
|
||||||
|
|
||||||
<!-- AJUSTES + WHATSAPP -->
|
|
||||||
<div class="bg-white rounded-[2.5rem] p-6 shadow-sm border border-slate-100">
|
|
||||||
<div class="flex items-center gap-3 mb-6">
|
|
||||||
<div class="bg-emerald-100 p-2 rounded-xl text-emerald-600"><i data-lucide="message-circle" class="w-5 h-5"></i></div>
|
|
||||||
<h3 class="font-black text-slate-800 uppercase text-xs tracking-widest">Aviso por WhatsApp</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-4">
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">WhatsApp para avisos de nuevos leads</label>
|
|
||||||
<input type="tel" id="adminWhatsapp" placeholder="+34600000000" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800 placeholder:text-slate-300 placeholder:font-medium focus:outline-none focus:border-blue-300">
|
|
||||||
<p class="text-[9px] font-medium text-slate-400 mt-1.5 ml-1 uppercase">Recibirás un WhatsApp cada vez que un cliente suba su factura en marsalva.es</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- AJUSTES DE CALCULO -->
|
|
||||||
<div class="bg-white rounded-[2.5rem] p-6 shadow-sm border border-slate-100">
|
|
||||||
<div class="flex items-center gap-3 mb-6">
|
|
||||||
<div class="bg-blue-100 p-2 rounded-xl text-blue-600"><i data-lucide="sliders-horizontal" class="w-5 h-5"></i></div>
|
|
||||||
<h3 class="font-black text-slate-800 uppercase text-xs tracking-widest">Ajustes del Cálculo</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">IEE %</label>
|
|
||||||
<input type="number" step="0.0001" id="ieePct" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800 focus:outline-none focus:border-blue-300">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">IVA %</label>
|
|
||||||
<input type="number" step="0.01" id="ivaPct" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800 focus:outline-none focus:border-blue-300">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-3">
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Modelo de IA (opcional)</label>
|
|
||||||
<input type="text" id="openaiModel" placeholder="gpt-4o-mini" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800 placeholder:text-slate-300 placeholder:font-medium focus:outline-none focus:border-blue-300">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex items-center justify-between p-4 mt-4 bg-slate-50 rounded-2xl border border-slate-100">
|
|
||||||
<div class="flex-1 pr-4">
|
|
||||||
<p class="font-black text-sm text-slate-800 leading-tight">Comparar con el mercado (CNMC)</p>
|
|
||||||
<p class="text-[10px] font-medium text-slate-400 mt-1 uppercase">Añade ofertas oficiales como dato informativo</p>
|
|
||||||
</div>
|
|
||||||
<label class="flex items-center cursor-pointer">
|
|
||||||
<div class="relative">
|
|
||||||
<input type="checkbox" id="toggleCNMC" class="sr-only">
|
|
||||||
<div class="toggle-bg block bg-slate-300 w-12 h-6 rounded-full transition-colors"></div>
|
|
||||||
<div class="toggle-dot absolute left-1 top-1 bg-white w-4 h-4 rounded-full shadow transition-transform"></div>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button onclick="guardarSettings()" class="w-full mt-5 bg-slate-900 text-white font-black py-4 rounded-2xl text-xs uppercase tracking-widest active:scale-[0.98] transition-transform flex items-center justify-center gap-2">
|
|
||||||
<i data-lucide="save" class="w-4 h-4"></i> Guardar ajustes
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- TARIFAS -->
|
|
||||||
<div class="bg-white rounded-[2.5rem] p-6 shadow-sm border border-slate-100">
|
|
||||||
<div class="flex items-center justify-between mb-6">
|
|
||||||
<div class="flex items-center gap-3">
|
|
||||||
<div class="bg-amber-100 p-2 rounded-xl text-amber-600"><i data-lucide="zap" class="w-5 h-5"></i></div>
|
|
||||||
<h3 class="font-black text-slate-800 uppercase text-xs tracking-widest">Tarifas</h3>
|
|
||||||
</div>
|
|
||||||
<button onclick="abrirModal()" class="w-9 h-9 flex items-center justify-center bg-slate-900 text-white rounded-full active:scale-95 transition-transform">
|
|
||||||
<i data-lucide="plus" class="w-5 h-5"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex items-center gap-1 bg-slate-100 p-1 rounded-2xl mb-4">
|
|
||||||
<button id="tab-propia" onclick="cambiarTab('propia')" class="flex-1 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest bg-white shadow-sm text-slate-900">Propias</button>
|
|
||||||
<button id="tab-repsol" onclick="cambiarTab('repsol')" class="flex-1 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest text-slate-400">Repsol</button>
|
|
||||||
<button id="tab-mercado" onclick="cambiarTab('mercado')" class="flex-1 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest text-slate-400">Mercado</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="listaTarifas" class="space-y-2">
|
|
||||||
<p class="text-center text-slate-400 text-xs font-bold uppercase py-8">Cargando...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<!-- MODAL TARIFA -->
|
|
||||||
<div id="modalTarifa" class="hidden fixed inset-0 bg-black/40 z-50 flex items-end justify-center">
|
|
||||||
<div class="bg-white w-full max-w-lg rounded-t-[2.5rem] p-6 max-h-[90vh] overflow-y-auto">
|
|
||||||
<div class="flex items-center justify-between mb-5">
|
|
||||||
<h3 id="modalTitulo" class="font-black text-lg text-slate-900">Nueva tarifa</h3>
|
|
||||||
<button onclick="cerrarModal()" class="w-9 h-9 flex items-center justify-center bg-slate-50 rounded-full border border-slate-200 text-slate-500"><i data-lucide="x" class="w-5 h-5"></i></button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-3">
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Tipo</label>
|
|
||||||
<select id="f_tipo" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800">
|
|
||||||
<option value="propia">Propia</option>
|
|
||||||
<option value="repsol">Repsol</option>
|
|
||||||
<option value="mercado">Mercado</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Nombre *</label>
|
|
||||||
<input type="text" id="f_nombre" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Comercializadora</label>
|
|
||||||
<input type="text" id="f_comercializadora" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Precio Potencia P1 (€/kW·día)</label>
|
|
||||||
<input type="number" step="0.000001" id="f_p1" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Precio Potencia P2 (€/kW·día)</label>
|
|
||||||
<input type="number" step="0.000001" id="f_p2" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-3 gap-2">
|
|
||||||
<div>
|
|
||||||
<label class="text-[9px] font-bold text-slate-400 uppercase ml-1">€/kWh Punta</label>
|
|
||||||
<input type="number" step="0.000001" id="f_punta" class="w-full mt-1 p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[9px] font-bold text-slate-400 uppercase ml-1">€/kWh Llano</label>
|
|
||||||
<input type="number" step="0.000001" id="f_llano" class="w-full mt-1 p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[9px] font-bold text-slate-400 uppercase ml-1">€/kWh Valle</label>
|
|
||||||
<input type="number" step="0.000001" id="f_valle" class="w-full mt-1 p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-3 gap-2">
|
|
||||||
<div>
|
|
||||||
<label class="text-[9px] font-bold text-slate-400 uppercase ml-1">Descuento %</label>
|
|
||||||
<input type="number" step="0.01" id="f_descuento" class="w-full mt-1 p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[9px] font-bold text-slate-400 uppercase ml-1">Bono Social €/día</label>
|
|
||||||
<input type="number" step="0.000001" id="f_bonosocial" class="w-full mt-1 p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="text-[9px] font-bold text-slate-400 uppercase ml-1">Alq. contador €/día</label>
|
|
||||||
<input type="number" step="0.000001" id="f_alquiler" class="w-full mt-1 p-3 bg-slate-50 rounded-xl border border-slate-100 text-xs font-bold text-slate-800">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label class="text-[10px] font-bold text-slate-400 uppercase ml-1">Notas</label>
|
|
||||||
<textarea id="f_notas" rows="2" class="w-full mt-1 p-4 bg-slate-50 rounded-2xl border border-slate-100 text-sm font-medium text-slate-800"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex items-center justify-between p-4 bg-slate-50 rounded-2xl border border-slate-100">
|
|
||||||
<p class="font-black text-sm text-slate-800">Tarifa activa</p>
|
|
||||||
<label class="flex items-center cursor-pointer">
|
|
||||||
<div class="relative">
|
|
||||||
<input type="checkbox" id="f_activa" class="sr-only">
|
|
||||||
<div class="toggle-bg block bg-slate-300 w-12 h-6 rounded-full transition-colors"></div>
|
|
||||||
<div class="toggle-dot absolute left-1 top-1 bg-white w-4 h-4 rounded-full shadow transition-transform"></div>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button onclick="guardarTarifa()" class="w-full mt-2 bg-blue-600 text-white font-black py-4 rounded-2xl text-xs uppercase tracking-widest active:scale-[0.98] transition-transform">
|
|
||||||
Guardar tarifa
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="toast" class="fixed top-5 left-1/2 -translate-x-1/2 bg-slate-900 text-white text-xs font-bold px-4 py-2.5 rounded-full shadow-lg z-50 transition-opacity" style="opacity:0;"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
|
||||||
? 'http://localhost:3000'
|
|
||||||
: 'https://integrarepara-api.integrarepara.es';
|
|
||||||
const token = localStorage.getItem('token');
|
|
||||||
|
|
||||||
let tarifas = [];
|
|
||||||
let currentTab = 'propia';
|
|
||||||
let editingId = null;
|
|
||||||
|
|
||||||
function authHeaders(json = true) {
|
|
||||||
const h = { "Authorization": `Bearer ${token}` };
|
|
||||||
if (json) h["Content-Type"] = "application/json";
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
function showToast(msg, isError = false) {
|
|
||||||
const toast = document.getElementById('toast');
|
|
||||||
toast.textContent = msg;
|
|
||||||
toast.className = `fixed top-5 left-1/2 -translate-x-1/2 ${isError ? 'bg-rose-600' : 'bg-slate-900'} text-white text-xs font-bold px-4 py-2.5 rounded-full shadow-lg z-50 transition-opacity`;
|
|
||||||
toast.style.opacity = '1';
|
|
||||||
setTimeout(() => { toast.style.opacity = '0'; }, 2500);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function cargarSettings() {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/energy-settings`, { headers: authHeaders(false) });
|
|
||||||
const data = await res.json();
|
|
||||||
const s = (data.ok && data.settings) ? data.settings : {};
|
|
||||||
document.getElementById('ieePct').value = s.iee_pct ?? 5.1126963;
|
|
||||||
document.getElementById('ivaPct').value = s.iva_pct ?? 21;
|
|
||||||
document.getElementById('openaiModel').value = s.openai_model || '';
|
|
||||||
document.getElementById('adminWhatsapp').value = s.admin_whatsapp || '';
|
|
||||||
document.getElementById('toggleCNMC').checked = s.cnmc_enabled !== false;
|
|
||||||
} catch (e) {
|
|
||||||
showToast('No se pudieron cargar los ajustes', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function guardarSettings() {
|
|
||||||
const body = {
|
|
||||||
ieePct: parseFloat(document.getElementById('ieePct').value) || 5.1126963,
|
|
||||||
ivaPct: parseFloat(document.getElementById('ivaPct').value) || 21,
|
|
||||||
openaiModel: document.getElementById('openaiModel').value.trim() || null,
|
|
||||||
cnmcEnabled: document.getElementById('toggleCNMC').checked,
|
|
||||||
adminWhatsapp: document.getElementById('adminWhatsapp').value.trim() || null,
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/energy-settings`, { method: 'PUT', headers: authHeaders(), body: JSON.stringify(body) });
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.ok) showToast('Ajustes guardados'); else showToast('Error al guardar', true);
|
|
||||||
} catch (e) {
|
|
||||||
showToast('Error de conexión', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function cargarTarifas() {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/energy-tariffs`, { headers: authHeaders(false) });
|
|
||||||
const data = await res.json();
|
|
||||||
tarifas = data.ok ? data.tarifas : [];
|
|
||||||
} catch (e) {
|
|
||||||
tarifas = [];
|
|
||||||
}
|
|
||||||
renderTarifas();
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderTarifas() {
|
|
||||||
const list = tarifas.filter(t => t.tipo === currentTab);
|
|
||||||
const cont = document.getElementById('listaTarifas');
|
|
||||||
if (!list.length) {
|
|
||||||
cont.innerHTML = `<p class="text-center text-slate-400 text-xs font-bold uppercase py-8">Sin tarifas en esta categoría</p>`;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cont.innerHTML = list.map(t => `
|
|
||||||
<div class="flex items-center justify-between p-4 bg-slate-50 rounded-2xl border border-slate-100">
|
|
||||||
<div class="flex-1 pr-3">
|
|
||||||
<p class="font-black text-sm text-slate-800">${escapeHtml(t.nombre)} ${t.activa === false ? '<span class="text-[9px] font-bold text-rose-500 uppercase ml-1">(inactiva)</span>' : ''}</p>
|
|
||||||
<p class="text-[10px] font-medium text-slate-400 mt-0.5 uppercase">${escapeHtml(t.comercializadora || '')} · Desc. ${Number(t.descuento_pct)}%</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center gap-2 shrink-0">
|
|
||||||
<button onclick="abrirModal(${t.id})" class="w-8 h-8 flex items-center justify-center bg-white rounded-full border border-slate-200 text-slate-500 active:scale-95"><i data-lucide="pencil" class="w-4 h-4"></i></button>
|
|
||||||
<button onclick="borrarTarifa(${t.id})" class="w-8 h-8 flex items-center justify-center bg-white rounded-full border border-slate-200 text-rose-500 active:scale-95"><i data-lucide="trash-2" class="w-4 h-4"></i></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`).join('');
|
|
||||||
lucide.createIcons();
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeHtml(str) {
|
|
||||||
return String(str).replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
|
||||||
}
|
|
||||||
|
|
||||||
function cambiarTab(tipo) {
|
|
||||||
currentTab = tipo;
|
|
||||||
['propia', 'repsol', 'mercado'].forEach(t => {
|
|
||||||
const btn = document.getElementById('tab-' + t);
|
|
||||||
if (t === tipo) btn.className = 'flex-1 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest bg-white shadow-sm text-slate-900';
|
|
||||||
else btn.className = 'flex-1 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest text-slate-400';
|
|
||||||
});
|
|
||||||
renderTarifas();
|
|
||||||
}
|
|
||||||
|
|
||||||
function abrirModal(id = null) {
|
|
||||||
editingId = id;
|
|
||||||
const t = id ? tarifas.find(x => x.id === id) : null;
|
|
||||||
document.getElementById('modalTitulo').textContent = id ? 'Editar tarifa' : 'Nueva tarifa';
|
|
||||||
document.getElementById('f_tipo').value = t ? t.tipo : currentTab;
|
|
||||||
document.getElementById('f_nombre').value = t ? t.nombre : '';
|
|
||||||
document.getElementById('f_comercializadora').value = t ? (t.comercializadora || '') : '';
|
|
||||||
document.getElementById('f_p1').value = t ? t.precio_potencia_p1 : 0;
|
|
||||||
document.getElementById('f_p2').value = t ? t.precio_potencia_p2 : 0;
|
|
||||||
document.getElementById('f_punta').value = t ? t.precio_energia_punta : 0;
|
|
||||||
document.getElementById('f_llano').value = t ? t.precio_energia_llano : 0;
|
|
||||||
document.getElementById('f_valle').value = t ? t.precio_energia_valle : 0;
|
|
||||||
document.getElementById('f_descuento').value = t ? t.descuento_pct : 0;
|
|
||||||
document.getElementById('f_bonosocial').value = t ? t.bono_social_dia : 0;
|
|
||||||
document.getElementById('f_alquiler').value = t ? t.alquiler_contador_dia : 0;
|
|
||||||
document.getElementById('f_notas').value = t ? (t.notas || '') : '';
|
|
||||||
document.getElementById('f_activa').checked = t ? t.activa !== false : true;
|
|
||||||
document.getElementById('modalTarifa').classList.remove('hidden');
|
|
||||||
lucide.createIcons();
|
|
||||||
}
|
|
||||||
|
|
||||||
function cerrarModal() {
|
|
||||||
document.getElementById('modalTarifa').classList.add('hidden');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function guardarTarifa() {
|
|
||||||
const body = {
|
|
||||||
tipo: document.getElementById('f_tipo').value,
|
|
||||||
nombre: document.getElementById('f_nombre').value.trim(),
|
|
||||||
comercializadora: document.getElementById('f_comercializadora').value.trim() || null,
|
|
||||||
precioPotenciaP1: parseFloat(document.getElementById('f_p1').value) || 0,
|
|
||||||
precioPotenciaP2: parseFloat(document.getElementById('f_p2').value) || 0,
|
|
||||||
precioEnergiaPunta: parseFloat(document.getElementById('f_punta').value) || 0,
|
|
||||||
precioEnergiaLlano: parseFloat(document.getElementById('f_llano').value) || 0,
|
|
||||||
precioEnergiaValle: parseFloat(document.getElementById('f_valle').value) || 0,
|
|
||||||
descuentoPct: parseFloat(document.getElementById('f_descuento').value) || 0,
|
|
||||||
bonoSocialDia: parseFloat(document.getElementById('f_bonosocial').value) || 0,
|
|
||||||
alquilerContadorDia: parseFloat(document.getElementById('f_alquiler').value) || 0,
|
|
||||||
notas: document.getElementById('f_notas').value.trim() || null,
|
|
||||||
activa: document.getElementById('f_activa').checked,
|
|
||||||
};
|
|
||||||
if (!body.nombre) { showToast('El nombre es obligatorio', true); return; }
|
|
||||||
try {
|
|
||||||
const url = editingId ? `${API_URL}/energy-tariffs/${editingId}` : `${API_URL}/energy-tariffs`;
|
|
||||||
const method = editingId ? 'PUT' : 'POST';
|
|
||||||
const res = await fetch(url, { method, headers: authHeaders(), body: JSON.stringify(body) });
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.ok) {
|
|
||||||
showToast('Tarifa guardada');
|
|
||||||
cerrarModal();
|
|
||||||
cargarTarifas();
|
|
||||||
} else {
|
|
||||||
showToast('Error al guardar', true);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
showToast('Error de conexión', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function borrarTarifa(id) {
|
|
||||||
if (!confirm('¿Eliminar esta tarifa?')) return;
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/energy-tariffs/${id}`, { method: 'DELETE', headers: authHeaders(false) });
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.ok) {
|
|
||||||
showToast('Tarifa eliminada');
|
|
||||||
cargarTarifas();
|
|
||||||
} else {
|
|
||||||
showToast('Error al eliminar', true);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
showToast('Error de conexión', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
lucide.createIcons();
|
|
||||||
if (!token) {
|
|
||||||
showToast('Sesión no válida', true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cargarSettings();
|
|
||||||
cargarTarifas();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -6,13 +6,13 @@
|
|||||||
<title>Configuración - IntegraRepara</title>
|
<title>Configuración - 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>
|
||||||
<script src="js/layout.js"></script>
|
<script src="js/layout.js"></script>
|
||||||
<style>
|
<style>
|
||||||
:root { --primary: #2563eb; --app-bg: #f4f7f9; }
|
:root { --primary: #2563eb; --app-bg: #f4f7f9; }
|
||||||
body { background-color: var(--app-bg); -webkit-tap-highlight-color: transparent; }
|
body { background-color: var(--app-bg); -webkit-tap-highlight-color: transparent; }
|
||||||
.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); } }
|
||||||
|
|
||||||
/* Estilo Toggle Pro */
|
/* Estilo Toggle Pro */
|
||||||
.toggle-dot { transition: all 0.3s ease-in-out; }
|
.toggle-dot { transition: all 0.3s ease-in-out; }
|
||||||
input:checked ~ .toggle-bg { background-color: #10b981; }
|
input:checked ~ .toggle-bg { background-color: #10b981; }
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
<p class="font-black text-sm text-slate-800 leading-tight">Envío Automático</p>
|
<p class="font-black text-sm text-slate-800 leading-tight">Envío Automático</p>
|
||||||
<p class="text-[10px] font-medium text-slate-400 mt-1 uppercase">Notificar cambios de estado a HomeServe</p>
|
<p class="text-[10px] font-medium text-slate-400 mt-1 uppercase">Notificar cambios de estado a HomeServe</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label class="flex items-center cursor-pointer">
|
<label class="flex items-center cursor-pointer">
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<input type="checkbox" id="toggleHS" class="sr-only" onchange="saveConfig()">
|
<input type="checkbox" id="toggleHS" class="sr-only" onchange="saveConfig()">
|
||||||
@@ -52,26 +52,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-4 space-y-2 px-2">
|
<div class="mt-4 space-y-2 px-2">
|
||||||
<div class="flex items-center gap-2 text-[9px] font-bold text-slate-400 uppercase"><i data-lucide="check" class="w-3 h-3 text-emerald-500"></i> Citas agendadas</div>
|
<div class="flex items-center gap-2 text-[9px] font-bold text-slate-400 uppercase"><i data-lucide="check" class="w-3 h-3 text-emerald-500"></i> Citas agendadas</div>
|
||||||
<div class="flex items-center gap-2 text-[9px] font-bold text-slate-400 uppercase"><i data-lucide="check" class="w-3 h-3 text-emerald-500"></i> En camino / Llegada</div>
|
<div class="flex items-center gap-2 text-[9px] font-bold text-slate-400 uppercase"><i data-lucide="check" class="w-3 h-3 text-emerald-500"></i> En camino / Llegada</div>
|
||||||
<div class="flex items-center gap-2 text-[9px] font-bold text-slate-400 uppercase"><i data-lucide="check" class="w-3 h-3 text-emerald-500"></i> Finalización de servicios</div>
|
<div class="flex items-center gap-2 text-[9px] font-bold text-slate-400 uppercase"><i data-lucide="check" class="w-3 h-3 text-emerald-500"></i> Finalización de servicios</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="comparador-luz.html" class="block bg-white rounded-[2.5rem] p-6 shadow-sm border border-slate-100 active:scale-[0.98] transition-transform">
|
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<div class="flex items-center gap-3">
|
|
||||||
<div class="bg-amber-100 p-2 rounded-xl text-amber-600"><i data-lucide="zap" class="w-5 h-5"></i></div>
|
|
||||||
<div>
|
|
||||||
<h3 class="font-black text-slate-800 uppercase text-xs tracking-widest">Comparador de Luz</h3>
|
|
||||||
<p class="text-[10px] font-medium text-slate-400 mt-1 uppercase">Tarifas, Repsol y aviso por WhatsApp</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<i data-lucide="chevron-right" class="w-5 h-5 text-slate-300"></i>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -88,4 +75,4 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user