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
|
<template>
<table>
<thead>
<tr>
<th v-for="header in tableData.headers">
{{ header }}
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="(row) in tableData.content">
<td>{{ row[0] }}</td>
<td v-for="(column) in row.slice(1)">
{{ column }}
</td>
<td>
<button @click="showEditForm(`${row[0]}`)">✎</button>
</td>
<td>
<button @click="removeField(`${row[0]}`)">✖</button>
</td>
</tr>
</tbody>
</table>
</template>
<script>
import EditFormBox from "./EditFormBox.vue";
import axios from 'axios';
export default {
name: "Table",
props: ['tableData'],
components: {EditFormBox},
methods: {
showEditForm(serviceId) {
axios
.request({
url: '/api/get/',
method: 'post',
headers: {'Content-Type': 'application/json'},
data: JSON.stringify({'type': 'single_id', 'service_id': serviceId})
})
.then(response => {
this.$emit('show-form', response.data);
});
},
removeField(serviceId) {
axios
.request({
url: '/api/delete', method: 'post',
data: {'service_id': parseInt(serviceId)}
})
.then(response => {
if (response.status === 200) {
let err = response.data.error;
if (err) this.$emit('show-popup', {'type': 'failure', 'msg': response.data.service_id});
else this.tableData.content = this.tableData.content.filter(row => row[0].toString() !== serviceId);
}
});
}
}
}
</script>
<style scoped>
table {
border-spacing: 0;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
}
th {
background-color: #6c7ae0;
padding: 7px 15px;
font-size: 19px;
color: white;
}
td {
padding: 6px;
color: #505050;
}
tbody > tr:hover, tbody > tr:nth-child(2n):hover {
background-color: rgba(0, 0, 0, 0.1);
}
tbody > tr:nth-child(2n) {
background-color: #f8f6ff;
}
button {
border: none;
border-radius: 2px;
}
button:hover {
background-color: #dadada;
}
button:focus {
background-color: #d5d5d5;
}
</style>
|