-
Notifications
You must be signed in to change notification settings - Fork 0
/
VueIndex
153 lines (131 loc) · 3.64 KB
/
VueIndex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<template>
<div>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Employees</h1>
</div>
<div class="row">
<div class="card mx-auto">
<div v-if="showMessage">
<div class="alert alert-success">{{ message }}</div>
</div>
<div class="card-header">
<div class="row">
<div class="col">
<form method="" action="">
<div class="form-row align-items-center">
<div class="col">
<input v-model.lazy="search" type="search" name="search" class="form-control mb-2" placeholder="John Doe">
</div>
<div class="col">
<button type="submit" class="btn btn-primary mb-2">Search</button>
</div>
<div class="col">
<select v-model="selectedDepartment" name="department" class="form-control" aria-label="Default select example">
<option v-for="department in departments" :key="department.id" :value="department.id">{{ department.name }}</option>
</select>
</div>
</div>
</form>
</div>
<div>
<router-link :to="{name: 'EmployeesCreate'}" class="btn btn-primary mb-2"> Create</router-link>
</div>
</div>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th scope="col">#Id</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Address</th>
<th scope="col">Department</th>
<th scope="col">Manage</th>
</tr>
</thead>
<tbody>
<tr
v-for="employee in employees" :key="employee.id"
>
<th scope="row">#{{ employee.id }}</th>
<td>{{ employee.first_name}}</td>
<td>{{ employee.last_name}}</td>
<td>{{ employee.address }}</td>
<td>{{ employee.department.name }}</td>
<td>
<router-link
class="btn btn-success"
:to="{name: 'EmployeeEdit',
params: {id: employee.id}}">
Edit</router-link>
<button class="btn btn-danger"
@click="deleteEmployee(employee.id)">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return {
employees: [],
showMessage: false,
message: "",
search: null,
selectedDepartment: null,
departments: []
};
},
watch: {
search() {
this.getEmployees();
},
selectedDepartment(){
this.getEmployees();
}
},
created(){
this.getEmployees();
this.getDepartments();
},
methods: {
getEmployees(){
axios.get('/api/employees')
.then(res => {
search: this.search
department_id: this.selectedDepartment
this.employees = res.data.data
}).catch(error => {
console.log(error);
})
},
getDepartments(){
axios.get("/api/employees/departments")
.then(res => {
this.departments = res.data;
}).catch(error => {
console.log(console.error);
});
},
deleteEmployee(id){
axios.delete('api/employees/'+ id)
.then(res => {
this.showMessage = true;
this.message = res.data
this.getEmployees()
})
.catch(error =>{
console.log(error);
});
}
}
}
</script>
<style scoped>
</style>