119 lines
2.8 KiB
Vue
119 lines
2.8 KiB
Vue
<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
|
|
>
|
|
</b-datepicker>
|
|
</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
|
|
>
|
|
</b-datepicker>
|
|
</b-field>
|
|
|
|
<div class="pb-5 pt-3">
|
|
<b-button type="is-info" @click="descargar()" :disabled="validarFechas()">
|
|
Descargar Excel
|
|
</b-button>
|
|
</div>
|
|
|
|
<b-loading
|
|
:is-full-page="true"
|
|
v-model="isLoading"
|
|
:can-cancel="false"
|
|
></b-loading>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import axios from 'axios'
|
|
import moment from 'moment'
|
|
import fileDownload from 'js-file-download'
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
admin: {},
|
|
selectedInicio: [],
|
|
selectedFin: [],
|
|
minDate: new Date('January 1, 2020'),
|
|
maxDate: new Date(),
|
|
isLoading: false,
|
|
token: {},
|
|
}
|
|
},
|
|
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() {
|
|
this.isLoading = true
|
|
axios
|
|
.get(
|
|
`${process.env.api}/servicio/reporte?inicio=${this.selectedInicio}&fin=${this.selectedFin}`,
|
|
this.token
|
|
)
|
|
.then((res) => {
|
|
fileDownload(res.data, `reporte.csv`)
|
|
this.selectedInicio = []
|
|
this.selectedFin = []
|
|
this.isLoading = false
|
|
})
|
|
.catch((err) => {
|
|
this.isLoading = false
|
|
this.error(err.response.data.message)
|
|
})
|
|
},
|
|
getLocalhostInfo() {
|
|
this.admin.idUsuario = localStorage.getItem('idUsuario')
|
|
this.admin.idTipoUsuario = Number(localStorage.getItem('idTipoUsuario'))
|
|
this.admin.tipoUsuario = localStorage.getItem('tipoUsuario')
|
|
this.token = {
|
|
headers: {
|
|
token: localStorage.getItem('token'),
|
|
},
|
|
}
|
|
},
|
|
imprimirError(err) {
|
|
this.$buefy.dialog.alert({
|
|
title: 'Error',
|
|
message: err.message,
|
|
type: 'is-danger',
|
|
hasIcon: true,
|
|
icon: 'alert-circle',
|
|
ariaRole: 'alertdialog',
|
|
ariaModal: true,
|
|
})
|
|
if (err.err === 'token error') {
|
|
localStorage.clear()
|
|
this.$router.push('/')
|
|
}
|
|
},
|
|
},
|
|
created() {
|
|
this.getLocalhostInfo()
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style scoped></style>
|