132 lines
4.7 KiB
PHP
132 lines
4.7 KiB
PHP
@push('page_scripts')
|
|
<script>
|
|
class ModalPayments {
|
|
prefix
|
|
ids = {
|
|
pie: {
|
|
checkbox: '',
|
|
value: '',
|
|
installments: ''
|
|
},
|
|
credit: {
|
|
checkbox: '',
|
|
value: ''
|
|
}
|
|
}
|
|
components = {
|
|
pie: {
|
|
$checkbox: null,
|
|
value: null,
|
|
installments: null
|
|
},
|
|
credit: {
|
|
$checkbox: null,
|
|
value: null
|
|
}
|
|
}
|
|
data = {
|
|
pie: {
|
|
value: '',
|
|
installments: ''
|
|
},
|
|
credit: {
|
|
value: ''
|
|
}
|
|
}
|
|
constructor(prefix) {
|
|
this.prefix = prefix
|
|
this.ids = {
|
|
pie: {
|
|
checkbox: `${this.prefix}_payment_has_pie`,
|
|
value: `${this.prefix}_payment_pie`,
|
|
installments: `${this.prefix}_payment_cuotas`
|
|
},
|
|
credit: {
|
|
checkbox: `${this.prefix}_payment_has_credit`,
|
|
value: `${this.prefix}_payment_credit`
|
|
}
|
|
}
|
|
this.setup()
|
|
}
|
|
reset() {
|
|
this.components.pie.$checkbox.prop('checked', false)
|
|
this.components.pie.value.value = ''
|
|
this.components.pie.installments.value = ''
|
|
this.components.credit.$checkbox.prop('checked', false)
|
|
this.components.credit.value.value = ''
|
|
}
|
|
show = {
|
|
pie: () => {
|
|
this.components.pie.value.style.display = this.data.pie.value
|
|
this.components.pie.installments.style.display = this.data.pie.installments
|
|
},
|
|
credit: () => {
|
|
this.components.credit.value.style.display = this.data.credit.value
|
|
}
|
|
}
|
|
hide = {
|
|
pie: () => {
|
|
this.components.pie.value.style.display = 'none'
|
|
this.components.pie.installments.style.display = 'none'
|
|
},
|
|
credit: () => {
|
|
this.components.credit.value.style.display = 'none'
|
|
},
|
|
all: () => {
|
|
this.hide.pie()
|
|
this.hide.credit()
|
|
}
|
|
}
|
|
fill(payment) {
|
|
if ('pie' in payment && payment.pie !== null) {
|
|
this.components.pie.$checkbox.prop('checked', true)
|
|
this.show.pie()
|
|
this.components.pie.value.querySelector('input').value = payment.pie.valor
|
|
this.components.pie.installments.querySelector('input').value = payment.pie.cuotas
|
|
}
|
|
if ('credito' in payment && payment.credito !== null) {
|
|
this.components.credit.$checkbox.prop('checked', true)
|
|
this.show.credit()
|
|
this.components.credit.value.querySelector('input').value = payment.credito.valor
|
|
}
|
|
/*if ('subsidio' in payment && payment.subsidio !== null) {
|
|
this.components.subsidio.$checkbox.prop('checked', true)
|
|
this.components.subsidio.subsidy.value.value = payment.subsidio.subsidio.valor
|
|
this.components.subsidio.savings.value.value = payment.subsidio.ahorro.valor
|
|
this.show.subsidio()
|
|
}*/
|
|
}
|
|
setup() {
|
|
this.components.pie.$checkbox = $(`#${this.ids.pie.checkbox}`)
|
|
this.components.pie.value = document.getElementById(this.ids.pie.value)
|
|
this.components.pie.installments = document.getElementById(this.ids.pie.installments)
|
|
this.components.credit.$checkbox = $(`#${this.ids.credit.checkbox}`)
|
|
this.components.credit.value = document.getElementById(this.ids.credit.value)
|
|
|
|
this.components.pie.$checkbox.checkbox()
|
|
this.components.pie.$checkbox.change(changeEvent => {
|
|
if (this.components.pie.$checkbox.is(':checked')) {
|
|
this.show.pie()
|
|
return
|
|
}
|
|
this.hide.pie()
|
|
})
|
|
this.components.credit.$checkbox.checkbox()
|
|
this.components.credit.$checkbox.change(changeEvent => {
|
|
if (this.components.credit.$checkbox.is(':checked')) {
|
|
this.show.credit()
|
|
return
|
|
}
|
|
this.hide.credit()
|
|
})
|
|
|
|
this.data.pie.value = this.components.pie.value.style.display
|
|
this.data.pie.installments = this.components.pie.installments.style.display
|
|
this.data.credit.value = this.components.credit.value.style.display
|
|
|
|
this.hide.all()
|
|
}
|
|
}
|
|
</script>
|
|
@endpush
|