mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
741 lines
26 KiB
JavaScript
741 lines
26 KiB
JavaScript
import ClassSelect from '../../components/select2.js';
|
|
import Ajax from '../../components/ajax.js';
|
|
import tarjetaDireccion from '../../components/tarjetaDireccionPresupuesto.js';
|
|
import SelectorTiradaEnvio from './selectorTiradaEnvio.js';
|
|
import DireccionForm from '../../components/modalDireccion.js';
|
|
|
|
|
|
class Direcciones {
|
|
|
|
constructor(domItem, wizardForm, validatorStepper) {
|
|
|
|
this.domItem = domItem;
|
|
this.wizardStep = wizardForm.querySelector('#direcciones-libro');
|
|
this.validatorStepper = validatorStepper;
|
|
this.allowNext = true;
|
|
|
|
this.recogidaTaller = this.domItem.find('#recogerEnTaller');
|
|
|
|
this.unidadesAdd = this.domItem.find('#unidadesEnvio');
|
|
this.btnAdd = this.domItem.find('#insertarDireccion');
|
|
this.btnNew = this.domItem.find('#nuevaDireccion');
|
|
this.entregaPieCallero = this.domItem.find('#entregaPieCalle');
|
|
|
|
this.direccionesCliente = new ClassSelect($("#direcciones"), '/misdirecciones/getSelect2');
|
|
this.direccionesClienteFP1 = new ClassSelect($("#direccionesFP1"), '/misdirecciones/getSelect2');
|
|
this.direccionesClienteFP2 = new ClassSelect($("#direccionesFP2"), '/misdirecciones/getSelect2');
|
|
|
|
this.divDirecciones = $(this.domItem.find('#divDirecciones'));
|
|
this.divTiradas = this.domItem.find('#containerTiradasEnvios');
|
|
|
|
this.sameAddPrincipalFP1 = this.domItem.find('#sameAddPrincipalFP1');
|
|
this.sameAddPrincipalFP2 = this.domItem.find('#sameAddPrincipalFP2');
|
|
this.sameAddFP1 = this.domItem.find('#sameAddFP1');
|
|
|
|
this.checksTiradasEnvio = $('.check-tirada-envio');
|
|
|
|
this.direcciones = [];
|
|
this.direccionesFP1 = [];
|
|
this.direccionesFP2 = [];
|
|
|
|
this.tiradaSeleccionada = null;
|
|
|
|
this.direcciones.calcularPresupuesto = false;
|
|
}
|
|
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
$("#clienteId").on('change', this.handleChangeCliente.bind(this));
|
|
|
|
this.recogidaTaller.on('change', () => {
|
|
|
|
if (this.recogidaTaller.is(':checked')) {
|
|
|
|
this.divDirecciones.empty();
|
|
this.direcciones = [];
|
|
$('.div-direcciones').addClass('d-none');
|
|
}
|
|
else {
|
|
$('.div-direcciones').removeClass('d-none');
|
|
}
|
|
});
|
|
|
|
|
|
this.direccionesCliente.init();
|
|
this.direccionesClienteFP1.init();
|
|
this.direccionesClienteFP2.init();
|
|
this.btnAdd.on('click', this.#insertDireccion.bind(this));
|
|
this.btnNew.on('click', this.#nuevaDireccion.bind(this));
|
|
|
|
$('#insertarDireccionFP1').on('click', () => {
|
|
this.#insertDireccionFP(1);
|
|
});
|
|
$('#insertarDireccionFP2').on('click', () => {
|
|
this.#insertDireccionFP(2);
|
|
});
|
|
|
|
// evento para actualizar el selector de tiradas
|
|
$(document).on('update-tiradas-envios', (event, data) => {
|
|
self.divTiradas.empty();
|
|
if (data.tiradas.length > 0) {
|
|
data.tiradas.forEach(tirada => {
|
|
self.insertTirada(tirada);
|
|
});
|
|
|
|
if (data.tiradaSeleccionada) {
|
|
self.divTiradas.find('.check-tirada-envio[tirada="' + data.tiradaSeleccionada + '"]').trigger('click');
|
|
self.selectedTirada = data.tiradaSeleccionada;
|
|
}
|
|
else {
|
|
self.tiradaSeleccionada = null;
|
|
}
|
|
|
|
|
|
self.divTiradas.trigger('change');
|
|
}
|
|
});
|
|
|
|
this.sameAddPrincipalFP1.on('change', this.#handleSameAddPrincipalFP1.bind(this));
|
|
this.sameAddPrincipalFP2.on('change', this.#handleSameAddPrincipalFP2.bind(this));
|
|
this.sameAddFP1.on('change', this.#handleSameAddFP1.bind(this));
|
|
}
|
|
|
|
|
|
|
|
cargarDatos(datos, datosGenerales, direccionesFP = [], direccionesFPChecks = {}) {
|
|
|
|
self = this;
|
|
|
|
try {
|
|
|
|
let tiradas_envio = [datosGenerales.tirada];
|
|
if (datosGenerales.tirada2) {
|
|
tiradas_envio.push(datosGenerales.tirada2);
|
|
}
|
|
if (datosGenerales.tirada3) {
|
|
tiradas_envio.push(datosGenerales.tirada3);
|
|
}
|
|
if (datosGenerales.tirada4) {
|
|
tiradas_envio.push(datosGenerales.tirada4);
|
|
}
|
|
tiradas_envio.sort((a, b) => a - b);
|
|
|
|
setTimeout(() => {
|
|
|
|
tiradas_envio.forEach(tirada => {
|
|
self.insertTirada(tirada);
|
|
});
|
|
}, 0);
|
|
|
|
$('#tiradaEnvios-' + datosGenerales.selectedTirada).trigger('click');
|
|
|
|
if (datos.entrega_taller == 1) {
|
|
this.recogidaTaller.prop('checked', true);
|
|
this.recogidaTaller.trigger('change');
|
|
}
|
|
else {
|
|
|
|
this.recogidaTaller.prop('checked', false);
|
|
|
|
setTimeout(function () {
|
|
$(`#containerTiradasEnvios .tirada-envio input[tirada="${datosGenerales.tirada}"]`).trigger('click');
|
|
}, 0);
|
|
|
|
|
|
for (let i = 0; i < datos.length; i++) {
|
|
|
|
let id = datos[i].id;
|
|
let unidades = datos[i].cantidad;
|
|
let entregaPalets = datos[i].palets;
|
|
|
|
|
|
if (id == null || id <= 0 || id == undefined)
|
|
return;
|
|
if (unidades == null || unidades <= 0 || unidades == undefined)
|
|
return;
|
|
|
|
let divId = "dirEnvio-1";
|
|
let direccionesActuales = this.divDirecciones.find('.direccion-cliente');
|
|
if (direccionesActuales.length > 0) {
|
|
// the the lass item
|
|
let last = direccionesActuales[direccionesActuales.length - 1];
|
|
divId = "dirEnvio-" + (parseInt(last.id.split('-')[1]) + 1);
|
|
}
|
|
let tarjeta = new tarjetaDireccion(this.divDirecciones, divId, datos[i]);
|
|
tarjeta.setUnidades(unidades);
|
|
tarjeta.setEntregaPalets(entregaPalets);
|
|
tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self));
|
|
tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self));
|
|
this.divDirecciones.append(tarjeta.card);
|
|
this.direcciones.push(tarjeta);
|
|
}
|
|
}
|
|
|
|
if (direccionesFP.length > 0) {
|
|
direccionesFP.forEach(element => {
|
|
let divId = "dirEnvio-fp-" + element.num_ferro_prototipo;
|
|
let containerId = element.num_ferro_prototipo == 1 ? "#divDireccionesFerroPrototipo" : "#divDireccionesFerroPrototipo2";
|
|
let tarjeta = new tarjetaDireccion(containerId,
|
|
divId, element, true, element.num_ferro_prototipo);
|
|
tarjeta.setUnidades(1);
|
|
tarjeta.setEntregaPalets(0);
|
|
tarjeta.card.find('.direccion-eliminar').on('click', (event) => {
|
|
this.#deleteDireccionFP(event, element.num_ferro_prototipo);
|
|
$('.div-direcciones-fp' + element.num_ferro_prototipo).removeClass('d-none');
|
|
});
|
|
$(containerId).append(tarjeta.card);
|
|
if (element.num_ferro_prototipo == 1) {
|
|
this.direccionesFP1.push(tarjeta);
|
|
}
|
|
else {
|
|
this.direccionesFP2.push(tarjeta);
|
|
}
|
|
$('.div-direcciones-fp' + element.num_ferro_prototipo).addClass('d-none');
|
|
|
|
});
|
|
}
|
|
|
|
if (direccionesFPChecks.addFP1isAddMain && direccionesFPChecks.addFP1isAddMain === "true") {
|
|
this.sameAddPrincipalFP1.prop('checked', true);
|
|
}
|
|
|
|
if (direccionesFPChecks.addFP2isFP1 && direccionesFPChecks.addFP2isFP1 === "true") {
|
|
this.sameAddFP1.prop('checked', true);
|
|
}
|
|
else if (direccionesFPChecks.addFP2isAddMain && direccionesFPChecks.addFP2isAddMain === "true") {
|
|
this.sameAddPrincipalFP2.prop('checked', true);
|
|
}
|
|
} catch (e) {
|
|
console.error(e);
|
|
$('#loader').modal('hide');
|
|
}
|
|
}
|
|
|
|
|
|
validate(goToNext = true) {
|
|
|
|
let errores = [];
|
|
|
|
$('#divDirecciones').removeClass('is-invalid');
|
|
if ($('.check-tirada-envio:checked').length > 0) {
|
|
let unidades = parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada'));
|
|
let total_envio = 0;
|
|
// se recorre el array this.direcciones
|
|
this.direcciones.forEach(direccion => {
|
|
total_envio += parseInt(direccion.getUnidades());
|
|
});
|
|
if (total_envio > unidades) {
|
|
$('#divDirecciones').addClass('is-invalid');
|
|
errores.push(window.translations["validation"].unidades_envio_mayor_tirada.replace('{field}', total_envio));
|
|
}
|
|
}
|
|
|
|
const skAlert = document.getElementById('sk-alert');
|
|
skAlert.innerHTML = '';
|
|
const uniqueErrors = [...new Set(errores)];
|
|
|
|
if (uniqueErrors.length > 0) {
|
|
const message = window.translations["validation"].fix_errors +
|
|
`<ul class="mb-0">
|
|
${uniqueErrors.map(err => `<li>${err}</li>`).join('')}
|
|
</ul>`;
|
|
popErrorAlert(message, 'sk-alert', false);
|
|
errores = [];
|
|
return false;
|
|
}
|
|
else {
|
|
document.getElementById('sk-alert').innerHTML = '';
|
|
errores = [];
|
|
if (goToNext)
|
|
this.validatorStepper.next();
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
insertTirada(tirada) {
|
|
|
|
const self = this;
|
|
|
|
let tarjeta = new SelectorTiradaEnvio(this.divTiradas, 'tiradaEnvios-' + tirada, tirada);
|
|
let customOption = tarjeta.card.find('.check-tirada-envio');
|
|
|
|
customOption.on('click', function () {
|
|
self.#handleTiradaEnvio(customOption, self);
|
|
});
|
|
}
|
|
|
|
obtenerDireccionesCalculo() {
|
|
let direcciones = [];
|
|
this.direcciones.forEach(direccion => {
|
|
let dir = {
|
|
direccion: direccion.getDireccion(),
|
|
unidades: direccion.getUnidades(),
|
|
entregaPalets: direccion.getEntregaPalets()
|
|
};
|
|
direcciones.push(dir);
|
|
});
|
|
}
|
|
|
|
|
|
#nuevaDireccion() {
|
|
|
|
let dialog = new DireccionForm($("#addressModal"), function () {
|
|
try {
|
|
let data = dialog.getData();
|
|
data.cliente_id = $("#clienteId").select2('data')[0].id;
|
|
|
|
new Ajax(
|
|
'/misdirecciones/add',
|
|
data,
|
|
{},
|
|
() => { dialog.modal.modal('hide') },
|
|
() => { dialog.modal.modal('hide') }
|
|
).post();
|
|
}
|
|
catch (e) {
|
|
console.error(e);
|
|
dialog.modal.modal('hide');
|
|
}
|
|
|
|
});
|
|
dialog.init();
|
|
}
|
|
|
|
#handleTiradaEnvio(customOption, self) {
|
|
|
|
const el = customOption[0];
|
|
|
|
if (el.checked) {
|
|
// If custom option element is radio, remove checked from the siblings (closest `.row`)
|
|
if (el.type === 'radio') {
|
|
const customRadioOptionList = [].slice.call(el.closest('.row').querySelectorAll('.custom-option'))
|
|
customRadioOptionList.map(function (customRadioOptionEL) {
|
|
customRadioOptionEL.closest('.custom-option').classList.remove('checked')
|
|
})
|
|
}
|
|
el.closest('.custom-option').classList.add('checked')
|
|
self.tiradaSeleccionada = parseInt(el.getAttribute('tirada'));
|
|
} else {
|
|
el.closest('.custom-option').classList.remove('checked')
|
|
}
|
|
}
|
|
|
|
|
|
#insertDireccion() {
|
|
|
|
self = this;
|
|
|
|
try {
|
|
|
|
let id = this.direccionesCliente.getVal();
|
|
let unidades = this.unidadesAdd.val();
|
|
|
|
if (id == null || id <= 0 || id == undefined)
|
|
return;
|
|
if (unidades == null || unidades <= 0 || unidades == undefined)
|
|
return;
|
|
|
|
let entregaPalets = this.entregaPieCallero.is(':checked');
|
|
let divId = "dirEnvio-1";
|
|
let direccionesActuales = this.divDirecciones.find('.direccion-cliente');
|
|
if (direccionesActuales.length > 0) {
|
|
// the the lass item
|
|
let last = direccionesActuales[direccionesActuales.length - 1];
|
|
divId = "dirEnvio-" + (parseInt(last.id.split('-')[1]) + 1);
|
|
|
|
let total_unidades = 0;
|
|
for (let i = 0; i < this.direcciones.length; i++) {
|
|
total_unidades += parseInt(this.direcciones[i].getUnidades());
|
|
}
|
|
|
|
|
|
if (this.getSelectedTirada() == null) {
|
|
popErrorAlert("Tiene que seleccionar una tirada para insertar una dirección");
|
|
return;
|
|
}
|
|
|
|
if (total_unidades + parseInt(unidades) > this.getSelectedTirada()) {
|
|
popErrorAlert("El total de unidades enviadas tiene que ser menor que " + this.getSelectedTirada());
|
|
return;
|
|
}
|
|
}
|
|
else {
|
|
if (this.getSelectedTirada() == null) {
|
|
popErrorAlert("Tiene que seleccionar una tirada para insertar una dirección");
|
|
return;
|
|
}
|
|
|
|
if (unidades > this.getSelectedTirada()) {
|
|
popErrorAlert("El total de unidades enviadas tiene que ser menor que " + this.getSelectedTirada());
|
|
return;
|
|
}
|
|
}
|
|
this.#addTarjetaDireccion(this.divDirecciones, this.direcciones, divId, id, unidades, entregaPalets);
|
|
|
|
this.calcularPresupuesto = true;
|
|
this.divDirecciones.trigger('change');
|
|
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
$('#loader').modal('hide');
|
|
}
|
|
}
|
|
|
|
#insertDireccionFP(num_ferroPrototipo) {
|
|
|
|
self = this;
|
|
|
|
try {
|
|
|
|
let id = 0;
|
|
if (num_ferroPrototipo === 1) {
|
|
id = this.direccionesClienteFP1.getVal();
|
|
}
|
|
if (num_ferroPrototipo === 2) {
|
|
id = this.direccionesClienteFP2.getVal();
|
|
}
|
|
let unidades = 1;
|
|
|
|
if (id == null || id <= 0 || id == undefined)
|
|
return;
|
|
|
|
let divId = "dirEnvio-FP-" + num_ferroPrototipo;
|
|
let containerId = num_ferroPrototipo === 1 ? "#divDireccionesFerroPrototipo" : "#divDireccionesFerroPrototipo2";
|
|
|
|
if (num_ferroPrototipo === 1) {
|
|
this.direccionesFP1 = [];
|
|
}
|
|
if (num_ferroPrototipo === 2) {
|
|
this.direccionesFP2 = [];
|
|
}
|
|
|
|
this.#addTarjetaDireccion(
|
|
$(containerId),
|
|
num_ferroPrototipo === 1 ? this.direccionesFP1 : this.direccionesFP2,
|
|
divId,
|
|
id,
|
|
1, false, true, num_ferroPrototipo);
|
|
|
|
$('.div-direcciones-fp' + num_ferroPrototipo).addClass('d-none');
|
|
$('#loader').modal('hide');
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
$('#loader').modal('hide');
|
|
}
|
|
}
|
|
|
|
async #addTarjetaDireccion(container, addArray, divId, data, unidades, entregaPalets = false, isFerroPrototipo = false, numFerroPrototipo = 0) {
|
|
const self = this;
|
|
|
|
let id = data;
|
|
|
|
try {
|
|
if (typeof data === 'object') {
|
|
const ajaxGetId = new Ajax('/misdirecciones/getId', {
|
|
data: data,
|
|
cliente_id: $("#clienteId").select2('data')[0].id
|
|
}, {}, null, null);
|
|
const response = await ajaxGetId.getPromise();
|
|
id = response;
|
|
}
|
|
|
|
$('#loader').modal('show');
|
|
|
|
if (id == null || id <= 0 || id == undefined || id === 'undefined' || id === '') {
|
|
$('#loader').modal('hide');
|
|
Swal.fire({
|
|
title: 'Error',
|
|
text: window.translations["errores"].error_direccion_principal_no_encontrada,
|
|
icon: 'error',
|
|
showCancelButton: false,
|
|
confirmButtonColor: '#3085d6',
|
|
confirmButtonText: 'Ok',
|
|
customClass: {
|
|
confirmButton: 'btn btn-primary me-1',
|
|
},
|
|
buttonsStyling: false
|
|
});
|
|
if(numFerroPrototipo === 1) {
|
|
this.sameAddPrincipalFP1.prop('checked', false);
|
|
this.sameAddPrincipalFP1.trigger('change');
|
|
}
|
|
if(numFerroPrototipo === 2) {
|
|
this.sameAddPrincipalFP2.prop('checked', false);
|
|
this.sameAddPrincipalFP2.trigger('change');
|
|
}
|
|
return;
|
|
}
|
|
|
|
const ajaxGetDireccion = new Ajax('/misdirecciones/get/' + id, {}, {}, null, null);
|
|
const response = await ajaxGetDireccion.getPromise();
|
|
|
|
if (this.direcciones.length === 0) {
|
|
$('#loader').modal('hide');
|
|
if (entregaPalets) {
|
|
this.calcularPresupuesto = true;
|
|
}
|
|
} else {
|
|
this.calcularPresupuesto = true;
|
|
}
|
|
|
|
const tarjeta = new tarjetaDireccion(container, divId, response.data[0], isFerroPrototipo, numFerroPrototipo);
|
|
tarjeta.setUnidades(unidades);
|
|
tarjeta.setEntregaPalets(entregaPalets);
|
|
|
|
if (!isFerroPrototipo) {
|
|
tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self));
|
|
tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self));
|
|
}
|
|
else {
|
|
tarjeta.card.find('.direccion-eliminar').on('click', (event) => {
|
|
this.#deleteDireccionFP(event, numFerroPrototipo);
|
|
$('.div-direcciones-fp' + numFerroPrototipo).removeClass('d-none');
|
|
});
|
|
}
|
|
container.append(tarjeta.card);
|
|
addArray.push(tarjeta);
|
|
container.trigger('change');
|
|
$('#loader').modal('hide');
|
|
|
|
} catch (err) {
|
|
console.error('Error en petición Ajax:', err);
|
|
$('#loader').modal('hide');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleChangeCliente() {
|
|
|
|
this.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
|
|
this.direccionesCliente.empty();
|
|
this.direccionesClienteFP1.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
|
|
this.direccionesClienteFP1.empty();
|
|
this.direccionesClienteFP2.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
|
|
this.direccionesClienteFP2.empty();
|
|
|
|
this.domItem.find('.direccion-cliente').remove();
|
|
this.direcciones = [];
|
|
}
|
|
|
|
#editUnits(event) {
|
|
|
|
let id = $(event.currentTarget.closest('.direccion-cliente'))[0].id;
|
|
let tarjeta = this.direcciones.filter(direccion => direccion.id == id)[0].card;
|
|
let unidades = tarjeta.find('.unidades').text().split(' ')[0];
|
|
|
|
let modal = $('#modalInput');
|
|
modal.find('.modal-title').text('Editar unidades');
|
|
modal.find('.inputData').val(unidades);
|
|
modal.modal('show');
|
|
|
|
modal.find('.btn-primary').off('click');
|
|
modal.find('.btn-primary').on('click', () => {
|
|
try {
|
|
|
|
let nuevo_valor = parseInt(modal.find('.modal-body input').val());
|
|
if (nuevo_valor > 0) {
|
|
tarjeta.find('.unidades').text(nuevo_valor + ' unidades');
|
|
if (this.direcciones.length > 1) {
|
|
this.calcularPresupuesto = true;
|
|
}
|
|
this.divDirecciones.trigger('change');
|
|
}
|
|
} catch (error) {
|
|
console.error('Units must be a number');
|
|
}
|
|
modal.modal('hide');
|
|
});
|
|
}
|
|
|
|
#deleteDireccion(event) {
|
|
|
|
let tarjeta = event.currentTarget.closest('.direccion-cliente');
|
|
let id = tarjeta.id;
|
|
|
|
const numTarjetasAntes = this.direcciones.length;
|
|
if (numTarjetasAntes == 2) {
|
|
this.calcularPresupuesto = true;
|
|
}
|
|
|
|
this.direcciones = this.direcciones.filter(direccion => direccion.getId() !== id);
|
|
|
|
tarjeta.remove();
|
|
this.divDirecciones.trigger('change');
|
|
|
|
if (this.direcciones.length === 0) {
|
|
if (this.sameAddPrincipalFP1.is(':checked')) {
|
|
this.sameAddPrincipalFP1.prop('checked', false);
|
|
this.sameAddPrincipalFP1.trigger('change');
|
|
}
|
|
if (this.sameAddPrincipalFP2.is(':checked')) {
|
|
this.sameAddPrincipalFP2.prop('checked', false);
|
|
this.sameAddPrincipalFP2.trigger('change');
|
|
}
|
|
}
|
|
|
|
this.calcularPresupuesto = true;
|
|
this.divDirecciones.trigger('change');
|
|
|
|
}
|
|
|
|
#deleteDireccionFP(event, num_ferroPrototipo = 1) {
|
|
|
|
let tarjeta = event.currentTarget.closest('.direccion-cliente');
|
|
|
|
this.calcularPresupuesto = true;
|
|
|
|
if (num_ferroPrototipo === 1) {
|
|
this.direccionesFP1 = [];
|
|
this.sameAddPrincipalFP1.prop('checked', false);
|
|
$('#divDireccionesFerroPrototipo1').trigger('change');
|
|
if (this.sameAddFP1.is(':checked')) {
|
|
this.sameAddFP1.prop('checked', false);
|
|
this.sameAddFP1.trigger('change');
|
|
}
|
|
$('.div-direcciones-fp1').removeClass('d-none');
|
|
}
|
|
if (num_ferroPrototipo === 2) {
|
|
this.direccionesFP2 = [];
|
|
this.sameAddPrincipalFP2.prop('checked', false);
|
|
this.sameAddFP1.prop('checked', false);
|
|
$('#divDireccionesFerroPrototipo2').trigger('change');
|
|
$('.div-direcciones-fp2').removeClass('d-none');
|
|
}
|
|
|
|
tarjeta.remove();
|
|
}
|
|
|
|
#handleSameAddPrincipalFP1() {
|
|
|
|
if (this.sameAddPrincipalFP1.is(':checked')) {
|
|
$('.div-direcciones-fp1').addClass('d-none');
|
|
$('#divDireccionesFerroPrototipo').empty();
|
|
if (this.direcciones.length > 0) {
|
|
// get first element
|
|
let data = this.direcciones[0].getDireccion();
|
|
|
|
this.direccionesFP1 = [];
|
|
this.#addTarjetaDireccion(
|
|
$("#divDireccionesFerroPrototipo"),
|
|
this.direccionesFP1,
|
|
'dirEnvio-FP-1',
|
|
data,
|
|
1, false, true, 1);
|
|
$('#divDireccionesFerroPrototipo').removeClass('d-none');
|
|
}
|
|
else {
|
|
popErrorAlert(window.translations["validation"].error_sameAddPrincipal_FP,
|
|
'sk-alert-ferro-prototipo1', true);
|
|
this.sameAddPrincipalFP1.prop('checked', false);
|
|
$('#divDireccionesFerroPrototipo').empty();
|
|
}
|
|
|
|
}
|
|
else {
|
|
$('.div-direcciones-fp1').removeClass('d-none');
|
|
$('#divDireccionesFerroPrototipo').removeClass('d-none');
|
|
$('#divDireccionesFerroPrototipo').empty();
|
|
}
|
|
}
|
|
|
|
#handleSameAddPrincipalFP2() {
|
|
|
|
if (this.sameAddPrincipalFP2.is(':checked')) {
|
|
if (this.sameAddFP1.is(':checked')) {
|
|
this.sameAddFP1.prop('checked', false);
|
|
}
|
|
$('.div-direcciones-fp2').addClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
if (this.direcciones.length > 0) {
|
|
|
|
let data = this.direcciones[0].getDireccion();
|
|
this.direccionesFP2 = [];
|
|
this.#addTarjetaDireccion(
|
|
$("#divDireccionesFerroPrototipo2"),
|
|
this.direccionesFP2,
|
|
'dirEnvio-FP-2',
|
|
data,
|
|
1, false, true, 2);
|
|
$('#divDireccionesFerroPrototipo2').removeClass('d-none');
|
|
}
|
|
else {
|
|
popErrorAlert(window.translations["validation"].error_sameAddPrincipal_FP,
|
|
'sk-alert-ferro-prototipo2', true);
|
|
this.sameAddPrincipalFP2.prop('checked', false);
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
}
|
|
|
|
}
|
|
else {
|
|
$('.div-direcciones-fp2').removeClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').removeClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
}
|
|
}
|
|
|
|
#handleSameAddFP1() {
|
|
|
|
if (this.sameAddFP1.is(':checked')) {
|
|
if (this.sameAddPrincipalFP2.is(':checked')) {
|
|
this.sameAddPrincipalFP2.prop('checked', false);
|
|
}
|
|
$('.div-direcciones-fp2').addClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
if (this.direccionesFP1.length > 0) {
|
|
|
|
let data = this.direccionesFP1[0].getDireccion();
|
|
|
|
this.direccionesFP2 = [];
|
|
this.#addTarjetaDireccion(
|
|
$("#divDireccionesFerroPrototipo2"),
|
|
this.direccionesFP2,
|
|
'dirEnvio-FP-2',
|
|
data,
|
|
1, false, true, 2);
|
|
|
|
$('#divDireccionesFerroPrototipo2').removeClass('d-none');
|
|
}
|
|
else {
|
|
popErrorAlert(window.translations["validation"].error_sameAddFP1,
|
|
'sk-alert-ferro-prototipo2', true);
|
|
this.sameAddFP1.prop('checked', false);
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
}
|
|
|
|
}
|
|
else {
|
|
$('.div-direcciones-fp2').removeClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').removeClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
}
|
|
}
|
|
|
|
|
|
getSelectedTirada() {
|
|
if ($('.check-tirada-envio:checked').length > 0)
|
|
return parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada'));
|
|
else
|
|
return null;
|
|
}
|
|
|
|
getDireccionesFPChecks() {
|
|
return {
|
|
addFP1isAddMain: this.sameAddPrincipalFP1.is(':checked'),
|
|
addFP2isAddMain: this.sameAddPrincipalFP2.is(':checked'),
|
|
addFP2isFP1: this.sameAddFP1.is(':checked')
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
export default Direcciones; |