Files
inscripciones_front/components/admin/reporte.vue
T
2022-03-07 09:25:31 -06:00

81 lines
1.7 KiB
Vue

<template>
<div>
<div class="columns">
<b-field class="column" label="Fecha inicio">
<b-datepicker
v-model="inicio"
:min-date="minDate1"
:max-date="maxDate"
icon="calendar-today"
rounded
>
</b-datepicker>
</b-field>
<b-field class="column" label="Fecha fin">
<b-datepicker
v-model="fin"
:min-date="minDate2"
:max-date="maxDate"
icon="calendar-today"
rounded
>
</b-datepicker>
</b-field>
</div>
<div class="has-text-centered">
<b-button type="is-link" @click="pedirReporte()">Descargar</b-button>
</div>
</div>
</template>
<script>
import axios from 'axios'
import fileDownload from 'js-file-download'
export default {
props: {
updateIsLoading: { type: Function, require: true },
tipo: { type: String, require: true },
},
data() {
return {
token: '',
minDate1: new Date('2022-01-01'),
minDate2: new Date(),
maxDate: new Date(),
inicio: new Date(),
fin: new Date(),
}
},
methods: {
pedirReporte() {
console.log(this.inicio)
this.updateIsLoading(true)
axios
.get(
`${process.env.api}/admin/reporte?inicio=${this.inicio}&fin=${this.fin}&tipo=${this.tipo}`,
this.token
)
.then((res) => {
fileDownload(res.data, `reporte.csv`)
this.updateIsLoading(false)
})
.catch((err) => {
this.updateIsLoading(false)
})
},
},
created() {
this.token = {
headers: { token: localStorage.getItem('token') },
}
},
}
</script>
<style scoped></style>