Änderung: Verbesserung der Berechnungslogik in HouseView.vue

Änderungen:
- Hinzugefügte Überprüfungen in den Methoden `getRenovationCost`, `getWorth` und `buyCost`, um sicherzustellen, dass die erforderlichen Daten vorhanden sind, bevor Berechnungen durchgeführt werden.
- Diese Anpassungen erhöhen die Robustheit der Preisberechnungen und verhindern Fehler bei fehlenden Informationen.
This commit is contained in:
Torsten Schulz (local)
2025-09-12 15:24:50 +02:00
parent 1d72372511
commit 2a3a2b258f

View File

@@ -125,6 +125,7 @@ export default {
return new Intl.NumberFormat('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value); return new Intl.NumberFormat('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value);
}, },
getRenovationCost(key, value) { getRenovationCost(key, value) {
if (!this.userHouse || !this.userHouse.houseType) return this.formatPrice(0);
const base = this.userHouse.houseType.cost || 0; const base = this.userHouse.houseType.cost || 0;
const weights = { roofCondition: 0.25, wallCondition: 0.25, floorCondition: 0.25, windowCondition: 0.25 }; const weights = { roofCondition: 0.25, wallCondition: 0.25, floorCondition: 0.25, windowCondition: 0.25 };
const weight = weights[key] || 0; const weight = weights[key] || 0;
@@ -141,12 +142,13 @@ export default {
}, },
getWorth() { getWorth() {
const vals = Object.values(this.status); const vals = Object.values(this.status);
if (!vals.length) return this.formatPrice(0); if (!vals.length || !this.houseType) return this.formatPrice(0);
const avg = vals.reduce((s, v) => s + v, 0) / vals.length; const avg = vals.reduce((s, v) => s + v, 0) / vals.length;
const price = this.houseType.cost || 0; const price = this.houseType.cost || 0;
return this.formatPrice(price * avg / 100 * 0.8); return this.formatPrice(price * avg / 100 * 0.8);
}, },
buyCost(house) { buyCost(house) {
if (!house || !house.houseType) return this.formatPrice(0);
const avg = (house.roofCondition + house.wallCondition + house.floorCondition + house.windowCondition) / 4; const avg = (house.roofCondition + house.wallCondition + house.floorCondition + house.windowCondition) / 4;
return this.formatPrice(house.houseType.cost * avg / 100); return this.formatPrice(house.houseType.cost * avg / 100);
}, },