Files
servicio_social_front/components/admin/inputTableA.vue
T

270 lines
6.8 KiB
Vue
Raw Normal View History

2021-01-05 16:43:09 -06:00
<template>
2021-06-08 13:19:51 -05:00
<div>
<h3 class="title">Servicios Sociales</h3>
2021-01-05 16:43:09 -06:00
<div class="columns">
2021-05-14 18:47:35 -05:00
<b-field class="column" label="Número de Cuenta">
<b-input
type="text"
placeholder="No.Cuenta"
icon="school"
maxlength="9"
2021-06-07 23:42:00 -05:00
v-model="busqueda.numeroCuenta"
2021-05-15 01:18:15 -05:00
@keyup.enter.native="obtenerServicios()"
2021-06-07 23:42:00 -05:00
rounded
2021-05-14 18:47:35 -05:00
></b-input>
</b-field>
2021-01-05 16:43:09 -06:00
2021-05-14 18:47:35 -05:00
<b-field class="column" label="Nombre">
<b-input
type="name"
placeholder="Nombre"
icon="account"
2021-06-07 23:42:00 -05:00
v-model="busqueda.nombre"
2021-05-15 01:18:15 -05:00
@keyup.enter.native="obtenerServicios()"
2021-06-07 23:42:00 -05:00
rounded
2021-05-14 18:47:35 -05:00
></b-input>
</b-field>
2021-01-05 16:43:09 -06:00
2021-05-14 18:47:35 -05:00
<b-field class="column" label="Status">
2021-06-07 23:42:00 -05:00
<b-select icon="information" v-model="busqueda.idStatus" rounded>
2021-05-14 18:47:35 -05:00
<option value="">Status</option>
<option
v-for="(s, i) in status"
:key="i"
:value="s.idStatus"
v-show="i < 10"
2021-01-05 16:43:09 -06:00
>
2021-05-14 18:47:35 -05:00
{{ s.status }}
</option>
</b-select>
</b-field>
2021-01-05 16:43:09 -06:00
2021-06-07 23:42:00 -05:00
<div class="column is-align-self-center">
<b-button type="is-info" @click="obtenerServicios()" expanded rounded>
Buscar
</b-button>
</div>
2021-01-05 16:43:09 -06:00
</div>
2021-05-14 18:47:35 -05:00
<b-table
:data="data"
:total="total"
:current-page="page"
:per-page="perPage"
:selected.sync="servicioSeleccionado"
:loading="isLoading"
2021-06-07 23:42:00 -05:00
:row-class="(row, index) => 'pointer'"
2021-05-14 18:47:35 -05:00
@page-change="onPageChange"
hoverable
striped
paginated
backend-pagination
>
<b-table-column
field="numeroCuenta"
label="Número de Cuenta"
v-slot="props"
centered
>
<span>{{ props.row.Usuario.usuario }}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-05-15 01:18:15 -05:00
<b-table-column field="nombre" label="Nombre" v-slot="props" centered>
<span>{{ props.row.Usuario.nombre }}</span>
</b-table-column>
2021-05-14 18:47:35 -05:00
<b-table-column field="carrera" label="Carrera" v-slot="props" centered>
<span>{{ props.row.Carrera.carrera }}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-05-14 18:47:35 -05:00
<b-table-column
field="fechaInicio"
label="Fecha Inicio"
v-slot="props"
centered
>
<span>{{ fecha(props.row.fechaInicio) }}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-05-14 18:47:35 -05:00
<b-table-column
field="fechaFin"
label="Fecha Fin"
v-slot="props"
centered
>
<span>{{ fecha(props.row.fechaFin) }}</span>
</b-table-column>
2021-01-14 17:06:40 -06:00
2021-05-14 18:47:35 -05:00
<b-table-column
field="fechaCreado"
label="Día de Creación"
v-slot="props"
centered
>
<span>{{ fecha(props.row.createdAt) }}</span>
</b-table-column>
<b-table-column field="status" label="Status" v-slot="props" centered>
<span :class="types(props.row.Status.idStatus)">{{
props.row.Status.status
}}</span>
</b-table-column>
</b-table>
2021-06-07 23:42:00 -05:00
</div>
2021-01-05 16:43:09 -06:00
</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-14 18:47:35 -05:00
admin: {},
2021-06-07 23:42:00 -05:00
servicioSeleccionado: {},
2021-05-14 18:47:35 -05:00
status: [],
2021-01-05 16:43:09 -06:00
data: [],
page: 1,
perPage: 25,
2021-05-14 18:47:35 -05:00
total: 0,
isLoading: false,
2021-06-07 23:42:00 -05:00
busqueda: {
idStatus: '',
},
busquedaAnterior: {},
2021-05-14 18:47:35 -05:00
token: {},
2021-05-13 14:22:56 -05:00
}
2021-01-05 16:43:09 -06:00
},
methods: {
types(idStatus) {
2021-05-14 18:47:35 -05:00
let style = 'tag'
if (idStatus === 1) style += ' is-dark'
if (idStatus === 2) style += ' is-info'
if (idStatus === 3) style += ' is-warning'
if (idStatus === 4) style += ' is-link'
if (idStatus === 5) style += ' is-success'
if (idStatus === 6) style += ' is-success is-light'
2021-05-15 00:58:24 -05:00
if (idStatus >= 7 && idStatus <= 9) style += ' is-danger'
2021-05-14 18:47:35 -05:00
return style
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-06-07 23:42:00 -05: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
},
2021-05-14 18:47:35 -05:00
onPageChange(page) {
this.page = page
this.obtenerServicios()
},
getLocalhostInfo() {
this.admin.idUsuario = localStorage.getItem('idUsuario')
this.admin.idTipoUsuario = Number(localStorage.getItem('idTipoUsuario'))
2021-05-14 18:47:35 -05:00
this.admin.tipoUsuario = localStorage.getItem('tipoUsuario')
this.token = {
headers: {
2021-05-16 22:14:27 -05:00
token: localStorage.getItem('token'),
2021-05-14 18:47:35 -05:00
},
}
},
obtenerServicios() {
let data = ''
2021-01-05 16:43:09 -06:00
2021-05-14 18:47:35 -05:00
this.isLoading = true
if (
2021-06-07 23:42:00 -05:00
this.busqueda.numeroCuenta != this.busquedaAnterior.numeroCuenta ||
this.busqueda.nombre != this.busquedaAnterior.nombre ||
this.busqueda.idStatus != this.busquedaAnterior.idStatus
2021-05-14 18:47:35 -05:00
) {
this.page = 1
2021-06-07 23:42:00 -05:00
this.busquedaAnterior.numeroCuenta = this.busqueda.numeroCuenta
this.busquedaAnterior.nombre = this.busqueda.nombre
this.busquedaAnterior.idStatus = this.busqueda.idStatus
2021-05-14 18:47:35 -05:00
}
2021-06-07 23:42:00 -05:00
if (this.busqueda.idStatus) data += `&idStatus=${this.busqueda.idStatus}`
if (this.busqueda.nombre) data += `&nombre=${this.busqueda.nombre}`
if (this.busqueda.numeroCuenta)
2021-06-08 12:21:19 -05:00
data += `&numeroCuenta=${this.busqueda.numeroCuenta}`
2021-01-05 16:43:09 -06:00
axios
.get(
2021-05-14 18:47:35 -05:00
`${process.env.api}/servicio/servicios_admin?&pagina=${this.page}${data}`,
2021-01-05 16:43:09 -06:00
this.token
)
.then((res) => {
2021-05-14 18:47:35 -05:00
this.data = res.data.serviciosAdmin
this.total = res.data.count
this.isLoading = false
2021-01-05 18:54:43 -06:00
})
2021-05-14 18:47:35 -05:00
.catch((err) => {
2021-05-13 14:22:56 -05:00
this.isLoading = false
2021-05-14 18:47:35 -05:00
this.imprimirError(err.response.data)
2021-05-13 14:22:56 -05:00
})
2021-01-05 16:43:09 -06:00
},
2021-05-14 18:47:35 -05:00
obtenerCatalogoStatus() {
axios
.get(`${process.env.api}/status`, this.token)
.then((res) => {
this.status = res.data
})
.catch((err) => {
this.imprimirError(err.response.data)
})
2021-01-05 16:43:09 -06:00
},
2021-05-14 18:47:35 -05:00
imprimirError(err) {
2021-01-05 18:54:43 -06:00
this.$buefy.dialog.alert({
2021-05-13 14:22:56 -05:00
title: 'Error',
2021-05-14 18:47:35 -05:00
message: err.message,
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',
ariaRole: 'alertdialog',
2021-01-05 18:54:43 -06:00
ariaModal: true,
2021-05-13 14:22:56 -05:00
})
2021-05-14 18:47:35 -05:00
if (err.err === 'token error') {
2021-05-13 14:22:56 -05:00
localStorage.clear()
2021-05-14 18:47:35 -05:00
this.$router.push('/')
2021-01-05 18:54:43 -06:00
}
},
2021-05-14 18:47:35 -05:00
},
watch: {
servicioSeleccionado() {
2021-05-16 22:14:27 -05:00
localStorage.setItem('idServicio', this.servicioSeleccionado.idServicio)
2021-05-14 18:47:35 -05:00
this.$router.push(`/admin/servicio`)
},
2021-01-05 16:43:09 -06:00
},
created() {
2021-05-14 18:47:35 -05:00
this.getLocalhostInfo()
if (this.admin.idTipoUsuario === 1) {
this.obtenerCatalogoStatus()
this.obtenerServicios()
}
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;
}
2021-05-14 18:47:35 -05:00
2021-01-05 16:43:09 -06:00
.select select:focus {
border-color: #1b3d70;
box-shadow: 0 0 8px 0 #1b3d70;
}
2021-05-14 18:47:35 -05:00
2021-01-05 16:43:09 -06:00
.select:not(.is-multiple):not(.is-loading)::after {
border-color: #1b3d70;
}
2021-05-14 18:47:35 -05:00
2021-01-05 16:43:09 -06:00
.pagination-link.is-current {
background-color: #1b3d70;
border-color: #1b3d70;
}
2021-05-14 18:47:35 -05:00
2021-06-07 23:42:00 -05:00
.pointer {
2021-01-05 16:43:09 -06:00
cursor: pointer;
}
</style>