mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
325 lines
9.7 KiB
JavaScript
325 lines
9.7 KiB
JavaScript
import DatosGenerales from './datosGenerales.js';
|
|
import DisenioInterior from './disenioInterior.js';
|
|
import DisenioCubierta from './disenioCubierta.js';
|
|
import Direcciones from './direcciones.js';
|
|
import Ajax from '../../components/ajax.js';
|
|
|
|
|
|
import tarjetaTiradasPrecio from './tarjetaTiradasPrecio.js';
|
|
|
|
class PresupuestoCliente {
|
|
|
|
constructor() {
|
|
this.clientePresupuestoWizard = document.querySelector('#wizard-presupuesto-cliente');
|
|
|
|
this.validationStepper = new Stepper(this.clientePresupuestoWizard, {
|
|
linear: true
|
|
});
|
|
|
|
this.btnNext = $('#btnNext');
|
|
this.btnPrev = $('#btnPrev');
|
|
this.btnPrint = $('#btnPrint');
|
|
this.btnSave = $('#btnSave');
|
|
this.btnConfirm = $('#btnConfirm');
|
|
|
|
this.datosGenerales = new DatosGenerales($("#datos-generales"), this.clientePresupuestoWizard, this.validationStepper);
|
|
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.divTiradasPrecios = $("#divTiradasPrecio");
|
|
|
|
this.datos = {};
|
|
this.ajax_calcular = new Ajax('/presupuestocliente/calcular',
|
|
{}, this.datos,
|
|
this.#procesarPresupuesto.bind(this),
|
|
() => { $('#loader').hide(); });
|
|
}
|
|
|
|
|
|
init() {
|
|
|
|
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();
|
|
});
|
|
|
|
this.validationStepper._element.addEventListener('shown.bs-stepper', this.buttonsHandler.bind(this));
|
|
|
|
this.datosGenerales.init();
|
|
this.disenioInterior.init();
|
|
this.disenioCubierta.init();
|
|
this.direcciones.init();
|
|
|
|
this.RELLENAR_PRESUPUESTO();
|
|
|
|
}
|
|
|
|
|
|
checkForm(event) {
|
|
|
|
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");
|
|
$("#titulo").trigger('change');
|
|
|
|
const clienteId = $("#clienteId");
|
|
const newOption = new Option("Cliente Potencial", "1817", true, true);
|
|
clienteId.append(newOption).trigger('change');
|
|
|
|
const papelFormatoId = $("#papelFormatoId");
|
|
const newOption2 = new Option("148 x 210", "1", true, true);
|
|
papelFormatoId.append(newOption2).trigger('change');
|
|
|
|
$("#paginasColor").val("6");
|
|
$("#paginasColor").trigger('change');
|
|
|
|
$("#fresado").trigger("click");
|
|
|
|
|
|
$("#colorEstandar").trigger("click");
|
|
$("#offsetBlanco").trigger("click");
|
|
|
|
setTimeout(function () {
|
|
$("#gramaje80").trigger("click");
|
|
}, 0);
|
|
|
|
setTimeout(function () {
|
|
$("#tapaDura").trigger("click");
|
|
}, 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);*/
|
|
}
|
|
|
|
|
|
buttonsHandler() {
|
|
switch (this.validationStepper._currentIndex + 1) {
|
|
case 0:
|
|
this.btnPrev.addClass('d-none');
|
|
this.btnNext.removeClass('d-none');
|
|
this.btnPrint.addClass('d-none');
|
|
this.btnSave.addClass('d-none');
|
|
this.btnConfirm.addClass('d-none');
|
|
break;
|
|
|
|
case 1:
|
|
this.btnPrev.removeClass('d-none');
|
|
this.btnNext.removeClass('d-none');
|
|
this.btnPrint.addClass('d-none');
|
|
this.btnSave.addClass('d-none');
|
|
this.btnConfirm.addClass('d-none');
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
#procesarPresupuesto(response) {
|
|
|
|
$('#loader').hide();
|
|
// checj if response.tiradas exists and is not empty
|
|
if (response.tiradas && response.tiradas.length) {
|
|
|
|
this.divTiradasPrecios.empty();
|
|
|
|
for (let i = 0; i < response.tiradas.length; i++) {
|
|
new tarjetaTiradasPrecio(
|
|
this.divTiradasPrecios,
|
|
('precio-tiradas-' + response.tiradas[i]),
|
|
response.tiradas[i],
|
|
(parseFloat(response.precio_u[i])*parseInt(response.tiradas[i])).toFixed(2),
|
|
response.precio_u[i]
|
|
);
|
|
|
|
}
|
|
}
|
|
// DEBUG
|
|
//console.log(response);
|
|
}
|
|
|
|
|
|
#nextStep() {
|
|
|
|
switch (this.validationStepper._currentIndex) {
|
|
case 0:
|
|
this.datosGenerales.formValidation.validate();
|
|
break;
|
|
|
|
case 1:
|
|
this.disenioInterior.formValidation.validate();
|
|
break;
|
|
|
|
|
|
case 2:
|
|
this.disenioCubierta.formValidation.validate();
|
|
break;
|
|
|
|
case 3:
|
|
this.direcciones.formValidation.validate();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
#prevtStep() {
|
|
if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4)
|
|
this.validationStepper.previous();
|
|
}
|
|
|
|
|
|
#getDatos() {
|
|
|
|
this.datos = {
|
|
|
|
clienteId: this.datosGenerales.cliente.getVal(),
|
|
|
|
tamanio: this.datosGenerales.getDimensionLibro(),
|
|
tirada: this.datosGenerales.getTiradas(),
|
|
paginas: this.datosGenerales.paginas.val(),
|
|
paginasColor: this.datosGenerales.paginasColor.val(),
|
|
paginasCuadernillo: this.datosGenerales.paginasCuadernillo.val(),
|
|
papelInteriorDiferente: this.datosGenerales.papelDiferente.is(':checked');
|
|
|
|
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.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;
|
|
}
|
|
|
|
if(this.direcciones.direcciones.length > 0){
|
|
this.datos.direcciones = this.direcciones.direcciones;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#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);
|
|
|
|
let presupuestoCliente = new PresupuestoCliente();
|
|
presupuestoCliente.init();
|
|
}
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
|
|
|
|
new Ajax('/translate/getTranslation', { locale: locale, translationFile: 'Presupuestos' }, {},
|
|
initialize,
|
|
function (error) {
|
|
console.log("Error getting translations:", error);
|
|
}
|
|
).post();
|
|
|
|
});
|
|
|