-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathTaskTable.vue
More file actions
117 lines (98 loc) · 2.58 KB
/
TaskTable.vue
File metadata and controls
117 lines (98 loc) · 2.58 KB
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
<template>
<div class="tw-flex tw-flex-col tw-w-full tw-grow tw-py-3 tw-overflow-hidden tw-space-y-3">
<SortTable
id="task-table"
:columns="columnsConfig"
:data="data"
:placeholder="showPlaceholder"
@changeFilter="onChangeFilter">
<template #placeholder>
<TablePlaceholder
:placeholder="placeholderType"
class="tw-grow" />
</template>
</SortTable>
<Pagination
:total="dataPagination.total"
:page="dataPagination.page"
:pages="dataPagination.pages"
:per-page="dataPagination.perPage"
@perPage="onPerPage"
@go="onGo" />
</div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { SortTable, Pagination, TablePlaceholder } from "../../../system";
import { getDataTask } from "../api/index";
import { getColumns } from "../config/columns";
import { getCaseNumber } from "../variables";
const data = ref(null);
const columnsConfig = ref(null);
const filter = ref({
field: null,
filter: "asc",
});
// Placeholder variables
const showPlaceholder = ref(false);
const placeholderType = ref("loading");
// Pagination variable
const dataPagination = ref({
total: 0,
page: 1,
pages: 0,
perPage: 15,
});
const getData = async () => {
const response = await getDataTask({
params: {
case_number: getCaseNumber(),
status: "ACTIVE",
order_by: filter.value?.field,
order_direction: filter.value?.filter,
page: dataPagination.value.page,
per_page: dataPagination.value.perPage,
},
});
return response;
};
const setMetaPagination = (meta) => {
dataPagination.value = {
total: meta.total,
page: meta.current_page,
pages: meta.last_page,
perPage: dataPagination.value.perPage,
};
};
const hookGetData = async () => {
placeholderType.value = "loading";
showPlaceholder.value = true;
const response = await getData();
setMetaPagination(response.meta);
setTimeout(() => {
data.value = response.data;
if (response.data && !response.data.length) {
placeholderType.value = "empty-tasks";
return;
}
showPlaceholder.value = false;
}, 300);
};
const onGo = async (page) => {
dataPagination.value.page = page;
await hookGetData();
};
const onPerPage = async (perPage) => {
dataPagination.value.perPage = perPage;
dataPagination.value.page = 1;
await hookGetData();
};
const onChangeFilter = async (dataFilter) => {
filter.value = dataFilter;
await hookGetData();
};
onMounted(async () => {
columnsConfig.value = getColumns("tasks");
await hookGetData();
});
</script>