ff-admin/src/components/admin/unit/inspection/FileInput.vue

82 lines
2.2 KiB
Vue
Raw Normal View History

2025-05-16 10:27:08 +02:00
<template>
<div class="flex flex-col h-fit w-full border border-primary rounded-md">
<div class="bg-primary p-2 text-white flex flex-row justify-between items-center">
<p>{{ inspectionPoint.title }}</p>
</div>
<div class="p-2">
<p v-if="inspectionPoint.description" class="pb-2">Beschreibung: {{ inspectionPoint.description }}</p>
<hr v-if="inspectionPoint.description" />
<label :for="inspectionPoint.id">{{ inspectionPoint.others == "pdf" ? "PDF" : "Bild" }}-Datei</label>
<button
:primary="value != ''"
:primary-outline="value == ''"
type="button"
class="flex flex-row gap-2"
@click="($refs.fileInput as HTMLInputElement).click()"
2025-07-10 13:22:38 +02:00
:disabled="!editable"
>
<span v-if="value == ''">Datei wählen</span><span v-else>Datei gewählt</span>
<CheckIcon v-if="value != ''" class="h-5 w-5" />
</button>
2025-05-16 10:27:08 +02:00
<input
ref="fileInput"
2025-05-16 10:27:08 +02:00
:id="inspectionPoint.id"
:name="inspectionPoint.id"
type="file"
:accept="inspectionPoint.others == 'pdf' ? 'application/pdf' : 'image/*'"
hidden
@change="selectFile"
2025-05-16 10:27:08 +02:00
/>
</div>
</div>
</template>
<script setup lang="ts">
import { defineComponent, type PropType } from "vue";
2025-06-04 12:49:42 +02:00
import type { InspectionPointViewModel } from "@/viewmodels/admin/unit/inspection/inspectionPlan.models";
import { CheckIcon } from "@heroicons/vue/24/outline";
2025-05-16 10:27:08 +02:00
</script>
<script lang="ts">
export default defineComponent({
props: {
inspectionPoint: {
type: Object as PropType<InspectionPointViewModel>,
required: true,
},
modelValue: {
type: String,
default: "",
},
2025-07-10 13:22:38 +02:00
editable: {
type: Boolean,
default: true,
},
2025-05-16 10:27:08 +02:00
},
emits: {
"update:model-value": (p: string) => {
return true;
},
"update:upload": (p: File | null) => {
return true;
},
},
2025-05-16 10:27:08 +02:00
computed: {
value: {
get() {
return this.modelValue;
},
set(val: string | number) {
this.$emit("update:model-value", val.toString());
},
},
},
methods: {
selectFile(e: Event) {
this.$emit("update:upload", (e.target as HTMLInputElement).files?.[0] ?? null);
this.value = "set";
},
},
2025-05-16 10:27:08 +02:00
});
</script>