const text_color_button = "#F9F9F9";
const background_color_button = "#588087";
const errores = {
afinanciar:"El mínim a finançar són 250 i el màxim permès són 21.000",
aportacion: "L'aportació ha d'estar entre 0 i 21.000",
nombre:"El nom és requerit",
tel1:"El telèfon és requerit",
correo:"El correu és requerit",
acepto:"Ha d'acceptar els termes i les condicions"
}
const placeholders = {
afinanciar:"escriviu l'import a finançar",
aportacion: "quant aportarà",
nombre:"nom i cognoms del pacient",
tel1:"telèfon del pacient",
correo:"correu electrònic del pacient",
acepto:"Accepto la política de privadesa.",
}
const getConfiguration = token => {
let data = {
"id_cliente": 633,
"id_tarifa": 21,
"text1": "Calcula la teva quota",
"text11": "(prem aquí)",
"text2": "Gràcies pel vostre interès. Li hem enviat un correu electrònic amb la simulació que ha sol·licitat.",
"text3": "Si esteu interessats en iniciar el tràmit per sol·licitar el vostre finançament, cal que ho indiqueu al vostre centre mèdic.",
"url": "https:\/\/www.simuladortmf.com\/",
"logo1": "https://www.tumedicinafinanciada.com/tmf/uploads/logo.png",
"logo2": "https:\/\/simuladortmf.com\/applettmf\/logo.gif",
"color1": "f9f9f9",
"color2": "f9f9f9",
"activo": 1
};
return data;
/*
const getConfiguration = async token => {
let data = await fetch('https://www.simuladortmf.com/api/?token=ywkwBeKjYxL33czQAwhAF5tLFtremPpsnjbJkj8z&accion=applet')
.then(response => response.json())
.then(data => data);
return data;
}
*/
}
const checkError = element => {
let name = element.name;
let texto_de_error = errores[name];
let label = document.querySelector(".error_" + name);
label.innerText = isValid(element) ? '' : texto_de_error;
}
const isValid = element => {
let form = element.closest('form');
return form[element.name].checkValidity();
}
const financiaOperacion = token => {
let conf = getConfiguration(token);
let elementos = `
${conf.text1 || 'financiar tu operacion?'}
`;
let div = document.createElement("div");
div.id = "financiacion_1234";
let body = document.querySelector("body");
body.appendChild(div);
document.getElementById('financiacion_1234').innerHTML = elementos;
}
const enviarPeticion = async element => {
let form = element.closest('form');
let inputs = form.querySelectorAll('input');
let validated = true;
let URL_PETICION = ''; //URL A LA QUE SE HARÁ LA PETICIÓN POR POST
let data = {};
inputs.forEach(element => {
if (element.checkValidity() == false) {
validated = false;
}
data[element.name] = element.value;
});
if (validated == false) {
alert("Debe rellenar todos los campos de una forma válida");
return false;
}
document.querySelector('.financia_form_1').style['display'] = 'none';
document.querySelector('.financia_form_2').style['display'] = 'block';
document.getElementById("financiacion_12345_enlace").innerText = 'CALCULANT SIMULACIÓ...'
let url = await fetch("https://simuladortmf.com/informe.php", {
method:"POST",
body:JSON.stringify(data)
})
.then(response => response.text())
.then(response => {
document.getElementById("financiacion_12345_enlace").setAttribute("data-href", response);
document.getElementById("financiacion_12345_enlace").disabled = false;
document.getElementById("financiacion_12345_enlace").innerText = 'VISUALITZAR SIMULACIÓ';
return response
})
console.log(url);
}
const marcar = _ => {
document.getElementById("acepto").checked = true;
}
const cambiarMini = _ => {
let element = document.querySelector('.financia_1234');
element.style.display = 'none';
let element2 = document.querySelector('.financia_12345');
element2.style.display = 'block';
}
const cambiarMega = _ => {
let element = document.querySelector('.financia_1234');
element.style.display = 'block';
let element2 = document.querySelector('.financia_12345');
element2.style.display = 'none';
}
const realizar_otra_simulacion = _ => {
let form = document.querySelector('.financia_form_1');
let inputs = form.querySelectorAll('input[type="text"], input[type="number"], input[type="email"]');
inputs.forEach(element => {
element.value = "";
});
document.querySelector('.financia_form_2').style['display'] = 'none';
document.querySelector('.financia_form_1').style['display'] = 'block';
}
const visualizar_pdf = _ => {
let enlace = document.querySelector('.financiacion_12345_enlace');
window.open(enlace.dataset.href, '_blank');
}
window.addEventListener("load", _ => financiaOperacion("ywkwBeKjYxL33czQAwhAF5tLFtremPpsnjbJkj8z"));
function validarRango() {
const inputImporte = document.getElementById("afinanciar");
const inputAportacion = document.getElementById("aportacion");
const valor = parseInt(inputImporte.value, 10);
if (valor < 250 || valor > 21000) {
alert("El número debe estar entre 250 y 21,000 €");
inputImporte.value = "";
inputAportacion.value = "";
}
}