|
|
@@ -346,6 +346,7 @@ import TopBar from '@/components/TopBar.vue'
|
|
|
import 'leaflet/dist/leaflet.css'
|
|
|
import TripMap from '@/components/TripMap.vue'
|
|
|
import { useUserStore } from '@/stores/useUserStore'
|
|
|
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
|
|
|
import { useStationStore } from '@/stores/useStationStore'
|
|
|
import { useToast } from '@/composables/useToast'
|
|
|
import TripService from '@/services/TripService'
|
|
|
@@ -397,7 +398,23 @@ const formData = ref<Trip>({
|
|
|
notes: '',
|
|
|
companyId: 0,
|
|
|
createdAt: '',
|
|
|
- updatedAt: ''
|
|
|
+ updatedAt: '',
|
|
|
+ departStationId: 0,
|
|
|
+ arriveStationId: 0,
|
|
|
+ departStation: {
|
|
|
+ id: 0,
|
|
|
+ name: '',
|
|
|
+ address: '',
|
|
|
+ lat: 0,
|
|
|
+ long: 0,
|
|
|
+ },
|
|
|
+ arriveStation: {
|
|
|
+ id: 0,
|
|
|
+ name: '',
|
|
|
+ address: '',
|
|
|
+ lat: 0,
|
|
|
+ long: 0,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
const isFormValid = computed(() => {
|
|
|
@@ -407,8 +424,9 @@ const isFormValid = computed(() => {
|
|
|
formData.value.estimatedArrivalDateTime &&
|
|
|
formData.value.vehicleId &&
|
|
|
formData.value.driverId &&
|
|
|
- formData.value.pricePerSeat > 0 &&
|
|
|
- formData.value.totalSeats > 0
|
|
|
+ formData.value.pricePerSeat !== undefined && formData.value.pricePerSeat > 0 &&
|
|
|
+ formData.value.totalSeats !== undefined && formData.value.totalSeats > 0 &&
|
|
|
+ formData.value.availableSeats !== undefined && formData.value.availableSeats > 0
|
|
|
})
|
|
|
|
|
|
const filteredTrips = computed(() => {
|
|
|
@@ -456,6 +474,7 @@ const getStationName = (stationId: number): string => {
|
|
|
}
|
|
|
|
|
|
const getDriverName = (driverId: number): string => {
|
|
|
+ console.log('drivers:', drivers.value)
|
|
|
const driver = drivers.value.find(d => d.id === driverId)
|
|
|
return driver ? `${driver.name} ${driver.otherName}` : 'Inconnu'
|
|
|
}
|
|
|
@@ -520,7 +539,7 @@ const loadTrips = async () => {
|
|
|
loading.value = true
|
|
|
try {
|
|
|
const userRole = userStore.userRole
|
|
|
- const companyId = userStore.companyId
|
|
|
+ const companyId = useUserCompanyStore().id as number
|
|
|
|
|
|
let result
|
|
|
if (userRole === 'admin') {
|
|
|
@@ -530,7 +549,7 @@ const loadTrips = async () => {
|
|
|
// Utilisateur d'entreprise ne voit que les trajets de son entreprise
|
|
|
result = await TripService.getTripsByCompany(companyId, pagination.value.page, pagination.value.limit)
|
|
|
}
|
|
|
-
|
|
|
+ console.log('result:',result)
|
|
|
trips.value = result.trips
|
|
|
pagination.value = result.pagination
|
|
|
} catch (error) {
|
|
|
@@ -543,22 +562,18 @@ const loadTrips = async () => {
|
|
|
|
|
|
const loadDrivers = async () => {
|
|
|
try {
|
|
|
- const userRole = userStore.userRole
|
|
|
- const companyId = userStore.decodedCompanyId || userStore.companyId
|
|
|
-
|
|
|
- if (userRole === Role.Manager || userRole === Role.Admin) {
|
|
|
-
|
|
|
- drivers.value = (await CompanyService.getCompanyEmployees(parseInt(companyId))).employees.filter(driver => driver.role === Role.Driver)
|
|
|
- } else {
|
|
|
+ const companyId = useUserCompanyStore().id as number
|
|
|
+ console.log('companyId:',companyId)
|
|
|
// Pour les entreprises, récupérer uniquement les chauffeurs de l'entreprise
|
|
|
- const companyId = userStore.decodedCompanyId || userStore.companyId
|
|
|
+ const response = await CompanyService.getCompanyEmployees(companyId)
|
|
|
if (companyId) {
|
|
|
- drivers.value = (await CompanyService.getCompanyEmployees(parseInt(companyId))).employees.filter(driver => driver.role === Role.Driver)
|
|
|
+ drivers.value = response.data.data.filter(driver => driver.role === Role.Driver)
|
|
|
+
|
|
|
} else {
|
|
|
console.error('Aucune entreprise associée à l\'utilisateur')
|
|
|
drivers.value = []
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
console.log('Driver valeur ======>',drivers.value)
|
|
|
} catch (error) {
|
|
|
console.error('Erreur lors du chargement des chauffeurs:', error)
|
|
|
@@ -567,9 +582,10 @@ const loadDrivers = async () => {
|
|
|
}
|
|
|
|
|
|
const loadVehicles = async () => {
|
|
|
+ console.log('je suis dans vehicule')
|
|
|
try {
|
|
|
const userRole = userStore.userRole
|
|
|
- const companyId = userStore.companyId
|
|
|
+ const companyId = useUserCompanyStore().id as number
|
|
|
|
|
|
let result
|
|
|
if (userRole === 'admin') {
|
|
|
@@ -778,6 +794,7 @@ const handleUserMenu = () => {
|
|
|
}
|
|
|
// Initialisation des données
|
|
|
onMounted(async () => {
|
|
|
+ console.log('viewingTrip:', viewingTrip.value)
|
|
|
await loadStations()
|
|
|
await loadDrivers()
|
|
|
await loadVehicles()
|