trabajando en el backend

This commit is contained in:
2024-10-13 21:10:02 +02:00
parent e64022a7b7
commit 0eaac5af28
32 changed files with 1196 additions and 4746 deletions

View File

@ -4,6 +4,9 @@ import DisenioCubierta from './disenioCubierta.js';
import Direcciones from './direcciones.js';
import Ajax from '../../components/ajax.js';
import tarjetaTiradasPrecio from './tarjetaTiradasPrecio.js';
class PresupuestoCliente {
constructor() {
@ -23,6 +26,12 @@ class PresupuestoCliente {
this.disenioInterior = new DisenioInterior($("#interior-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.disenioCubierta = new DisenioCubierta($("#cubierta-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.direcciones = new Direcciones($("#direcciones-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.datos = {};
this.ajax_calcular = new Ajax('/presupuestocliente/calcular',
{}, this.datos,
this.#procesarPresupuesto,
() => { $('#loader').hide(); console.log("Error") });
}
@ -31,6 +40,8 @@ class PresupuestoCliente {
this.btnNext.on('click', this.#nextStep.bind(this));
this.btnPrev.on('click', this.#prevtStep.bind(this));
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
// Fuerza el foco en el campo de búsqueda de select2
$(document).on('select2:open', () => {
document.querySelector('.select2-search__field').focus();
@ -48,6 +59,29 @@ class PresupuestoCliente {
}
checkForm() {
this.#getDatos();
if (Object.values(this.datos).every(this.#isValidDataForm)) {
try {
$('#loader').show();
// Si se está ejecutando la petición, abortar la petición anterior
this.ajax_calcular.abort();
this.ajax_calcular.setData(this.datos);
this.ajax_calcular.post();
}
catch (e) {
console.log(e);
$('#loader').hide();
}
}
}
RELLENAR_PRESUPUESTO() {
$("#titulo").val("Titulo del libro");
@ -58,7 +92,7 @@ class PresupuestoCliente {
clienteId.append(newOption).trigger('change');
const papelFormatoId = $("#papelFormatoId");
const newOption2 = new Option("Formato 1", "1", true, true);
const newOption2 = new Option("148 x 210", "1", true, true);
papelFormatoId.append(newOption2).trigger('change');
$("#paginasColor").val("6");
@ -66,18 +100,33 @@ class PresupuestoCliente {
$("#fresado").trigger("click");
$("#colorEstandar").trigger("click");
$("#offsetBlanco").trigger("click");
setTimeout(function() {
$("#offsetBlanco").trigger("click");
setTimeout(function () {
$("#gramaje80").trigger("click");
}, 0);
setTimeout(function() {
setTimeout(function () {
$("#tapaDura").trigger("click");
}, 0);
}, 0);
/*
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#unidadesEnvio").val("100");
}, 0);*/
}
@ -102,6 +151,14 @@ class PresupuestoCliente {
}
#procesarPresupuesto(response) {
$('#loader').hide();
console.log("Success");
console.log(response);
}
#nextStep() {
switch (this.validationStepper._currentIndex) {
@ -112,27 +169,113 @@ class PresupuestoCliente {
case 1:
this.disenioInterior.formValidation.validate();
break;
case 2:
this.disenioCubierta.formValidation.validate();
break;
/*
case 3:
FormValidation5.validate();
this.direcciones.formValidation.validate();
break;
*/
default:
break;
}
}
#prevtStep() {
if(this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4)
if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4)
this.validationStepper.previous();
}
#getDatos() {
this.datos = {
clienteId: this.datosGenerales.cliente.getValue(),
tamanio: this.datosGenerales.getDimensionLibro(),
tirada: this.datosGenerales.getTiradas(),
paginas: this.datosGenerales.paginas.val(),
paginasColor: this.datosGenerales.paginasColor.val(),
tipo: this.datosGenerales.tiposLibro.filter('.selected').attr('id'),
isColor: this.datosGenerales.getIsColor(),
isHq: this.disenioInterior.getIsHq(),
interior: {
papelInterior: this.disenioInterior.getPapel(),
gramajeInterior: this.disenioInterior.getGramaje(),
},
cubierta: {
tipoCubierta: this.disenioCubierta.disenioCubierta.filter('.selected').attr('id'),
papelCubierta: this.disenioCubierta.getPapel(),
gramajeCubierta: this.disenioCubierta.getGramaje(),
cabezada: this.disenioCubierta.getCabezada(),
acabados: this.disenioCubierta.getAcabados(),
carasImpresion: this.disenioCubierta.carasCubierta.val(),
},
guardas: this.disenioCubierta.getGuardas(),
sobrecubierta: this.disenioCubierta.getSobrecubierta(),
faja: this.disenioCubierta.getFaja(),
excluirRotativa: this.datosGenerales.excluirRotativa.is(':checked'),
ivaReducido: this.datosGenerales.ivaReducido.find('option:selected').val(),
servicios: {
'prototipo' : this.datosGenerales.servicios.prototipo.is(':checked'),
},
};
if(this.datos.tipo == "cosido"){
this.datos.paginasCuadernillo = this.datosGenerales.paginasCuadernillo.val();
}
let solapasCubierta = this.disenioCubierta.getSolapasCubierta();
if (solapasCubierta !== null && solapasCubierta !== undefined) {
if (solapasCubierta === false)
this.datos.cubierta.solapas = false;
else {
this.datos.cubierta.solapas = true;
this.datos.cubierta.tamanioSolapas = solapasCubierta;
}
}
else{
this.datos.cubierta.solapas = false;
}
}
#isValidDataForm(value) {
if (value === null || value === undefined || value === '') {
return false;
}
if (typeof value === 'object' && value !== null) {
return Object.values(value).every(isValid);
}
return true;
}
}
function isValid(value) {
if (value === null || value === undefined || value === '') {
return false;
}
if (typeof value === 'object' && value !== null) {
return Object.values(value).every(isValid);
}
return true;
}
function initialize(translations) {
window.translations = JSON.parse(translations);