Add vehicle repair functionality in Falukant module
- Implemented a new repairVehicle method in FalukantService to handle vehicle repairs, including cost calculation and precondition checks. - Updated FalukantController to expose the repairVehicle endpoint, allowing users to initiate repairs via the API. - Enhanced FalukantRouter to include a new route for vehicle repairs. - Modified BranchView component to add UI elements for repairing vehicles, including a dialog for repair confirmation and displaying repair details. - Updated German localization files to include translations related to vehicle repair actions, improving user experience for German-speaking users.
This commit is contained in:
@@ -108,14 +108,24 @@
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
v-if="v.status === 'available'"
|
||||
@click="openSendVehicleDialog(v.id)"
|
||||
:title="$t('falukant.branch.transport.sendSingle')"
|
||||
>
|
||||
{{ $t('falukant.branch.transport.send') }}
|
||||
</button>
|
||||
<span v-else class="no-action">—</span>
|
||||
<div class="vehicle-actions">
|
||||
<button
|
||||
v-if="v.status === 'available'"
|
||||
@click="openSendVehicleDialog(v.id)"
|
||||
:title="$t('falukant.branch.transport.sendSingle')"
|
||||
>
|
||||
{{ $t('falukant.branch.transport.send') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="v.status === 'available' && v.condition < 100"
|
||||
@click="openRepairVehicleDialog(v)"
|
||||
:title="$t('falukant.branch.transport.repairTooltip')"
|
||||
class="repair-button"
|
||||
>
|
||||
{{ $t('falukant.branch.transport.repair') }}
|
||||
</button>
|
||||
<span v-if="v.status !== 'available'" class="no-action">—</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -154,7 +164,7 @@
|
||||
<div v-if="sendVehicleDialog.show" class="modal-overlay" @click.self="closeSendVehicleDialog">
|
||||
<div class="modal-content">
|
||||
<h3>{{ $t('falukant.branch.transport.sendVehiclesTitle') }}</h3>
|
||||
<div class="send-vehicle-form">
|
||||
<div v-if="!sendVehicleDialog.success" class="send-vehicle-form">
|
||||
<label>
|
||||
{{ $t('falukant.branch.transport.selectTargetBranch') }}
|
||||
<select v-model.number="sendVehicleDialog.targetBranchId">
|
||||
@@ -173,6 +183,49 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="send-vehicle-success">
|
||||
<p>{{ $t('falukant.branch.transport.sendSuccess') }}</p>
|
||||
<div class="modal-buttons">
|
||||
<button @click="closeSendVehicleDialog">
|
||||
{{ $t('falukant.branch.transport.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Dialog zum Reparieren von Fahrzeugen -->
|
||||
<div v-if="repairVehicleDialog.show" class="modal-overlay" @click.self="closeRepairVehicleDialog">
|
||||
<div class="modal-content">
|
||||
<h3>{{ $t('falukant.branch.transport.repairVehicleTitle') }}</h3>
|
||||
<div class="repair-vehicle-form" v-if="repairVehicleDialog.vehicle">
|
||||
<div class="repair-info">
|
||||
<p>
|
||||
<strong>{{ $t('falukant.branch.transport.repairVehicleType') }}:</strong>
|
||||
{{ $t(`falukant.branch.vehicles.${repairVehicleDialog.vehicle.type.tr}`) }}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{{ $t('falukant.branch.transport.repairCurrentCondition') }}:</strong>
|
||||
{{ repairVehicleDialog.vehicle.condition }}%
|
||||
</p>
|
||||
<p>
|
||||
<strong>{{ $t('falukant.branch.transport.repairCost') }}:</strong>
|
||||
{{ formatMoney(repairVehicleDialog.repairCost) }}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{{ $t('falukant.branch.transport.repairBuildTime') }}:</strong>
|
||||
{{ formatBuildTime(repairVehicleDialog.buildTimeMinutes) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button @click="repairVehicle" class="repair-confirm-button">
|
||||
{{ $t('falukant.branch.transport.repairConfirm') }}
|
||||
</button>
|
||||
<button @click="closeRepairVehicleDialog">
|
||||
{{ $t('falukant.branch.transport.cancel') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -240,6 +293,13 @@ export default {
|
||||
vehicleIds: null,
|
||||
vehicleTypeId: null,
|
||||
targetBranchId: null,
|
||||
success: false,
|
||||
},
|
||||
repairVehicleDialog: {
|
||||
show: false,
|
||||
vehicle: null,
|
||||
repairCost: null,
|
||||
buildTimeMinutes: null,
|
||||
},
|
||||
};
|
||||
},
|
||||
@@ -625,6 +685,7 @@ export default {
|
||||
vehicleIds: null,
|
||||
vehicleTypeId: null,
|
||||
targetBranchId: null,
|
||||
success: false,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -635,6 +696,7 @@ export default {
|
||||
vehicleIds: vehicleList.map(v => v.id),
|
||||
vehicleTypeId: vehicleTypeId,
|
||||
targetBranchId: null,
|
||||
success: false,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -645,6 +707,7 @@ export default {
|
||||
vehicleIds: null,
|
||||
vehicleTypeId: null,
|
||||
targetBranchId: null,
|
||||
success: false,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -685,13 +748,85 @@ export default {
|
||||
|
||||
await apiClient.post('/api/falukant/transports', payload);
|
||||
await this.loadVehicles();
|
||||
this.closeSendVehicleDialog();
|
||||
alert(this.$t('falukant.branch.transport.sendSuccess'));
|
||||
this.sendVehicleDialog.success = true;
|
||||
} catch (error) {
|
||||
console.error('Error sending vehicles:', error);
|
||||
alert(this.$t('falukant.branch.transport.sendError'));
|
||||
}
|
||||
},
|
||||
|
||||
openRepairVehicleDialog(vehicle) {
|
||||
if (!vehicle || vehicle.status !== 'available' || vehicle.condition >= 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Kosten berechnen: Baupreis * 0.8 * (100 - zustand) / 100
|
||||
const baseCost = vehicle.type.cost || 0;
|
||||
const repairCost = Math.round(baseCost * 0.8 * (100 - vehicle.condition) / 100);
|
||||
const buildTimeMinutes = vehicle.type.buildTimeMinutes || 0;
|
||||
|
||||
this.repairVehicleDialog = {
|
||||
show: true,
|
||||
vehicle: vehicle,
|
||||
repairCost: repairCost,
|
||||
buildTimeMinutes: buildTimeMinutes,
|
||||
};
|
||||
},
|
||||
|
||||
closeRepairVehicleDialog() {
|
||||
this.repairVehicleDialog = {
|
||||
show: false,
|
||||
vehicle: null,
|
||||
repairCost: null,
|
||||
buildTimeMinutes: null,
|
||||
};
|
||||
},
|
||||
|
||||
formatMoney(amount) {
|
||||
if (amount == null) return '';
|
||||
try {
|
||||
return amount.toLocaleString(undefined, {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
} catch (e) {
|
||||
return String(amount);
|
||||
}
|
||||
},
|
||||
|
||||
formatBuildTime(minutes) {
|
||||
if (!minutes || minutes === 0) {
|
||||
return this.$t('falukant.branch.transport.repairBuildTimeInstant');
|
||||
}
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = minutes % 60;
|
||||
const parts = [];
|
||||
if (hours > 0) {
|
||||
parts.push(`${hours} ${this.$t('falukant.branch.transport.repairBuildTimeHours')}`);
|
||||
}
|
||||
if (mins > 0) {
|
||||
parts.push(`${mins} ${this.$t('falukant.branch.transport.repairBuildTimeMinutes')}`);
|
||||
}
|
||||
return parts.length > 0 ? parts.join(' ') : '0 ' + this.$t('falukant.branch.transport.repairBuildTimeMinutes');
|
||||
},
|
||||
|
||||
async repairVehicle() {
|
||||
if (!this.repairVehicleDialog.vehicle) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await apiClient.post(`/api/falukant/vehicles/${this.repairVehicleDialog.vehicle.id}/repair`);
|
||||
await this.loadVehicles();
|
||||
this.closeRepairVehicleDialog();
|
||||
alert(this.$t('falukant.branch.transport.repairSuccess'));
|
||||
this.$refs.statusBar?.fetchStatus();
|
||||
} catch (error) {
|
||||
console.error('Error repairing vehicle:', error);
|
||||
const errorMessage = error.response?.data?.message || this.$t('falukant.branch.transport.repairError');
|
||||
alert(errorMessage);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -808,4 +943,59 @@ h2 {
|
||||
.modal-buttons button:last-child:hover {
|
||||
background-color: #5a6268;
|
||||
}
|
||||
|
||||
.vehicle-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.repair-button {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.repair-button:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
.repair-vehicle-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.repair-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.repair-info p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.repair-confirm-button {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.repair-confirm-button:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
.send-vehicle-success {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
margin-top: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.send-vehicle-success p {
|
||||
margin: 0;
|
||||
font-size: 1.1em;
|
||||
color: #28a745;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user