Files
cssd-front/src/views/Cycle/List.vue
T

282 lines
14 KiB
Vue

<template>
<div class>
<v-container fluid>
<material-card class color="black" title="All Cycles" text>
<v-layout align-center wrap class="px-3">
<v-flex xs12 sm4 lg2 xl1 class="WM-FlexCenter">
<v-icon class="fa fa-align-left mr-2 WM-Margin-B-8"/>
<v-text-field class="pt-3 pr-3" v-model="filter.cycle_id" label="Cycle ID"
color="black"/>
</v-flex>
<v-flex xs12 sm4 lg2 xl1 class="WM-FlexCenter">
<v-icon class="fas fa-sort-numeric-up mr-2 WM-Margin-B-8"/>
<v-text-field class="pt-3 pr-3" v-model="filter.sterilizer_id" label="Sterilizer ID"
color="black"/>
</v-flex>
<v-flex xs12 sm4 lg2 xl1 class="WM-FlexCenter">
<v-icon class="fas fa-sort-numeric-up mr-2 WM-Margin-B-8"/>
<v-text-field class="pt-3 pr-3" v-model="filter.cycle_number" label="Cycle Number"
color="black"/>
</v-flex>
<v-flex xs12 sm6 lg3 xl2 class="WM-FlexCenter" v-if="$hasRole('Admin')">
<v-icon class="fa fa-hospital-o mr-2 WM-Margin-B-8"/>
<v-autocomplete class="pt-3 pr-3" v-model="filter.medical_center_id" item-text="name"
item-value="id" label="Hospital" color="black" :items="medicalCenters"
:clearable="true"/>
</v-flex>
<v-flex xs12 sm6 lg3 xl2 class="WM-FlexCenter">
<v-icon class="far fa-calendar-alt mr-2 WM-Margin-B-8"/>
<v-menu class="pt-3 pr-3" lazy :close-on-content-click="true" transition="v-scale-transition"
offset-y v-model="Menu" style="width: 100%;">
<v-text-field style="padding-top:0 !important" required slot="activator" label="Date"
color="black" class="" v-model="filter.date">
</v-text-field>
<v-date-picker color="pink" no-title v-model="filter.date"
:date-format="date => new Date(date).toDateString()"/>
</v-menu>
</v-flex>
<v-spacer/>
<v-flex xs12 sm12 md12 lg12 xl3 class="WM-Align-R">
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" color="WM-Tooltip-Btn WM-Outline-Btn WM-Border WM-Margin-BT-0 WM-Border-Black mr-2" @click="load()">
<v-icon class="black--text caption">fas fa-search</v-icon>
</v-btn>
</template>
<span>Filter</span>
</v-tooltip>
<v-btn class="WM-Outline-Btn WM-Border mr-2 WM-Margin-BT-0 WM-Border-Black" @click="download()" style="padding: 10px 30px;">
<v-icon class="black--text mr-2 caption">fas fa-share-square</v-icon>
<span class="black--text">EXPORT</span>
</v-btn>
<router-link :to="{ name: 'AddCycle' }">
<v-btn class="WM-CyanBlueGradient-BG WM-Margin-BT-0" style="padding:10px 30px">
<v-icon class="white--text mr-2 caption">fas fa-plus</v-icon>
<span class="white--text">Add</span>
</v-btn>
</router-link>
</v-flex>
</v-layout>
<v-layout class="px-3 my-3">
<v-divider/>
</v-layout>
<v-layout align-center wrap class="px-3 my-3">
<v-flex md12>
<v-data-table :headers="headers" :items="packages" hide-actions>
<template slot="headerCell" slot-scope="{ header }">
<span class="subheading font-weight-light text-white text--darken-3"
v-text="header.text"/>
</template>
<template slot="items" slot-scope="{ item }">
<td class="title font-weight-light">{{ item.id }}</td>
<td class="title font-weight-light">
{{ (item.user && item.user.medical_center) ? item.user.medical_center.name : '' }}
</td>
<td class="title font-weight-light">{{ item.sterilizer_id }}</td>
<td class="title font-weight-light">
<span v-for="(label , index) in item.labels" :key="index">
{{ label.id }} <span v-if="index !== item.labels.length-1">,</span>
</span>
</td>
<td class="title font-weight-light">{{ item.cycle_number }}</td>
<td class="title font-weight-light">{{ item.date }}</td>
<td class="text-xs-right FlexBtn Height-MD-60 justify-self-end">
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" color="light-gray" class="mr-2"
@click="show(item.id)">
<v-icon class="black--text mr-1 caption">fas fa-eye</v-icon>
<span>Show</span>
</v-btn>
</template>
<span>Show</span>
</v-tooltip>
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" color="light-gray" class="mr-2"
@click="generateBarcode(item.id, 'Cycle')">
<v-icon class="black--text mr-1 caption">fas fa-barcode</v-icon>
<span>Generate Barcode</span>
</v-btn>
</template>
<span>Generate Barcode</span>
</v-tooltip>
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<router-link class="LinkBtn"
v-if="$hasRole('Admin') || item.user_id == $store.state.user.id"
:to="{ name: 'EditCycle', params: { cycle: item.id } }">
<v-btn v-bind="attrs" v-on="on" color="black" class="mr-2">
<v-icon class="white--text mr-1 caption">fas fa-pen</v-icon>
<span>Edit</span>
</v-btn>
</router-link>
</template>
<span>Edit</span>
</v-tooltip>
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" color="red" class="WM-ActionButton mr-2"
@click="removeModal(item.id)"
v-if="$hasRole('Admin') || item.user_id == $store.state.user.id">
<v-icon class="white--text mr-2 caption">fas fa-trash</v-icon>
<span>Remove</span>
</v-btn>
</template>
<span>Remove</span>
</v-tooltip>
</td>
</template>
</v-data-table>
</v-flex>
</v-layout>
<v-divider/>
<div class="text-xs-center mt-2" v-if="lastPage > 1">
<v-pagination color="black" v-model="currentPage" :length="lastPage"
:total-visible="6"/>
</div>
<v-layout row wrap align-center justify-center class="px-3 mt-3">
<router-link to="/dashboard">
<v-btn class="WM-NoShadow WM-Outline-Btn WM-Border WM-Border-Black">
<v-icon class="black--text mr-2 caption">fas fa-chevron-left</v-icon>
<span class="black--text">Back</span>
</v-btn>
</router-link>
<v-spacer/>
</v-layout>
</material-card>
</v-container>
</div>
</template>
<script>
import {ApiService} from "@/services";
import {urls} from "@/config/urls";
import {mapMutations, mapGetters} from "vuex";
export default {
metaInfo() {
return {
title: this.$route.meta.title,
meta: this.$route.meta.metaTags || []
}
},
data: () => ({
headers: [
{sortable: false, text: "ID", value: "Cycle ID"},
{sortable: false, text: "Hospital", value: "Hospital"},
{sortable: false, text: "Sterilizer ID", value: "Sterilizer ID"},
{sortable: false, text: "Label IDs", value: "Label IDs"},
{sortable: false, text: "Cycle Number", value: "Cycle Number"},
{sortable: false, text: "Date", value: "date"},
{sortable: false, text: "Action", value: "action", align: "center", width: '10%'}
],
filter: {},
Menu: false,
packages: [],
currentPage: 1,
lastPage: 1,
medicalCenters: []
}),
created() {
this.load();
},
methods: {
...mapMutations("modal", ["changeCurrentModal", "closeModal"]),
async load(page = 1) {
let filter = '?';
for (const key in this.filter) {
if (this.filter.hasOwnProperty(key)) {
filter += `${key}=${this.filter[key]}&`;
}
}
filter += (page) ? `page=${page}` : `page=1`;
const result = await ApiService.get(
urls.listCycle(filter)
);
if (result && result.status == 200) {
const {data, meta} = result.data;
this.packages = data;
this.currentPage = meta.current_page;
this.lastPage = meta.last_page;
}
this.loadMedicalCenters();
},
async show(id) {
const result = await ApiService.get(urls.showCycle(id));
if (result && result.status == 200) {
this.changeCurrentModal({
modal: "modal-cycle-show",
properties: {result}
});
}
},
async generateBarcode(code, type) {
const result = await ApiService.post(urls.Barcode(code, type));
if (result && result.status == 200) {
this.changeCurrentModal({
modal: "modal-barcode-barcode",
properties: {result}
});
}
},
removeModal(id) {
this.changeCurrentModal({
modal: "modal-user-confirmation",
properties: {width: '30'},
success: async () => {
const result = await ApiService.delete(urls.removeCycle(id));
if (result && result.status == 200) {
for (const key in this.packages) {
if (this.packages.hasOwnProperty(key) && this.packages[key].id == id) {
this.packages.splice(key, 1);
}
}
}
this.closeModal();
},
});
},
async loadMedicalCenters() {
const result = await ApiService.get(urls.listFilterItemsTestResult);
if (result && result.status == 200) {
this.medicalCenters = result.data.data.MedicalCenters;
}
},
async download() {
const result = await ApiService.get(urls.exportCycles());
if (result && result.status == 200) {
window.open(result.download, '_blank');
}
},
},
computed: {
...mapGetters("modal", ["getModalResult"])
},
watch: {
currentPage(page) {
this.load(page);
}
}
};
</script>
<style>
.v-btn--floating {
padding: 0 !important;
}
.theme--light.v-btn.v-btn--flat {
color: rgba(0, 0, 0, .87) !important;
}
.v-btn--floating,
.v-btn--icon:before {
border-radius: 50% !important;
}
</style>