2025-04-28 12:29:44 +02:00
|
|
|
<template>
|
2025-05-21 09:20:22 +02:00
|
|
|
<MainTemplate title="Fahrzeug erfassen">
|
2025-04-28 12:29:44 +02:00
|
|
|
<template #diffMain>
|
|
|
|
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
|
|
|
|
<form class="flex flex-col gap-4 py-2 w-full max-w-xl mx-auto" @submit.prevent="triggerCreate">
|
|
|
|
<VehicleTypeSearchSelect title="Typ" v-model="selectedType" />
|
|
|
|
<div>
|
|
|
|
<label for="name">Bezeichnung</label>
|
|
|
|
<input type="text" id="name" required />
|
|
|
|
</div>
|
2025-05-13 12:30:57 +02:00
|
|
|
<ScanInput name="code" label="Code" :required="false" />
|
2025-05-21 09:10:41 +02:00
|
|
|
<div>
|
|
|
|
<label for="commissioned">In-Betrieb-Nahme</label>
|
|
|
|
<input type="date" id="commissioned" required />
|
|
|
|
</div>
|
2025-04-28 12:29:44 +02:00
|
|
|
<div>
|
|
|
|
<label for="location">Verortung (optional)</label>
|
|
|
|
<input type="text" id="location" />
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-row justify-end gap-2">
|
|
|
|
<RouterLink
|
|
|
|
:to="{ name: 'admin-unit-vehicle' }"
|
|
|
|
primary-outline
|
|
|
|
button
|
|
|
|
class="w-fit!"
|
|
|
|
:disabled="status == 'loading' || status?.status == 'success'"
|
|
|
|
>
|
|
|
|
abbrechen
|
|
|
|
</RouterLink>
|
|
|
|
<button primary type="submit" class="w-fit!" :disabled="status == 'loading'">speichern</button>
|
|
|
|
<Spinner v-if="status == 'loading'" class="my-auto" />
|
|
|
|
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
|
|
|
<FailureXMark v-else-if="status?.status == 'failed'" />
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</MainTemplate>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import { mapActions, mapState } from "pinia";
|
|
|
|
import MainTemplate from "@/templates/Main.vue";
|
|
|
|
import { useVehicleStore } from "@/stores/admin/unit/vehicle/vehicle";
|
|
|
|
import type { CreateVehicleViewModel } from "@/viewmodels/admin/unit/vehicle/vehicle.models";
|
|
|
|
import Spinner from "@/components/Spinner.vue";
|
|
|
|
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
|
|
|
import FailureXMark from "@/components/FailureXMark.vue";
|
|
|
|
import { useVehicleTypeStore } from "@/stores/admin/unit/vehicleType/vehicleType";
|
|
|
|
import VehicleTypeSearchSelect from "@/components/search/VehicleTypeSearchSelect.vue";
|
2025-07-15 13:19:59 +02:00
|
|
|
import ScanInput from "@/components/scanner/ScanInput.vue";
|
2025-04-28 12:29:44 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
|
|
|
timeout: null as any,
|
|
|
|
selectedType: "" as string,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState(useVehicleTypeStore, ["vehicleTypes"]),
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
try {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
} catch (error) {}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(useVehicleStore, ["createVehicle"]),
|
|
|
|
triggerCreate(e: any) {
|
|
|
|
if (this.selectedType == null) return;
|
|
|
|
let formData = e.target.elements;
|
|
|
|
let createVehicle: CreateVehicleViewModel = {
|
|
|
|
name: formData.name.value,
|
2025-05-13 12:30:57 +02:00
|
|
|
code: formData.code.value || null,
|
2025-04-28 12:29:44 +02:00
|
|
|
location: formData.location.value,
|
|
|
|
vehicleTypeId: this.selectedType,
|
2025-05-21 09:10:41 +02:00
|
|
|
commissioned: formData.commissioned.value,
|
2025-04-28 12:29:44 +02:00
|
|
|
};
|
|
|
|
this.status = "loading";
|
|
|
|
this.createVehicle(createVehicle)
|
|
|
|
.then((res) => {
|
|
|
|
this.status = { status: "success" };
|
|
|
|
|
|
|
|
this.timeout = setTimeout(() => {
|
|
|
|
this.$router.push({
|
|
|
|
name: "admin-unit-vehicle-overview",
|
|
|
|
params: {
|
|
|
|
vehicleId: res.data,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, 1500);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.status = { status: "failed" };
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|