Add synchronous price calculation method: Introduce calcRegionalSellPriceSync for improved performance in price calculations when worthPercent is known. Refactor getAllProductPricesInRegion to utilize this new method, enhancing efficiency by reducing database calls. Update BranchView to manage product prices cache with regionId for better data handling.
This commit is contained in:
@@ -68,7 +68,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
toggleDropdown() {
|
||||
console.log("toggleDropdown", 'clicked');
|
||||
if (this.disabled) return;
|
||||
this.isOpen = !this.isOpen;
|
||||
},
|
||||
|
||||
@@ -360,6 +360,7 @@ export default {
|
||||
vehicles: [],
|
||||
activeTab: 'production',
|
||||
productPricesCache: {}, // Cache für regionale Preise: { productId: price }
|
||||
productPricesCacheRegionId: null, // regionId, für die der Cache gültig ist
|
||||
tabs: [
|
||||
{ value: 'production', label: 'falukant.branch.tabs.production' },
|
||||
{ value: 'inventory', label: 'falukant.branch.tabs.inventory' },
|
||||
@@ -569,20 +570,20 @@ export default {
|
||||
async loadProductPricesForCurrentBranch() {
|
||||
if (!this.selectedBranch || !this.selectedBranch.regionId) {
|
||||
this.productPricesCache = {};
|
||||
this.productPricesCacheRegionId = null;
|
||||
return;
|
||||
}
|
||||
if (this.productPricesCacheRegionId === this.selectedBranch.regionId && Object.keys(this.productPricesCache).length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Lade alle Preise für die Region auf einmal (Bulk-Request)
|
||||
try {
|
||||
const startTime = performance.now();
|
||||
const { data } = await apiClient.get('/api/falukant/products/prices-in-region', {
|
||||
params: {
|
||||
regionId: this.selectedBranch.regionId
|
||||
}
|
||||
});
|
||||
const loadTime = performance.now() - startTime;
|
||||
console.log(`[BranchView] Product prices loaded in ${loadTime.toFixed(2)}ms`);
|
||||
this.productPricesCache = data.prices || {};
|
||||
this.productPricesCacheRegionId = this.selectedBranch.regionId;
|
||||
} catch (error) {
|
||||
console.error(`Error loading product prices for region ${this.selectedBranch.regionId}:`, error);
|
||||
// Fallback: Lade Preise einzeln (alte Methode)
|
||||
@@ -607,6 +608,7 @@ export default {
|
||||
}
|
||||
}
|
||||
this.productPricesCache = prices;
|
||||
this.productPricesCacheRegionId = this.selectedBranch?.regionId ?? null;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user