Add transport and inventory update handling in BranchView component
- Implemented socket event listeners for 'transport_arrived' and 'inventory_updated' to manage real-time updates in the BranchView component. - Enhanced event handling logic to refresh vehicle and inventory data based on the selected branch, improving user experience and data accuracy. - Updated the component to ensure proper cleanup of socket listeners on component destruction, maintaining optimal performance.
This commit is contained in:
@@ -283,6 +283,8 @@ export default {
|
||||
if (this.socket) {
|
||||
this.socket.on('falukantUpdateStatus', (data) => this.handleEvent({ event: 'falukantUpdateStatus', ...data }));
|
||||
this.socket.on('falukantBranchUpdate', (data) => this.handleEvent({ event: 'falukantBranchUpdate', ...data }));
|
||||
this.socket.on('transport_arrived', (data) => this.handleEvent({ event: 'transport_arrived', ...data }));
|
||||
this.socket.on('inventory_updated', (data) => this.handleEvent({ event: 'inventory_updated', ...data }));
|
||||
}
|
||||
},
|
||||
|
||||
@@ -294,6 +296,8 @@ export default {
|
||||
if (this.socket) {
|
||||
this.socket.off('falukantUpdateStatus');
|
||||
this.socket.off('falukantBranchUpdate');
|
||||
this.socket.off('transport_arrived');
|
||||
this.socket.off('inventory_updated');
|
||||
}
|
||||
},
|
||||
|
||||
@@ -549,6 +553,40 @@ export default {
|
||||
this.$refs.revenueSection.refresh && this.$refs.revenueSection.refresh();
|
||||
}
|
||||
break;
|
||||
case 'transport_arrived':
|
||||
// Leerer Transport angekommen - Fahrzeug wurde zurückgeholt
|
||||
if (eventData.empty && eventData.branch_id) {
|
||||
// Nur aktualisieren, wenn der betroffene Branch ausgewählt ist
|
||||
if (this.selectedBranch && this.selectedBranch.id === eventData.branch_id) {
|
||||
// Fahrzeuge im Transport-Tab aktualisieren
|
||||
this.loadVehicles();
|
||||
// Laufende Transporte im Inventar-Tab aktualisieren
|
||||
if (this.$refs.saleSection) {
|
||||
this.$refs.saleSection.loadTransports();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'inventory_updated':
|
||||
// Inventar wurde aktualisiert (durch Transporte)
|
||||
if (eventData.branch_id) {
|
||||
// Nur aktualisieren, wenn der betroffene Branch ausgewählt ist
|
||||
if (this.selectedBranch && this.selectedBranch.id === eventData.branch_id) {
|
||||
// Inventar im Inventar-Tab aktualisieren
|
||||
if (this.$refs.saleSection) {
|
||||
this.$refs.saleSection.loadInventory();
|
||||
this.$refs.saleSection.loadTransports();
|
||||
}
|
||||
// Lager aktualisieren
|
||||
if (this.$refs.storageSection) {
|
||||
this.$refs.storageSection.loadStorageData();
|
||||
}
|
||||
if (this.$refs.productionSection) {
|
||||
this.$refs.productionSection.loadStorage();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log('Unhandled event:', eventData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user