|
@@ -239,10 +239,11 @@ import Sidebar from '@/components/Sidebar.vue'
|
|
|
import TopBar from '@/components/TopBar.vue'
|
|
import TopBar from '@/components/TopBar.vue'
|
|
|
import VehicleModal from '@/components/VehicleModal.vue'
|
|
import VehicleModal from '@/components/VehicleModal.vue'
|
|
|
import { useUserStore } from '@/stores/useUserStore'
|
|
import { useUserStore } from '@/stores/useUserStore'
|
|
|
|
|
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
|
|
|
import { Role } from '@/Enum/Role'
|
|
import { Role } from '@/Enum/Role'
|
|
|
import { useVehiculeStore, Vehicule } from '@/stores/useVehiculeStore'
|
|
import { useVehiculeStore, Vehicule } from '@/stores/useVehiculeStore'
|
|
|
import VehiculeService from '@/services/VehiculeService'
|
|
import VehiculeService from '@/services/VehiculeService'
|
|
|
-import CompanyService from '@/services/CompanyService'
|
|
|
|
|
|
|
+//import CompanyService from '@/services/CompanyService'
|
|
|
import type { Vehicle, Company } from '@/types'
|
|
import type { Vehicle, Company } from '@/types'
|
|
|
|
|
|
|
|
// Variables réactives pour les données
|
|
// Variables réactives pour les données
|
|
@@ -266,27 +267,27 @@ const typeFilter = ref('')
|
|
|
const statusFilter = ref('')
|
|
const statusFilter = ref('')
|
|
|
|
|
|
|
|
// États pour les modals
|
|
// États pour les modals
|
|
|
-const showAddForm = ref(false)
|
|
|
|
|
-const editingVehicle = ref(null)
|
|
|
|
|
-const deletingVehicle = ref(null)
|
|
|
|
|
-const viewingVehicle = ref(null)
|
|
|
|
|
|
|
+const showAddForm = ref<boolean>(false)
|
|
|
|
|
+const editingVehicle = ref<Vehicle | null>(null)
|
|
|
|
|
+const deletingVehicle = ref<Vehicle | null>(null)
|
|
|
|
|
+const viewingVehicle = ref<Vehicle | null>(null)
|
|
|
|
|
|
|
|
// Formulaire
|
|
// Formulaire
|
|
|
const formData = ref({
|
|
const formData = ref({
|
|
|
id: null,
|
|
id: null,
|
|
|
brand: '',
|
|
brand: '',
|
|
|
model: '',
|
|
model: '',
|
|
|
- licensePlate: '',
|
|
|
|
|
|
|
+ number_places: 0,
|
|
|
year: new Date().getFullYear(),
|
|
year: new Date().getFullYear(),
|
|
|
type: 'van',
|
|
type: 'van',
|
|
|
companyId: '',
|
|
companyId: '',
|
|
|
- capacity: null,
|
|
|
|
|
|
|
+ immatriculation: '',
|
|
|
color: '',
|
|
color: '',
|
|
|
status: 'active',
|
|
status: 'active',
|
|
|
image: null,
|
|
image: null,
|
|
|
notes: ''
|
|
notes: ''
|
|
|
})
|
|
})
|
|
|
-const vehicleStore = useVehiculeStore()
|
|
|
|
|
|
|
+ useVehiculeStore().fetchVehicles()
|
|
|
|
|
|
|
|
// Fonctions pour charger les données
|
|
// Fonctions pour charger les données
|
|
|
const loadVehicles = async () => {
|
|
const loadVehicles = async () => {
|
|
@@ -300,7 +301,8 @@ const loadVehicles = async () => {
|
|
|
result = await VehiculeService.getVehicles(pagination.value.page, pagination.value.limit)
|
|
result = await VehiculeService.getVehicles(pagination.value.page, pagination.value.limit)
|
|
|
} else {
|
|
} else {
|
|
|
// Récupérer l'ID de l'entreprise de l'utilisateur connecté
|
|
// Récupérer l'ID de l'entreprise de l'utilisateur connecté
|
|
|
- const companyId = userStore.companyId || 1 // Fallback temporaire
|
|
|
|
|
|
|
+ const companyId = useUserCompanyStore().id
|
|
|
|
|
+ console.log('ID de l\'entreprise:',companyId)
|
|
|
result = await VehiculeService.getVehiclesByCompany(companyId, pagination.value.page, pagination.value.limit)
|
|
result = await VehiculeService.getVehiclesByCompany(companyId, pagination.value.page, pagination.value.limit)
|
|
|
console.log('Véhicules de l\'entreprise:', result)
|
|
console.log('Véhicules de l\'entreprise:', result)
|
|
|
}
|
|
}
|
|
@@ -314,31 +316,32 @@ const loadVehicles = async () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const loadCompanies = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- const result = await CompanyService.getCompanies(1, 100) // Charger toutes les entreprises
|
|
|
|
|
- companies.value = result.companies
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('Erreur lors du chargement des entreprises:', error)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// const loadCompanies = async () => {
|
|
|
|
|
+// try {
|
|
|
|
|
+// const result = await CompanyService.getCompanies(1, 100) // Charger toutes les entreprises
|
|
|
|
|
+// companies.value = result.companies
|
|
|
|
|
+// } catch (error) {
|
|
|
|
|
+// console.error('Erreur lors du chargement des entreprises:', error)
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+const createNewVehicle = async (vehicule: Vehicle) => {
|
|
|
|
|
|
|
|
-const createNewVehicle = async (vehicule) => {
|
|
|
|
|
try {
|
|
try {
|
|
|
// Transformation des données pour correspondre au format attendu par le backend
|
|
// Transformation des données pour correspondre au format attendu par le backend
|
|
|
const vehiculeData: Vehicule = {
|
|
const vehiculeData: Vehicule = {
|
|
|
- number_places: vehicule.capacity || 0,
|
|
|
|
|
|
|
+ number_places: vehicule.number_places || 0,
|
|
|
color: vehicule.color || '',
|
|
color: vehicule.color || '',
|
|
|
type: vehicule.type || '',
|
|
type: vehicule.type || '',
|
|
|
- immatriculation: vehicule.licensePlate || '',
|
|
|
|
|
|
|
+ immatriculation: vehicule.immatriculation || '',
|
|
|
model: `${vehicule.model}` || '',
|
|
model: `${vehicule.model}` || '',
|
|
|
- companyId: vehicule.companyId || userStore.companyId || 1,
|
|
|
|
|
|
|
+ companyId: useUserCompanyStore().id,
|
|
|
driverId: 0
|
|
driverId: 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
console.log('Données envoyées au backend:', vehiculeData)
|
|
console.log('Données envoyées au backend:', vehiculeData)
|
|
|
|
|
|
|
|
- const newVehicle = await vehicleStore.createVehicle(vehiculeData)
|
|
|
|
|
|
|
+ const newVehicle = await useVehiculeStore().createVehicle(vehiculeData)
|
|
|
|
|
|
|
|
console.log('Véhicule créé avec succès:', newVehicle)
|
|
console.log('Véhicule créé avec succès:', newVehicle)
|
|
|
// Recharger la liste après création
|
|
// Recharger la liste après création
|
|
@@ -377,32 +380,32 @@ const getCompanyName = (companyId) => {
|
|
|
return company ? company.name : 'Inconnue'
|
|
return company ? company.name : 'Inconnue'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const getVehicleTypeName = (type) => {
|
|
|
|
|
|
|
+const getVehicleTypeName = (type: string) => {
|
|
|
const types = {
|
|
const types = {
|
|
|
car: 'Voiture',
|
|
car: 'Voiture',
|
|
|
van: 'Fourgon',
|
|
van: 'Fourgon',
|
|
|
bus: 'Bus',
|
|
bus: 'Bus',
|
|
|
truck: 'Camion'
|
|
truck: 'Camion'
|
|
|
}
|
|
}
|
|
|
- return types[type] || type
|
|
|
|
|
|
|
+ return types[type as keyof typeof types] || type
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const getStatusName = (status) => {
|
|
|
|
|
|
|
+const getStatusName = (status: string) => {
|
|
|
const statuses = {
|
|
const statuses = {
|
|
|
active: 'Actif',
|
|
active: 'Actif',
|
|
|
inactive: 'Inactif',
|
|
inactive: 'Inactif',
|
|
|
maintenance: 'En maintenance'
|
|
maintenance: 'En maintenance'
|
|
|
}
|
|
}
|
|
|
- return statuses[status] || status
|
|
|
|
|
|
|
+ return statuses[status as keyof typeof statuses] || status
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const getStatusClass = (status) => {
|
|
|
|
|
|
|
+const getStatusClass = (status: string) => {
|
|
|
const classes = {
|
|
const classes = {
|
|
|
active: 'active',
|
|
active: 'active',
|
|
|
inactive: 'inactive',
|
|
inactive: 'inactive',
|
|
|
maintenance: 'maintenance'
|
|
maintenance: 'maintenance'
|
|
|
}
|
|
}
|
|
|
- return classes[status] || ''
|
|
|
|
|
|
|
+ return classes[status as keyof typeof classes] || ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Statistiques fictives
|
|
// Statistiques fictives
|
|
@@ -422,17 +425,17 @@ const getVehicleMaintenanceCount = (vehicleId) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Méthodes pour les actions
|
|
// Méthodes pour les actions
|
|
|
-const viewVehicle = (vehicle) => {
|
|
|
|
|
|
|
+const viewVehicle = (vehicle: Vehicle) => {
|
|
|
viewingVehicle.value = { ...vehicle }
|
|
viewingVehicle.value = { ...vehicle }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const editVehicle = (vehicle) => {
|
|
|
|
|
|
|
+const editVehicle = (vehicle: Vehicle) => {
|
|
|
editingVehicle.value = vehicle
|
|
editingVehicle.value = vehicle
|
|
|
formData.value = { ...vehicle }
|
|
formData.value = { ...vehicle }
|
|
|
viewingVehicle.value = null
|
|
viewingVehicle.value = null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const confirmDelete = (vehicle) => {
|
|
|
|
|
|
|
+const confirmDelete = (vehicle: Vehicle) => {
|
|
|
deletingVehicle.value = vehicle
|
|
deletingVehicle.value = vehicle
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -443,11 +446,11 @@ const closeForm = () => {
|
|
|
id: null,
|
|
id: null,
|
|
|
brand: '',
|
|
brand: '',
|
|
|
model: '',
|
|
model: '',
|
|
|
- licensePlate: '',
|
|
|
|
|
|
|
+ immatriculation: '',
|
|
|
year: new Date().getFullYear(),
|
|
year: new Date().getFullYear(),
|
|
|
type: 'van',
|
|
type: 'van',
|
|
|
companyId: '',
|
|
companyId: '',
|
|
|
- capacity: null,
|
|
|
|
|
|
|
+ number_places: 0,
|
|
|
color: '',
|
|
color: '',
|
|
|
status: 'active',
|
|
status: 'active',
|
|
|
image: null,
|
|
image: null,
|
|
@@ -455,15 +458,15 @@ const closeForm = () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const saveVehicle = async (vehicleData) => {
|
|
|
|
|
|
|
+const saveVehicle = async (vehicleData: Vehicle) => {
|
|
|
if (editingVehicle.value) {
|
|
if (editingVehicle.value) {
|
|
|
// Mise à jour d'un véhicule existant
|
|
// Mise à jour d'un véhicule existant
|
|
|
try {
|
|
try {
|
|
|
const vehiculeData: Partial<Vehicle> = {
|
|
const vehiculeData: Partial<Vehicle> = {
|
|
|
- number_places: vehicleData.capacity || 0,
|
|
|
|
|
|
|
+ number_places: vehicleData.number_places || 0,
|
|
|
color: vehicleData.color || '',
|
|
color: vehicleData.color || '',
|
|
|
type: vehicleData.type || '',
|
|
type: vehicleData.type || '',
|
|
|
- immatriculation: vehicleData.licensePlate || '',
|
|
|
|
|
|
|
+ immatriculation: vehicleData.immatriculation || '',
|
|
|
model: vehicleData.model || '',
|
|
model: vehicleData.model || '',
|
|
|
companyId: vehicleData.companyId || userStore.companyId || 1,
|
|
companyId: vehicleData.companyId || userStore.companyId || 1,
|
|
|
status: vehicleData.status || 'active'
|
|
status: vehicleData.status || 'active'
|
|
@@ -497,7 +500,7 @@ const deleteVehicle = async () => {
|
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
|
await Promise.all([
|
|
await Promise.all([
|
|
|
loadVehicles(),
|
|
loadVehicles(),
|
|
|
- loadCompanies()
|
|
|
|
|
|
|
+ useVehiculeStore().fetchVehicles()
|
|
|
])
|
|
])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -512,7 +515,7 @@ watch(() => pagination.value.page, () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// Méthodes pour les événements du TopBar
|
|
// Méthodes pour les événements du TopBar
|
|
|
-const handleSearch = (query) => {
|
|
|
|
|
|
|
+const handleSearch = (query: string) => {
|
|
|
searchQuery.value = query
|
|
searchQuery.value = query
|
|
|
}
|
|
}
|
|
|
|
|
|