Edit modal, validation of whole data

This commit is contained in:
Juan Pablo Vial
2025-11-13 18:57:58 -03:00
parent 539ac3c0e8
commit a6037e4e14
8 changed files with 195 additions and 35 deletions

View File

@ -153,7 +153,7 @@
this.fill.brokers()
})
},
broker: (broker_rut) => {
/*broker: (broker_rut) => {
const uri = `/api/proyectos/broker/${broker_rut}`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (!('broker' in json)) {
@ -161,7 +161,7 @@
}
return json.broker
})
},
},*/
promotions: project_id => {
if (project_id in this.data.promotions) {
return new Promise((resolve, reject) => {
@ -266,6 +266,55 @@
this.components.$loader.hide()
}
}
validateBody(body) {
const fieldMap = {
'project_id': this.reservation.project_id,
'date': this.reservation.date,
'buyer_rut': this.reservation.buyer.rut.toString(),
'buyer_digit': this.reservation.buyer.digito,
'buyer_name': this.reservation.buyer.nombres,
'buyer_last_name': this.reservation.buyer.apellidoPaterno,
'buyer_last_name2': this.reservation.buyer.apellidoMaterno,
'buyer_address_street': this.reservation.buyer.datos?.direccion?.calle,
'buyer_address_number': this.reservation.buyer.datos?.direccion?.numero?.toString(),
'buyer_address_extra': this.reservation.buyer.datos?.direccion?.extra,
'buyer_address_comuna_id': this.reservation.buyer.datos?.direccion?.comuna?.id?.toString(),
'buyer_phone': this.reservation.buyer.datos?.telefono,
'buyer_email': this.reservation.buyer.datos?.email,
'buyer_birthdate': this.reservation.buyer.datos?.fechaNacimiento,
'buyer_marital_status': this.reservation.buyer.datos?.estadoCivil,
'buyer_profession': this.reservation.buyer.datos?.ocupacion,
'broker_rut': this.reservation.broker?.rut?.toString(),
'payment_pie': this.reservation.payment?.pie,
'payment_cuotas': this.reservation.payment?.cuotas?.toString(),
'payment_credit': this.reservation.payment?.credit,
'promotions[]': this.reservation.promotions?.map(p => p.id.toString()),
'units[]': this.reservation.units?.map(u => u.unit.id.toString()),
'units_value[]': this.reservation.units?.map(u => u.value.toString()),
}
Object.entries(fieldMap).forEach(([key, value]) => {
if (key.includes('[]') && body.has(`${this.prefix}_${key}`)) {
const values = body.getAll(`${this.prefix}_${key}`)
if (values.length !== value.length) {
return
}
const diff = values.some(v => !value.includes(v))
if (diff.length > 0) {
return
}
if (JSON.stringify(values.sort()) !== JSON.stringify(value.sort())) {
return
}
body.delete(`${this.prefix}_${key}`)
return
}
if (body.has(`${this.prefix}_${key}`) && value === body.get(`${this.prefix}_${key}`)) {
body.delete(`${this.prefix}_${key}`)
}
})
return body
}
show() {
this.reset()
this.components.$modal.modal('show')