Files

85 lines
2.1 KiB
Vue
Raw Permalink Normal View History

2021-06-08 12:21:19 -05:00
<template>
<div>
<h4 class="is-size-4 mb-2">Descargar reporte</h4>
<b-field label="Seleccione una fecha de inicio:">
<b-datepicker
icon="calendar-today"
placeholder="Seleccione una fecha de inicio"
:min-date="minDate"
:max-date="maxDate"
v-model="selectedInicio"
trap-focus
2021-08-05 15:12:22 -05:00
/>
2021-06-08 12:21:19 -05:00
</b-field>
<b-field label="Seleccione una fecha de fin:">
<b-datepicker
placeholder="Seleccione una fecha de fin"
icon="calendar-today"
:min-date="minDate"
:max-date="maxDate"
v-model="selectedFin"
trap-focus
2021-08-05 15:12:22 -05:00
/>
2021-06-08 12:21:19 -05:00
</b-field>
2021-12-06 14:59:19 -06:00
<b-field class="pb-5 pt-3">
2021-12-07 10:40:29 -06:00
<b-button type="is-info" @click="descargar()" :disabled="validarFechas()">
2021-06-08 12:21:19 -05:00
Descargar Excel
</b-button>
2021-12-06 14:59:19 -06:00
</b-field>
2021-06-08 12:21:19 -05:00
</div>
</template>
<script>
import axios from 'axios'
import moment from 'moment'
import fileDownload from 'js-file-download'
export default {
2021-12-06 14:59:19 -06:00
props: {
admin: { type: Object, required: true },
imprimirError: { type: Function, required: true },
updateIsLoading: { type: Function, required: true },
},
2021-06-08 12:21:19 -05:00
data() {
return {
selectedFin: [],
2021-11-23 17:44:24 -06:00
selectedInicio: [],
2021-06-08 12:21:19 -05:00
maxDate: new Date(),
2021-11-23 17:44:24 -06:00
minDate: new Date('January 1, 2020'),
2021-06-08 12:21:19 -05:00
}
},
methods: {
validarFechas() {
const fechaInicio = moment(new Date(this.selectedInicio))
const fechaFin = moment(new Date(this.selectedFin))
if (!fechaInicio.isValid() || !fechaFin.isValid()) return true
return false
},
descargar() {
2021-08-05 15:12:22 -05:00
this.updateIsLoading(true)
2021-06-08 12:21:19 -05:00
axios
.get(
`${process.env.api}/servicio/reporte?inicio=${this.selectedInicio}&fin=${this.selectedFin}`,
2021-08-04 16:28:45 -05:00
this.admin.token
2021-06-08 12:21:19 -05:00
)
.then((res) => {
fileDownload(res.data, `reporte.csv`)
this.selectedInicio = []
this.selectedFin = []
2021-08-05 15:12:22 -05:00
this.updateIsLoading(false)
2021-06-08 12:21:19 -05:00
})
.catch((err) => {
2021-08-05 15:12:22 -05:00
this.updateIsLoading(false)
2021-11-25 14:51:33 -06:00
this.imprimirError(err.response.data)
2021-06-08 12:21:19 -05:00
})
},
},
}
</script>
<style scoped></style>