|
@@ -234,13 +234,13 @@ import { ref, computed, onMounted } from 'vue'
|
|
|
import Sidebar from '@/components/Sidebar.vue'
|
|
import Sidebar from '@/components/Sidebar.vue'
|
|
|
import TopBar from '@/components/TopBar.vue'
|
|
import TopBar from '@/components/TopBar.vue'
|
|
|
import { useUserStore } from '@/stores/useUserStore'
|
|
import { useUserStore } from '@/stores/useUserStore'
|
|
|
|
|
+import { useUserCompanyStore } from '@/stores/useCompanyStore'
|
|
|
import EmployeeModal from '@/components/EmployeeModal.vue'
|
|
import EmployeeModal from '@/components/EmployeeModal.vue'
|
|
|
import { useToast } from '@/composables/useToast'
|
|
import { useToast } from '@/composables/useToast'
|
|
|
import UserService from '@/services/UserService'
|
|
import UserService from '@/services/UserService'
|
|
|
-import CompanyService from '@/services/CompanyService'
|
|
|
|
|
import type { User } from '@/types/index'
|
|
import type { User } from '@/types/index'
|
|
|
import { Role, RoleLabel } from '@/Enum/Role'
|
|
import { Role, RoleLabel } from '@/Enum/Role'
|
|
|
-import { useUserCompanyStore } from '@/stores/useCompanyStore'
|
|
|
|
|
|
|
+import CompanyService from '@/services/CompanyService'
|
|
|
|
|
|
|
|
interface Employee extends User {
|
|
interface Employee extends User {
|
|
|
firstName?: string
|
|
firstName?: string
|
|
@@ -282,35 +282,6 @@ const availableRoles = computed(() => {
|
|
|
}))
|
|
}))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-// Employés filtrés
|
|
|
|
|
-const filteredEmployees = computed(() => {
|
|
|
|
|
- return employees.value.filter(employee => {
|
|
|
|
|
- // Filtre de recherche
|
|
|
|
|
- const searchLower = searchQuery.value.toLowerCase()
|
|
|
|
|
- const fullName = getEmployeeFullName(employee).toLowerCase()
|
|
|
|
|
- const emailMatch = employee.email.toLowerCase().includes(searchLower)
|
|
|
|
|
- const phoneMatch = (employee.telephone || employee.phone || '').toLowerCase().includes(searchLower)
|
|
|
|
|
-
|
|
|
|
|
- if (searchQuery.value && !fullName.includes(searchLower) && !emailMatch && !phoneMatch) {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Filtre par rôle
|
|
|
|
|
- if (roleFilter.value && employee.role !== roleFilter.value) {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Filtre par statut
|
|
|
|
|
- if (statusFilter.value === 'active' && employee.active === false) {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
- if (statusFilter.value === 'inactive' && employee.active !== false) {
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return true
|
|
|
|
|
- })
|
|
|
|
|
-})
|
|
|
|
|
|
|
|
|
|
// Fonctions utilitaires
|
|
// Fonctions utilitaires
|
|
|
const getRoleLabel = (role: Role | string): string => {
|
|
const getRoleLabel = (role: Role | string): string => {
|
|
@@ -338,15 +309,37 @@ const formatDate = (dateString?: string): string => {
|
|
|
// Gestion des employés
|
|
// Gestion des employés
|
|
|
const loadEmployees = async (page: number = 1) => {
|
|
const loadEmployees = async (page: number = 1) => {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ if (useUserStore().userRole !== Role.Admin) {
|
|
|
|
|
+ const result = await CompanyService.getCompanyEmployees(useUserCompanyStore().id as number)
|
|
|
|
|
+
|
|
|
|
|
+ employees.value = result.data.data.map(user => ({
|
|
|
|
|
+ firstName: user.otherName,
|
|
|
|
|
+ lastName: user.name,
|
|
|
|
|
+ phone: user.telephone,
|
|
|
|
|
+ email: user.email,
|
|
|
|
|
+ role: user.role
|
|
|
|
|
+ }))
|
|
|
|
|
+
|
|
|
|
|
+ pagination.value = {
|
|
|
|
|
+ page: result.data.page,
|
|
|
|
|
+ limit: result.data.limit,
|
|
|
|
|
+ total: result.data.total,
|
|
|
|
|
+ totalPages: result.data.totalPages
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
loading.value = true
|
|
loading.value = true
|
|
|
|
|
+ const result = await UserService.getUsers(page, pagination.value.limit)
|
|
|
|
|
|
|
|
- const result = await CompanyService.getCompanyEmployees(useUserCompanyStore().id, page, pagination.value.limit)
|
|
|
|
|
-
|
|
|
|
|
- employees.value = result.employees.map(user => ({
|
|
|
|
|
|
|
+ employees.value = result.users.map(user => ({
|
|
|
...user,
|
|
...user,
|
|
|
firstName: user.otherName,
|
|
firstName: user.otherName,
|
|
|
lastName: user.name,
|
|
lastName: user.name,
|
|
|
- phone: user.telephone
|
|
|
|
|
|
|
+ phone: user.telephone,
|
|
|
|
|
+ email: user.email,
|
|
|
|
|
+ role: user.role
|
|
|
}))
|
|
}))
|
|
|
|
|
|
|
|
pagination.value = result.pagination
|
|
pagination.value = result.pagination
|
|
@@ -357,6 +350,37 @@ const loadEmployees = async (page: number = 1) => {
|
|
|
loading.value = false
|
|
loading.value = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+// Employés filtrés
|
|
|
|
|
+const filteredEmployees = computed(() => {
|
|
|
|
|
+ console.log('employee', employees.value)
|
|
|
|
|
+ return employees.value.filter(employee => {
|
|
|
|
|
+
|
|
|
|
|
+ // Filtre de recherche
|
|
|
|
|
+ const searchLower = searchQuery.value.toLowerCase()
|
|
|
|
|
+ const fullName = getEmployeeFullName(employee).toLowerCase()
|
|
|
|
|
+ const emailMatch = employee.email.toLowerCase().includes(searchLower)
|
|
|
|
|
+ const phoneMatch = (employee.telephone || employee.phone || '').toLowerCase().includes(searchLower)
|
|
|
|
|
+
|
|
|
|
|
+ if (searchQuery.value && !fullName.includes(searchLower) && !emailMatch && !phoneMatch) {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Filtre par rôle
|
|
|
|
|
+ if (roleFilter.value && employee.role !== roleFilter.value) {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Filtre par statut
|
|
|
|
|
+ if (statusFilter.value === 'active' && employee.active === false) {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ if (statusFilter.value === 'inactive' && employee.active !== false) {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
const viewEmployee = (employee: Employee) => {
|
|
const viewEmployee = (employee: Employee) => {
|
|
|
viewingEmployee.value = employee
|
|
viewingEmployee.value = employee
|