diff --git a/frontend/src/components/falukant/RevenueSection.vue b/frontend/src/components/falukant/RevenueSection.vue index a9ddb25..58fc62d 100644 --- a/frontend/src/components/falukant/RevenueSection.vue +++ b/frontend/src/components/falukant/RevenueSection.vue @@ -28,8 +28,8 @@ {{ calculateProductProfit(product).absolute }} {{ calculateProductProfit(product).perMinute }} -
- + {{ city.regionName }} @@ -59,6 +59,7 @@ return { isRevenueTableOpen: false, loadingPrices: new Set(), + betterPricesMap: {}, // Map von productId zu betterPrices Array }; }, computed: { @@ -83,14 +84,22 @@ } }, products: { - handler() { + handler(newProducts, oldProducts) { + // Leere betterPricesMap wenn sich die Produktliste ändert + if (oldProducts && oldProducts.length > 0) { + this.betterPricesMap = {}; + } if (this.isRevenueTableOpen && this.currentRegionId !== null) { this.loadPricesForAllProducts(); } }, deep: true }, - currentRegionId(newVal) { + currentRegionId(newVal, oldVal) { + // Leere betterPricesMap wenn sich die Region ändert + if (oldVal !== null && oldVal !== undefined) { + this.betterPricesMap = {}; + } if (this.isRevenueTableOpen && newVal !== null) { this.loadPricesForAllProducts(); } @@ -111,7 +120,9 @@ if (this.loadingPrices.has(product.id)) continue; this.loadingPrices.add(product.id); try { + // Verwende den gerundeten Preis aus calculateProductRevenue (wie gewollt) const currentPrice = parseFloat(this.calculateProductRevenue(product).absolute); + const { data } = await apiClient.get('/api/falukant/products/prices-in-cities', { params: { productId: product.id, @@ -119,15 +130,19 @@ currentRegionId: this.currentRegionId } }); - this.$set(product, 'betterPrices', data || []); + // Speichere betterPrices in einem separaten Map, nicht auf dem product Objekt + this.$set(this.betterPricesMap, product.id, data || []); } catch (error) { console.error(`Error loading prices for product ${product.id}:`, error); - this.$set(product, 'betterPrices', []); + this.$set(this.betterPricesMap, product.id, []); } finally { this.loadingPrices.delete(product.id); } } }, + getBetterPrices(productId) { + return this.betterPricesMap[productId] || []; + }, getCityPriceClass(branchType) { if (branchType === 'store') return 'city-price-green'; if (branchType === 'production') return 'city-price-orange';