Files
cssd-back/resources/js/vue/views/Label/List.vue
T
2020-07-04 13:48:53 +04:30

290 lines
9.3 KiB
Vue

<template>
<div class>
<v-container fluid>
<material-card class color="black" title="All Labels" text>
<v-layout align-center wrap class="my-3">
<v-flex xs12 md3 sm3 class="WM-FlexCenter pl-3">
<v-icon class="fas fa-sort-numeric-up mr-2 WM-Margin-B-8"></v-icon>
<v-text-field class="py-3" v-model="filter.label_id" label="Label ID" color="black"></v-text-field>
</v-flex>
<v-flex xs12 md3 sm3 class="WM-FlexCenter pl-3" v-if="$hasRole('Admin')">
<v-icon class="fa fa-hospital-o mr-2 WM-Margin-B-8"></v-icon>
<v-autocomplete
class="py-3 pr-3"
v-model="filter.medical_center_id"
@change="fillUsers"
item-text="name"
item-value="id"
label="Hospital"
color="black"
:items="medicalCenters"
></v-autocomplete>
</v-flex>
<v-flex xs12 md3 sm3 class="WM-FlexCenter pl-3">
<v-icon class="fas fa-sort-numeric-up mr-2 WM-Margin-B-8"></v-icon>
<!-- <v-autocomplete
class="py-3 pr-3"
v-model="filter.user_id"
item-text="name"
item-value="id"
label="Users"
color="black"
:items="users"
></v-autocomplete> -->
<v-text-field class="py-3" v-model="filter.sterilizer_id" label="Sterilizer ID" color="black"></v-text-field>
</v-flex>
<v-flex xs12 md3 sm3 class="WM-FlexCenter pl-3">
<v-icon class="fas fa-sort-numeric-up mr-2 WM-Margin-B-8"></v-icon>
<v-text-field class="py-3" v-model="filter.cycle_number" label="Cycle Number" color="black"></v-text-field>
</v-flex>
<v-flex xs12 md2 sm3 class="ml-3">
<v-btn class="WM-CyanBlueGradient-BG" style="padding:10px 60px" @click="load()">
<v-icon class="white--text mr-2 caption">fas fa-search</v-icon>
<span class="white--text">Filter</span>
</v-btn>
</v-flex>
<v-spacer></v-spacer>
<v-flex xs12 md2 sm2 class="text-xs-right">
<router-link :to="{name: 'AddLabel'}">
<v-btn class="WM-NoShadow WM-Outline-Btn WM-Border WM-Border-Black">
<v-icon class="black--text mr-2 caption">fas fa-plus</v-icon>
<span class="black--text">Add</span>
</v-btn>
</router-link>
</v-flex>
</v-layout>
<v-divider></v-divider>
<v-layout align-center wrap class="my-3">
<v-flex md12>
<v-data-table :headers="headers" :items="items" 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.user ? item.user.name : '' }}</td>
<td class="title font-weight-light">{{ item.cycle_number }}</td>
<td class="title font-weight-light">{{ item.sterilizer_id }}</td>
<td class="text-xs-right FlexBtn Height-MD-60">
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" color="cyan" class="mr-2" @click="show(item.id)">
<v-icon class="white--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 }">
<router-link
class="LinkBtn"
v-if="$hasRole('Admin') || item.user_id == $store.state.user.id"
:to="{name: 'EditLabel', params: {label: item.id}}"
>
<v-btn v-bind="attrs" v-on="on" color="orange" 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="pink"
class="WM-ActionButton mr-2"
@click="remove(item.id)"
v-if="$hasRole('Admin') || item.user_id == $store.state.user.id"
>
<v-icon class="white--text mr-2 caption">fas fa-times</v-icon>
<span>Remove</span>
</v-btn>
</template>
<span>Remove</span>
</v-tooltip>
<v-tooltip bottom open-on-hover>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" color="orange darken-1 mr-2" @click="generateBarcode(item.id, 'Label')">
<v-icon class="white--text mr-1 caption">fas fa-barcode</v-icon>
<span>Generate Barcode</span>
</v-btn>
</template>
<span>Generate Barcode</span>
</v-tooltip>
</td>
</template>
</v-data-table>
</v-flex>
</v-layout>
<v-divider></v-divider>
<div class="text-xs-center" v-if="lastPage > 1">
<v-pagination color="black" v-model="currentPage" :length="lastPage" :total-visible="6"></v-pagination>
</div>
<v-layout row wrap align-center justify-center class="mt-3">
<router-link to="/dashboard">
<v-btn class="WM-NoShadow WM-Outline-Btn WM-Border WM-Border-Black ml-5">
<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-layout>
</material-card>
</v-container>
</div>
</template>
<script>
import { ApiService } from "@/services";
import { urls } from "@/config/urls";
import { mapMutations, mapGetters } from "vuex";
export default {
data: () => ({
headers: [
{
sortable: true,
text: "Label ID",
value: "Label ID"
},
{
sortable: true,
text: "Hospital",
value: "Hospital"
},
{
sortable: false,
text: "User",
value: "User"
},
{
sortable: false,
text: "Cycle Number",
value: "Cycle Number"
},
{
sortable: false,
text: "SterilizerID",
value: "SterilizerID"
},
{
sortable: false,
text: "Action",
value: "action",
align: "right"
}
],
filter: {},
items: [],
medicalCenters: [],
users: [],
currentPage: 1,
lastPage: 1
}),
created() {
this.load();
},
methods: {
...mapMutations("modal", ["changeCurrentModal"]),
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.listLabel(filter));
if (result && result.status == 200) {
this.items = result.data.data.data;
this.currentPage = result.data.data.current_page;
this.lastPage = result.data.data.last_page;
}
this.loadMedicalCenters();
},
async loadMedicalCenters() {
const result = await ApiService.get(urls.listFilterItemsTestResult);
if (result && result.status == 200) {
this.medicalCenters = result.data.data.MedicalCenters;
}
},
async fillUsers() {
const result = await ApiService.get(
urls.listOpertorMedicalCenter(this.form.medicalCenterId)
);
if (result && result.status == 200) {
this.users = result.data.data.users;
}
},
async show(testResultId) {
const result = await ApiService.get(urls.showLabel(testResultId));
if (result && result.status == 200) {
this.changeCurrentModal({
modal: "modal-label-show",
properties: { result, width :40 }
});
}
},
async remove(testResultId) {
const result = await ApiService.delete(
urls.removeLabel(testResultId)
);
if (result && result.status == 200) {
for (const key in this.items) {
if (
this.items.hasOwnProperty(key) &&
this.items[key].id == testResultId
) {
this.items.splice(key, 1);
}
}
}
},
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 }
});
}
}
},
computed: {
...mapGetters("modal", ["getModalResult"])
},
watch: {
currentPage(page) {
this.load(page);
},
getModalResult(testResult) {
for (const key in this.items) {
if (
this.items.hasOwnProperty(key) &&
this.items[key].id == testResult.id
) {
this.items[key] = testResult;
}
}
}
}
};
</script>
<style>
.v-btn--floating {
padding: 0 !important;
}
.theme--light.v-btn.v-btn--flat {
color: rgba(0, 0, 0, 0.87) !important;
}
.v-btn--floating,
.v-btn--icon:before {
border-radius: 50% !important;
}
</style>