Files
servicio_social_front/components/admin/inputTableA.vue
T

336 lines
8.8 KiB
Vue
Raw Normal View History

2021-01-05 16:43:09 -06:00
<template>
2021-01-05 20:28:26 -06:00
<div
v-if="this.idTipoUsuario == 1 && this.tipoUsuario == 'admin'"
class="container"
>
2021-01-05 16:43:09 -06:00
<div class="columns">
<div class="column is-3 mb-0">
<b-field>
<b-input
placeholder="No.Cuenta"
icon="school"
rounded
v-model="numeroCuenta"
maxlength="9"
></b-input>
</b-field>
</div>
<div class="column is-3 mb-4 pb-4">
<b-field>
<b-input
type="name"
placeholder="Nombre"
icon="account"
rounded
v-model="nombre"
></b-input>
</b-field>
</div>
2021-05-13 14:22:56 -05:00
<div class="column is-3 mb-4 pb-4">
2021-01-05 16:43:09 -06:00
<b-field>
<b-select
placeholder="Status"
icon="information"
expanded
rounded
v-model="idStatus"
>
<optgroup>
2021-05-13 14:22:56 -05:00
<option value="">Status</option>
2021-01-05 16:43:09 -06:00
<option value="1">Pre-registro</option>
2021-01-06 17:43:26 -06:00
<option value="2">Pre-registro Validado</option>
<option value="3">Registro</option>
2021-01-05 16:43:09 -06:00
<option value="4">Pre-Término</option>
<option value="5">Término</option>
<option value="6">Liberación</option>
<option value="7">Carta Aceptacion Rechazada</option>
<option value="8">Carta Termino Rechazada</option>
<option value="9">Informe Global Rechazado</option>
<option value="10">Cancelado</option>
</optgroup>
</b-select>
</b-field>
</div>
<div class="buttons section pt-3 pl-5">
<b-button type="is-info" @click="obtenerDatos(idStatus)">
Buscar
</b-button>
</div>
</div>
<div class="columns">
<section class="column is-12">
<b-table
:data="data"
2021-01-05 20:28:26 -06:00
:loading="isLoading"
2021-01-05 16:43:09 -06:00
paginated
backend-pagination
:total="total"
:per-page="perPage"
@page-change="onPageChange"
hoverable
striped
>
<b-table-column field="nombre" label="Nombre" v-slot="props" centered>
<span @click="servicios(props.row.idServicio)">{{
props.row.nombre
}}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-01-05 16:43:09 -06:00
<b-table-column
field="numeroCuenta"
label="Número de Cuenta"
v-slot="props"
centered
width="100"
>
<span @click="servicios(props.row.idServicio)">{{
props.row.numeroCuenta
}}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-01-05 16:43:09 -06:00
<b-table-column
field="carrera"
label="Carrera"
v-slot="props"
centered
>
<span @click="servicios(props.row.idServicio)">{{
props.row.carrera
}}</span>
</b-table-column>
<b-table-column
field="fechaInicio"
truncate="10"
label="Fecha Inicio"
v-slot="props"
centered
>
<span @click="servicios(props.row.idServicio)">{{
fecha(props.row.fechaInicio)
}}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-01-05 16:43:09 -06:00
<b-table-column
field="fechaFin"
label="Fecha Fin"
v-slot="props"
centered
>
<span @click="servicios(props.row.idServicio)">{{
fecha(props.row.fechaFin)
}}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-01-05 16:43:09 -06:00
<b-table-column field="status" label="Status" v-slot="props" centered>
<span
@click="servicios(props.row.idServicio)"
class="tag"
:class="types(props.row.idStatus)"
>{{ props.row.status }}</span
>
</b-table-column>
2021-01-14 17:06:40 -06:00
<b-table-column
field="diaCreado"
label="Día de creación"
v-slot="props"
centered
>
<span @click="servicios(props.row.idServicio)">{{
fecha(props.row.diaCreado)
}}</span>
</b-table-column>
2021-01-05 16:43:09 -06:00
</b-table>
</section>
</div>
</div>
</template>
<script>
2021-05-13 14:22:56 -05:00
import axios from 'axios'
import moment from 'moment'
2021-01-05 16:43:09 -06:00
export default {
data() {
return {
2021-05-13 14:22:56 -05:00
idUsuario: '',
idTipoUsuario: '',
tipoUsuario: '',
2021-01-05 16:43:09 -06:00
data: [],
2021-05-13 14:22:56 -05:00
total: '',
2021-01-05 18:54:43 -06:00
isLoading: false,
2021-01-05 16:43:09 -06:00
page: 1,
perPage: 25,
2021-05-13 14:22:56 -05:00
numeroCuenta: '',
nombre: '',
idStatus: '',
2021-01-05 16:43:09 -06:00
token: {
headers: {
2021-05-13 14:22:56 -05:00
token: window.localStorage.getItem('token'),
2021-01-05 16:43:09 -06:00
},
},
2021-05-13 14:22:56 -05:00
}
2021-01-05 16:43:09 -06:00
},
methods: {
onPageChange(page) {
2021-05-13 14:22:56 -05:00
this.page = page
this.obtenerDatos()
2021-01-05 16:43:09 -06:00
},
types(idStatus) {
if (idStatus === 1) {
2021-05-13 14:22:56 -05:00
return 'is-dark'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 2) {
2021-05-13 14:22:56 -05:00
return 'is-info'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 3) {
2021-05-13 14:22:56 -05:00
return 'is-warning'
2021-01-25 19:56:31 -06:00
} else if (idStatus === 4) {
2021-05-13 14:22:56 -05:00
return 'is-link'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 5) {
2021-05-13 14:22:56 -05:00
return 'is-success'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 6) {
2021-05-13 14:22:56 -05:00
return 'is-success is-light'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 7) {
2021-05-13 14:22:56 -05:00
return 'is-danger'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 8) {
2021-05-13 14:22:56 -05:00
return 'is-danger'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 9) {
2021-05-13 14:22:56 -05:00
return 'is-danger'
2021-01-05 16:43:09 -06:00
} else if (idStatus === 10) {
// admin
2021-05-13 14:22:56 -05:00
return 'is-danger'
2021-01-05 16:43:09 -06:00
}
},
fecha(date) {
2021-05-13 14:22:56 -05:00
const fecha = moment(date.substr(0, 10))
2021-01-22 18:50:32 -06:00
2021-05-13 14:22:56 -05:00
return `${fecha.date()}/${fecha.month() + 1}/${fecha.year()}`
2021-01-05 16:43:09 -06:00
},
obtenerDatos(idStatus) {
2021-05-13 14:22:56 -05:00
this.isLoading = true
this.data = []
2021-01-05 16:43:09 -06:00
axios
.get(
`${process.env.api}/servicio/servicios_admin?pagina=${this.page}&idStatus=${this.idStatus}&nombre=${this.nombre}&numeroCuenta=${this.numeroCuenta}`,
this.token
)
.then((res) => {
2021-05-13 14:22:56 -05:00
const servicios = res.data.servicios
2021-01-05 16:43:09 -06:00
if (servicios.length !== 0) {
for (let i = 0; i < servicios.length; i++) {
this.data.push({
nombre: servicios[i].Usuario.nombre,
numeroCuenta: servicios[i].Usuario.usuario,
carrera: servicios[i].Carrera.carrera,
fechaInicio: servicios[i].fechaInicio,
fechaFin: servicios[i].fechaFin,
status: servicios[i].Status.status,
2021-01-14 17:06:40 -06:00
diaCreado: servicios[i].createdAt,
2021-01-05 16:43:09 -06:00
idStatus: servicios[i].Status.idStatus,
idServicio: servicios[i].idServicio,
2021-05-13 14:22:56 -05:00
})
2021-01-05 16:43:09 -06:00
}
}
2021-05-13 14:22:56 -05:00
let currentTotal = servicios.length
let contador
2021-01-05 16:43:09 -06:00
for (let i = 0; i < res.data.registros / 25 + 1; i++) {
2021-05-13 14:22:56 -05:00
contador = i
2021-01-05 16:43:09 -06:00
}
2021-05-13 14:22:56 -05:00
currentTotal = this.perPage * contador
this.total = currentTotal
2021-01-05 16:43:09 -06:00
})
2021-01-05 20:28:26 -06:00
2021-01-05 18:54:43 -06:00
.catch((error) => {
2021-05-13 14:22:56 -05:00
this.error(error.response.data.message)
2021-01-05 18:54:43 -06:00
})
.finally(() => {
2021-05-13 14:22:56 -05:00
this.isLoading = false
})
2021-01-05 16:43:09 -06:00
},
servicios(idServicio) {
2021-05-13 14:22:56 -05:00
window.localStorage.setItem('idServicio', idServicio)
this.$router.push('/admin/servicio')
2021-01-05 16:43:09 -06:00
},
getIdLocal() {
2021-05-13 14:22:56 -05:00
this.idUsuario = localStorage.getItem('idUsuario')
this.idTipoUsuario = localStorage.getItem('idTipoUsuario')
this.tipoUsuario = localStorage.getItem('tipoUsuario')
2021-01-05 20:28:26 -06:00
2021-05-13 14:22:56 -05:00
if (this.idTipoUsuario != 1 && this.tipoUsuario != 'admin') {
localStorage.clear()
this.$router.push('/')
2021-01-05 20:28:26 -06:00
}
2021-01-05 16:43:09 -06:00
},
2021-01-05 18:54:43 -06:00
error(msj) {
2021-05-13 14:22:56 -05:00
let salir = false
2021-01-05 20:28:26 -06:00
switch (msj) {
2021-05-13 14:22:56 -05:00
case 'invalid signature':
msj = 'Tu token no es valido, inicia sesión de nuevo.'
salir = true
break
case 'jwt expired':
msj = 'Tu sesión ha expirado, inicia sesión de nuevo.'
salir = true
break
case 'jwt malformed':
msj = 'No se encontro tu token, inicia sesión de nuevo.'
salir = true
break
case 'No hay token':
msj = 'Ocurrio un error al enviar tu token, inicia sesión de nuevo.'
salir = true
break
2021-01-05 18:54:43 -06:00
}
this.$buefy.dialog.alert({
2021-05-13 14:22:56 -05:00
title: 'Error',
2021-01-05 18:54:43 -06:00
message: msj,
2021-05-13 14:22:56 -05:00
type: 'is-danger',
2021-01-05 18:54:43 -06:00
hasIcon: true,
2021-05-13 14:22:56 -05:00
icon: 'alert-circle',
iconPack: 'mdi',
ariaRole: 'alertdialog',
2021-01-05 18:54:43 -06:00
ariaModal: true,
2021-05-13 14:22:56 -05:00
})
2021-01-06 16:00:41 -06:00
if (salir == true) {
2021-05-13 14:22:56 -05:00
localStorage.clear()
this.$router.push(`/`)
2021-01-05 18:54:43 -06:00
}
},
2021-01-05 16:43:09 -06:00
},
created() {
2021-05-13 14:22:56 -05:00
this.getIdLocal()
this.obtenerDatos(0)
2021-01-05 16:43:09 -06:00
},
2021-05-13 14:22:56 -05:00
}
2021-01-05 16:43:09 -06:00
</script>
<style>
.input:focus {
border: #1b3d70;
box-shadow: 0 0 8px 0 #1b3d70;
}
.select select:focus {
border-color: #1b3d70;
box-shadow: 0 0 8px 0 #1b3d70;
}
.select:not(.is-multiple):not(.is-loading)::after {
border-color: #1b3d70;
}
.pagination-link.is-current {
background-color: #1b3d70;
border-color: #1b3d70;
}
.b-table {
cursor: pointer;
}
</style>