Files

254 lines
10 KiB
Vue

<template>
<v-container grid-list-xs>
<material-card color="black" title="Show Item">
<v-layout align-left id="printMe" justify-left wrap class="my-3">
<h3 class="ml-3 CSSD-font"> Item - {{ MedicalCenter }}</h3>
<v-flex xs12>
<hr class="v-divider theme--light">
</v-flex>
<v-layout row wrap class="ml-4 align-center">
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">Item ID :</span>
<span class="headline ml-1 CSSD-font" style="letter-spacing:0 !important">
{{ data.id }}
</span>
</div>
</v-flex>
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">Name :</span>
<span class="headline ml-1 CSSD-font" style="letter-spacing:0 !important">
{{ data.name }}
</span>
</div>
</v-flex>
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">Size :</span>
<span class="headline ml-1 CSSD-font" style="letter-spacing:0 !important">
{{ data.size }}
</span>
</div>
</v-flex>
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">UDI :</span>
<span class="headline ml-1 CSSD-font" style="letter-spacing:0 !important">
{{ data.udi }}
</span>
</div>
</v-flex>
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">Specific :</span>
<span class="headline ml-1 CSSD-font" style="letter-spacing:0 !important">
{{ data.specific }}
</span>
</div>
</v-flex>
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">Register User :</span>
<span class="headline ml-2 CSSD-font" style="letter-spacing:0 !important">
{{ data.user ? data.user.name : '' }}
</span>
</div>
</v-flex>
<v-flex xs12 md6 sm6>
<div class>
<span class="title CSSD-font">Date Register:</span>
<span class="headline ml-2 CSSD-font" style="letter-spacing:0 !important">
{{ data.created_at }}
</span>
</div>
</v-flex>
</v-layout>
<v-layout align-left justify-left row wrap class="my-3" v-if="data.files && data.files.length">
<h3 class="CSSD-font">Image</h3>
<v-flex xs12>
<hr class="v-divider theme--light"/>
</v-flex>
<v-layout row wrap class="mt-3">
<v-flex xs6 md2 sm2 v-for="(file, key) in data.files" :key="key">
<template v-if="file.file_type == 'document'">
<a target="_blank" :href="'/'+file.thumbnail">
<v-icon class="mr-2 caption">fas fa-check</v-icon>
{{ file.file_name }}</a>
</template>
<template v-else>
<img :src="file.thumbnail" style="width: 100%" @click="openLightbox(key)"/>
</template>
</v-flex>
</v-layout>
</v-layout>
<v-flex xs12></v-flex>
<v-layout align-left justify-left row wrap class="my-3">
<h3 class="ml-3 CSSD-font">Barcode And QRCode Image</h3>
<v-flex xs12>
<hr class="v-divider theme--light">
</v-flex>
<v-layout row wrap class="ml-4 align-center mt-2">
<v-flex xs12 md6 sm6 v-if="barcodeimg">
<img :src="barcodeimg" class="barcode-container"><br/>
<span class="CSSD-font">Item ID : {{ data.id }}</span>
</v-flex>
<v-flex xs12 md6 sm6 v-if="QRCodeimg" class="WM-Align-C">
<img :src="QRCodeimg" class="WM-Width-150">
</v-flex>
</v-layout>
</v-layout>
</v-layout>
<v-layout row wrap align-center justify-center style="text-align:center">
<v-flex class xs12 md12 sm12>
<v-btn class="WM-NoShadow WM-Outline-Btn WM-Border WM-Border-Black" @click="addItem()">
<v-icon class="black--text">keyboard_arrow_left</v-icon>
<span class="black--text">Back</span>
</v-btn>
<v-btn class="WM-CyanBlueGradient-BG" @click="print" style="padding:10px 60px">
<v-icon class="white--text mr-2 caption">fas fa-print</v-icon>
<span class="white--text">Print</span>
</v-btn>
<v-btn color="orange" class="mr-2" style="padding:10px 60px" @click="editItem(data.id)">
<v-icon class="white--text mr-1 caption">fas fa-pen</v-icon>
<span>Edit</span>
</v-btn>
</v-flex>
</v-layout>
</material-card>
<vue-image-lightbox
v-if="showLightbox"
:media="lightboxImages"
:index="lightboxIndex"
@close="showLightbox = false"
/>
</v-container>
</template>
<script>
import {urls} from "@show/config/urls";
import axios from "axios";
import toast from "@/services/global/toast.service";
import VueImageLightbox from "vue-image-lightbox";
import 'vue-image-lightbox/dist/vue-image-lightbox.min.css'
export default {
data: () => ({
data: {},
QRCodeimg: '',
barcodeimg: '',
MedicalCenter: '',
showLightbox: false,
lightboxIndex: 0,
lightboxImages: [],
}),
components: {
VueImageLightbox,
},
computed: {
imagesOnly() {
return this.data.files && this.data.files.length ? this.data.files.filter(file => file.file_type !== 'document') : [];
},
},
methods: {
async load(id) {
try {
const result = await axios.get(urls.showItem(id));
if (result.status == 200) {
this.data = result.data.data;
if (this.data) {
this.generateBarcode(this.data);
this.MedicalCenter = this.data.user.medical_center.name;
}
}
} catch (error) {
console.error("Error loading data:", error);
}
},
async loadByUdi(udi) {
try {
const result = await axios.get(urls.showItemByUdi(udi));
if (result.status == 200) {
this.data = result.data.data;
if (this.data) {
this.generateBarcode(this.data);
this.MedicalCenter = this.data.user.medical_center.name;
}
}
} catch (error) {
console.error("Error loading data:", error);
}
},
async generateBarcode(item) {
let code = item.udi;
if (code) {
const result = await axios.post(urls.Barcode(code, 'Item'));
if (result && result.status == 200) {
this.QRCodeimg = result.data.data.QRCode ? result.data.data.QRCode : null;
this.barcodeimg = result.data.data.Barcode ? result.data.data.Barcode : null;
}
} else {
toast.error('An error occurred while generating the barcode . please first set UDI');
}
},
editItem(itemId) {
window.location.href = '/item/' + itemId + '/edit';
},
addItem() {
window.location.href = '/add-item';
},
print() {
const prtHtml = document.getElementById("printMe").innerHTML;
// Get all stylesheets HTML
let stylesHtml = "";
for (const node of [
...document.querySelectorAll('link[rel="stylesheet"], style')
]) {
stylesHtml += node.outerHTML;
}
// Open the print window
const WinPrint = window.open(
"",
"",
"left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0"
);
WinPrint.document.write(`<!DOCTYPE html><html><head>${stylesHtml}</head><body> ${prtHtml}</body></html>`);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
},
openLightbox(index) {
this.lightboxIndex = index;
this.showLightbox = false;
this.$nextTick(() => {
this.showLightbox = true;
});
}
},
created() {
if (this.$route.params.item) {
this.load(this.$route.params.item);
} else if (this.$route.params.udi) {
this.loadByUdi(this.$route.params.udi);
}
this.lightboxImages = this.imagesOnly && this.imagesOnly.length ? this.imagesOnly.map(file => ({
src: file.thumbnail,
thumb: file.thumbnail,
})) : [];
},
};
</script>
<style scoped lang="scss">
.barcode-container {
width: 100%;
max-width: 290px;
}
</style>