mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
import Ajax from '../../../components/ajax.js';
|
|
|
|
|
|
class editServiciosAcabado {
|
|
|
|
constructor() {
|
|
|
|
this.selectElement = $('#tarifas');
|
|
this.acabado_cubierta = $('#acabado_cubierta');
|
|
this.acabado_sobrecubierta = $('#acabado_sobrecubierta');
|
|
this.tarifasSeleccionadas = JSON.parse(this.selectElement.attr('data-selected') || '[]');
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.selectElement.select2({
|
|
placeholder: "Selecciona tarifas...",
|
|
allowClear: true,
|
|
ajax: {
|
|
url: "/serviciosacabado/gettarifas",
|
|
type: "GET",
|
|
dataType: "json",
|
|
delay: 250,
|
|
data: function (params) {
|
|
return {
|
|
id: window.location.pathname.split('/').pop(),
|
|
search: params.term ,
|
|
acabado_cubierta: self.acabado_cubierta.prop('checked')?1:0,
|
|
acabado_sobrecubierta: self.acabado_sobrecubierta.prop('checked')?1:0
|
|
};
|
|
},
|
|
processResults: function (data) {
|
|
return {
|
|
results: data.map(item => ({
|
|
id: item.id,
|
|
text: item.nombre
|
|
}))
|
|
};
|
|
},
|
|
cache: true
|
|
}
|
|
});
|
|
|
|
// Si hay tarifas preseleccionadas, cargarlas manualmente
|
|
if (this.tarifasSeleccionadas.length > 0) {
|
|
$.ajax({
|
|
url: "/serviciosacabado/getselectedtarifas",
|
|
type: "GET",
|
|
dataType: "json",
|
|
data: { ids: self.tarifasSeleccionadas },
|
|
success: (data) => {
|
|
let tarifasPreseleccionadas = data.map(item => ({
|
|
id: item.id,
|
|
text: item.nombre
|
|
}));
|
|
|
|
self.selectElement.append(
|
|
tarifasPreseleccionadas.map(item =>
|
|
new Option(item.text, item.id, true, true)
|
|
)
|
|
).trigger("change");
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function () {
|
|
new editServiciosAcabado().init();
|
|
})
|
|
|
|
export default editServiciosAcabado; |