pcpuma_unam_operador/components/operador/AdminEquipo.vue

295 lines
8.3 KiB
Vue
Raw Normal View History

2022-05-31 04:22:49 +00:00
<template>
<div class="column is-4">
<h3 class="is-size-4 mb-4">Administrador</h3>
2022-07-23 00:04:13 +00:00
<b-field label="Status" v-if="equipo.carrito.modulo.modulo">
2022-05-31 04:22:49 +00:00
<b-select icon="list-status" v-model="idStatus" expanded rounded>
<option
2022-07-10 06:56:46 +00:00
v-for="(s, index) in status"
:key="index"
2022-07-05 05:33:43 +00:00
:value="s.id_status"
v-show="equipo.id_equipo"
2022-07-13 23:21:49 +00:00
:disabled="disabledS(s.id_status, equipo.status.id_status)"
2022-05-31 04:22:49 +00:00
>
{{ s.status }}
</option>
</b-select>
</b-field>
2022-07-10 06:56:46 +00:00
<b-field label="Motivo" v-if="mostrarMotivo">
<b-input v-model="motivo" type="textarea" maxlength="150" />
</b-field>
2022-07-23 00:04:13 +00:00
<b-field label="Tipo de conector" v-if="equipo.carrito.modulo.modulo">
2022-07-10 06:56:46 +00:00
<b-select icon="list-status" v-model="idTipoEntrada" expanded rounded>
2022-07-23 00:13:21 +00:00
<option disabled :value="null">Tipo de conector</option>
2022-07-10 06:56:46 +00:00
<option
v-for="(tipoEntrada, index) in tipoEntradas"
:key="index"
2022-07-13 23:21:49 +00:00
:value="tipoEntrada.id_tipo_entrada"
:disabled="disabledT(tipoEntrada.id_tipo_entrada)"
2022-07-10 06:56:46 +00:00
>
2022-07-13 23:21:49 +00:00
{{ tipoEntrada.tipo_entrada }}
2022-07-10 06:56:46 +00:00
</option>
</b-select>
</b-field>
2022-07-23 00:04:13 +00:00
<b-field label="Software" v-if="equipo.carrito.modulo.modulo">
2022-05-31 04:22:49 +00:00
<b-select icon="list-status" v-model="idPrograma" expanded rounded>
2022-07-23 00:13:21 +00:00
<option disabled :value="null">Software</option>
2022-07-10 06:56:46 +00:00
<option
v-for="(programa, index) in programas"
:key="index"
2022-07-13 23:21:49 +00:00
:value="programa.id_programa"
:disabled="disabledP(programa.id_programa)"
2022-07-10 06:56:46 +00:00
>
2022-07-13 23:21:49 +00:00
{{ programa.programa }}
2022-05-31 04:22:49 +00:00
</option>
</b-select>
</b-field>
2022-07-10 06:56:46 +00:00
<b-field
label="Cambiar nombre del equipo"
2022-07-23 00:04:13 +00:00
v-if="equipo.carrito.modulo.modulo"
2022-07-10 06:56:46 +00:00
>
<b-input
icon="list-status"
v-model="nuevoNombreEquipo"
placeholder="Nuevo nombre del equipo"
rounded
/>
2022-05-31 04:22:49 +00:00
</b-field>
<b-button
class="my-5"
2022-07-22 04:02:08 +00:00
label="Actualizar Información"
2022-05-31 04:22:49 +00:00
type="is-link"
2022-07-05 05:33:43 +00:00
v-show="equipo.id_equipo"
2022-07-10 06:56:46 +00:00
@click="
2022-07-11 14:15:10 +00:00
$alertsGenericos.imprimirWarning(
$buefy,
2022-07-10 06:56:46 +00:00
`¿Estas segur@ que deseas cambiar esta información?`,
updateInformacion
2022-07-10 06:56:46 +00:00
)
"
2022-05-31 04:22:49 +00:00
:disabled="mostrarBoton()"
rounded
expanded
2022-07-22 04:02:08 +00:00
/>
2022-05-31 04:22:49 +00:00
</div>
</template>
<script>
import axios from 'axios'
export default {
props: {
operador: { type: Object, required: true },
equipo: { type: Object, required: true },
updateIsLoading: { type: Function, required: true },
buscar: { type: Function, required: true },
},
data() {
return {
status: [],
2022-07-23 00:13:21 +00:00
idStatus: '',
2022-07-10 06:56:46 +00:00
tipoEntradas: [],
2022-07-23 00:13:21 +00:00
idTipoEntrada: null,
programas: [],
idPrograma: null,
2022-07-10 06:56:46 +00:00
2022-07-23 00:13:21 +00:00
nuevoNombreEquipo: '',
2022-07-10 06:56:46 +00:00
motivo: '',
mostrarMotivo: false,
2022-05-31 04:22:49 +00:00
}
},
methods: {
mostrarBoton() {
if (
2022-07-22 23:42:36 +00:00
(this.idStatus != this.equipo.status.id_status && this.motivo) ||
this.idTipoEntrada ||
this.idPrograma ||
(this.nuevoNombreEquipo && this.nuevoNombreEquipo != this.equipo.equipo)
2022-05-31 04:22:49 +00:00
)
return false
2022-07-22 23:42:36 +00:00
else return true
2022-05-31 04:22:49 +00:00
},
2022-07-13 23:21:49 +00:00
disabledS(idStatus, idStatusEquipo) {
if (idStatus > 1 && idStatus < 4) return true
if (idStatusEquipo === 2 || idStatusEquipo === 3) return true
else return false
},
disabledT(idTipoEntrada) {
for (let i = 0; i < this.equipo.tiposEntradas.length; i++) {
if (
this.equipo.tiposEntradas[i].tipoEntrada.id_tipo_entrada ===
idTipoEntrada
)
return true
}
},
disabledP(idPrograma) {
for (let i = 0; i < this.equipo.programas.length; i++) {
if (this.equipo.programas[i].programa.id_programa === idPrograma)
return true
}
},
updateInformacion() {
if (
this.idStatus != this.equipo.status.id_status ||
this.nuevoNombreEquipo != ''
) {
this.updateEquipo()
this.motivo = ''
}
for (let i = 0; i < this.programas.length; i++) {
if (this.idPrograma) {
if (
2022-07-11 08:54:28 +00:00
this.equipo.programas.length === 0 ||
this.idPrograma != this.equipo.programas[i].programa.id_programa
) {
this.updateProgramas()
this.idPrograma = ''
}
}
}
for (let i = 0; i < this.tipoEntradas.length; i++) {
if (this.idTipoEntrada != '') {
if (
2022-07-11 08:53:51 +00:00
this.equipo.tiposEntradas.length === 0 ||
this.idTipoEntrada !=
2022-07-11 08:53:51 +00:00
this.equipo.tiposEntradas[i].tipoEntrada.id_tipo_entrada
) {
this.updateTipoEntradas()
this.idTipoEntrada = ''
}
}
}
},
2022-07-10 06:56:46 +00:00
updateEquipo() {
2022-05-31 04:22:49 +00:00
const data = {
2022-07-05 05:33:43 +00:00
id_equipo: this.equipo.id_equipo,
2022-07-10 06:56:46 +00:00
equipo: this.nuevoNombreEquipo
? this.nuevoNombreEquipo
: this.equipo.equpo,
id_operador: this.operador.id_operador,
2022-07-05 05:33:43 +00:00
id_status:
this.idStatus != this.equipo.status.id_status ? this.idStatus : null,
2022-07-10 06:56:46 +00:00
motivo: this.motivo,
idPrograma: this.idPrograma ? this.idPrograma : null,
2022-05-31 04:22:49 +00:00
}
this.updateIsLoading(true)
axios
2022-07-19 16:41:33 +00:00
.put(`${process.env.api}/equipo`, data, this.$getToken.token())
2022-05-31 04:22:49 +00:00
.then((res) => {
this.buscar()
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
2022-05-31 04:22:49 +00:00
})
.catch((err) => {
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-05-31 04:22:49 +00:00
})
},
updateProgramas() {
const data = {
id_equipo: this.equipo.id_equipo,
id_programa: this.idPrograma,
}
this.updateIsLoading(true)
axios
2022-07-19 16:41:33 +00:00
.post(
`${process.env.api}/equipo-programa`,
data,
this.$getToken.token()
)
.then((res) => {
this.buscar()
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
})
.catch((err) => {
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
})
},
updateTipoEntradas() {
const data = {
id_equipo: this.equipo.id_equipo,
id_tipo_entrada: this.idTipoEntrada,
}
this.updateIsLoading(true)
axios
.post(
`${process.env.api}/equipo-tipo-entrada`,
data,
2022-07-19 16:41:33 +00:00
this.$getToken.token()
)
.then((res) => {
this.buscar()
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
})
.catch((err) => {
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
})
},
2022-05-31 04:22:49 +00:00
obtenerCatalogoStatus() {
axios
2022-07-19 16:41:33 +00:00
.get(`${process.env.api}/status`, this.$getToken.token())
2022-05-31 04:22:49 +00:00
.then((res) => {
this.status = res.data
})
.catch((err) => {
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-05-31 04:22:49 +00:00
})
},
obtenerCatalogoProgramas() {
axios
2022-07-19 16:41:33 +00:00
.get(`${process.env.api}/institucion-programa`, this.$getToken.token())
2022-05-31 04:22:49 +00:00
.then((res) => {
2022-07-10 06:56:46 +00:00
this.programas = res.data
})
.catch((err) => {
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-07-10 06:56:46 +00:00
})
},
obtenerCatalogoTipoEntradas() {
axios
2022-07-19 16:41:33 +00:00
.get(
`${process.env.api}/institucion-tipo-entrada`,
this.$getToken.token()
)
2022-07-10 06:56:46 +00:00
.then((res) => {
this.tipoEntradas = res.data
2022-05-31 04:22:49 +00:00
})
.catch((err) => {
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-05-31 04:22:49 +00:00
})
},
},
watch: {
equipo() {
this.obtenerCatalogoProgramas()
2022-07-10 06:56:46 +00:00
this.obtenerCatalogoTipoEntradas()
2022-07-05 05:33:43 +00:00
this.idStatus = this.equipo.status.id_status
this.idCarrito = this.equipo.carrito.id_carrito
if (this.equipo.programa)
this.idPrograma = this.equipo.programa.id_programa
2022-05-31 04:22:49 +00:00
},
2022-07-10 06:56:46 +00:00
idStatus(value) {
if (value != this.equipo.status.id_status) this.mostrarMotivo = true
},
2022-05-31 04:22:49 +00:00
},
created() {
2022-07-05 05:33:43 +00:00
if (this.operador.tipoUsuario.id_tipo_usuario === 3) {
2022-05-31 04:22:49 +00:00
this.obtenerCatalogoStatus()
2022-07-05 05:33:43 +00:00
this.idStatus = this.equipo.status.id_status
2022-05-31 04:22:49 +00:00
}
},
}
</script>
<style></style>