añadido direcciones

This commit is contained in:
2024-10-08 15:14:12 +02:00
parent dfd915e47f
commit 032b09f0a3
4 changed files with 149 additions and 4 deletions

View File

@ -0,0 +1,55 @@
<div class="col-12 pb-2 d-flex flex-column align-items-center">
<div class="col-sm-8 mb-3 d-flex flex-column align-items-center">
<h5 class="mb-1 fw-bold titulo"></h5>
</div><!--//.mb-3 -->
<div class="col-sm-8 mb-3 d-flex flex-column align-items-center">
<h3 class="mb-1 fw-bold"> Direcciones de envío </h3>
</div><!--//.mb-3 -->
<div id="divInputDirecciones" name="div_input_direcciones" class="row col-sm-12 mb-5 justify-content-center">
<div id="containerTiradasEnvios" class="row mb-3">
</div>
<div class="row mb-3 justify-content-center">
<div class="col-sm-4 mb-3">
<label for="direcciones" class="form-label">Mis direcciones</label>
<select id="direcciones" name="direcciones" class="form-control select2bs2"
style="width: 100%;"></select>
</div>
<div class="col-sm-2 mb-3">
<label for="unidadesEnvio" class="form-label">
Unidades
</label>
<input type="number" class="form-control" id="unidadesEnvio" name="unidadesEnvio" maxLength="8" step="1"
class="form-control">
</div>
<div class="col-sm-2 mb-3 mt-auto mb-0">
<button id="insertarDireccion" type="button"
class="btn btn-secondary waves-effect waves-light">Insertar</button>
</div>
</div>
<div class="row mb-3 justify-content-center">
<div class="col-sm-4 mb-3">
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" id="entregaPieCalle" name="entregaPieCalle"
value="1">
<label class="form-check-label"
for="add_entregaPieCalle"><?= lang('PresupuestosDirecciones.entregaPieCalle') ?></label>
</div>
</div>
</div>
<div id="divDirecciones" class="col-12 pb-2">
</div>
</div>
</div>

View File

@ -1,12 +1,13 @@
class ClassSelect2 {
constructor(domItem, url, placeholder = "", delay = 60, text_field = 'nombre', id_field = 'id') {
constructor(domItem, url, placeholder = "", delay = 60, text_field = 'nombre', id_field = 'id', params={}) {
this.domItem = domItem;
this.url = url;
this.placeholder = placeholder;
this.delay = delay;
this.text_field = text_field;
this.id_field = id_field;
this.params = params;
}
init() {
@ -20,11 +21,17 @@ class ClassSelect2 {
dataType: 'json',
data: (params) => {
return {
let d = {
id: this.id_field,
text: this.text_field,
searchTerm: params.term,
};
for (let key in this.params) {
d[key] = this.params[key];
}
return d;
},
delay: this.delay,
processResults: function (response) {
@ -38,6 +45,10 @@ class ClassSelect2 {
});
}
setParams(params) {
this.params = params;
}
// Método para obtener el valor seleccionado
getValue() {
return this.domItem.val();
@ -48,6 +59,10 @@ class ClassSelect2 {
this.domItem.val(value).trigger('change');
}
clear() {
this.domItem.val(null).trigger('change');
}
// Método para oculatar el select2
hide() {
this.domItem.select2('close');

View File

@ -0,0 +1,68 @@
import ClassSelect from '../../components/select2.js';
class Direcciones {
constructor(domItem, wizardForm, validatorStepper) {
this.domItem = domItem;
this.wizardStep = wizardForm.querySelector('#direcciones-libro');
this.validatorStepper = validatorStepper;
this.direcciones = new ClassSelect($("#direcciones"), '/clientedirecciones/menuitems');
this.initValidation();
}
init() {
$("#clienteId").on('change', this.#handleChangeCliente.bind(this));
this.direcciones.init();
}
initValidation() {
const stepper = this.validatorStepper;
this.formValidation = FormValidation.formValidation(this.wizardStep, {
fields: {
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap5: new FormValidation.plugins.Bootstrap5({
// Use this for enabling/changing valid/invalid class
// eleInvalidClass: '',
eleValidClass: '',
rowSelector: function (field, ele) {
// field is the field name
// ele is the field element
switch (field) {
case ' ':
return '.col-sm-10';
default:
return '.col-sm-3';
}
}
}),
autoFocus: new FormValidation.plugins.AutoFocus(),
submitButton: new FormValidation.plugins.SubmitButton()
}
}).on('core.form.valid', () => {
stepper.next();
});
}
#handleChangeCliente() {
this.direcciones.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
this.direcciones.clear();
// falta quitar las direcciones que haya!!!!
}
}
export default Direcciones;

View File

@ -1,6 +1,7 @@
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';
class PresupuestoCliente {
@ -21,6 +22,7 @@ class PresupuestoCliente {
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);
}
@ -39,6 +41,7 @@ class PresupuestoCliente {
this.datosGenerales.init();
this.disenioInterior.init();
this.disenioCubierta.init();
this.direcciones.init();
this.RELLENAR_PRESUPUESTO();
@ -51,14 +54,14 @@ class PresupuestoCliente {
$("#titulo").trigger('change');
const clienteId = $("#clienteId");
const newOption = new Option("Cliente Potencial", "1", true, true);
const newOption = new Option("Cliente Potencial", "1817", true, true);
clienteId.append(newOption).trigger('change');
const papelFormatoId = $("#papelFormatoId");
const newOption2 = new Option("Formato 1", "1", true, true);
papelFormatoId.append(newOption2).trigger('change');
$("#paginasColor").val("5");
$("#paginasColor").val("6");
$("#paginasColor").trigger('change');
$("#fresado").trigger("click");
@ -70,6 +73,10 @@ class PresupuestoCliente {
setTimeout(function() {
$("#gramaje80").trigger("click");
}, 0);
setTimeout(function() {
$("#tapaDura").trigger("click");
}, 0);
}