hrms-mgt/src/modules/11_discipline/components/4_Result/Table.vue

282 lines
6.3 KiB
Vue
Raw Normal View History

2023-11-24 16:52:10 +07:00
<script setup lang="ts">
import { ref, useAttrs, watch } from "vue";
2023-12-26 15:53:52 +07:00
import { useDisciplineResultStore } from "@/modules/11_discipline/store/ResultStore";
2023-11-24 16:52:10 +07:00
2023-12-26 15:53:52 +07:00
const store = useDisciplineResultStore();
2023-11-24 16:52:10 +07:00
const table = ref<any>(null);
const filterRef = ref<any>(null);
const attrs = ref<any>(useAttrs());
const paging = ref<boolean>(true);
2024-01-10 17:13:23 +07:00
const statusFilter = ref<string>("DONE");
2023-11-24 16:52:10 +07:00
/** รับ props มาจากหน้าหลัก */
const props = defineProps({
count: Number,
pass: Number,
notpass: Number,
inputfilter: String,
name: String,
icon: String,
inputvisible: Array,
editvisible: Boolean,
validate: {
type: Function,
default: () => console.log("not function"),
},
2023-12-27 15:50:41 +07:00
fetchListResult: {
type: Function,
default: () => console.log("not function"),
},
openEdit: {
type: Function,
default: () => console.log("not function"),
},
filterStatus: {
type: Function,
default: () => console.log("not function"),
},
2023-11-24 16:52:10 +07:00
nornmalData: {
type: Boolean,
defualt: true,
},
conclude: {
type: Boolean,
defualt: false,
},
page: {
type: Number,
},
pageSize: {
type: Number,
},
maxPage: {
type: Number,
},
totalList: {
type: Number,
},
});
const currentPage = ref<number>(1);
const filter = ref<string>("");
const pagination = ref({
descending: false,
page: props.page,
rowsPerPage: props.pageSize,
2023-11-24 16:52:10 +07:00
});
const emit = defineEmits([
"update:inputfilter",
"update:inputvisible",
"update:editvisible",
"update:queryString",
2023-11-24 16:52:10 +07:00
]);
function updateVisible(value: []) {
emit("update:inputvisible", value);
}
function resetFilter() {
// reset ค่าที่ค้นหาเมื่อกดปุ่ม X ในกล่องค้นหา
emit("update:inputfilter", "");
filterRef.value.focus();
2023-12-27 15:50:41 +07:00
props.fetchListResult?.();
2023-11-24 16:52:10 +07:00
}
function updateRowsPerPage(newPagination: any) {
pagination.value = newPagination;
currentPage.value = 1;
}
function updatePaging(p: number, pS: number, key: string) {
emit("update:queryString", p, pS, key);
}
watch([() => currentPage.value, () => pagination.value.rowsPerPage], () => {
emit(
"update:queryString",
currentPage.value,
Number(pagination.value.rowsPerPage),
filter.value
);
});
2023-12-26 15:53:52 +07:00
function dataUpdate() {
props.filterStatus(statusFilter.value);
2023-12-26 15:53:52 +07:00
}
2023-12-27 15:50:41 +07:00
function updateInput(value: string | number | null) {
emit("update:inputfilter", value);
}
function filterFn() {
props.fetchListResult?.();
}
2023-11-24 16:52:10 +07:00
</script>
<template>
<div class="q-pb-sm row q-col-gutter-sm">
2023-12-26 15:53:52 +07:00
<div class="q-gutter-sm" v-if="nornmalData == true"></div>
2024-07-04 13:44:29 +07:00
<div class="col-xs-12 col-sm-4 col-md-4">
2023-12-26 15:53:52 +07:00
<q-select
v-model="statusFilter"
label="สถานะ"
dense
outlined
emit-value
map-options
option-label="name"
option-value="id"
:options="store.statusOptions"
@update:model-value="dataUpdate"
2024-07-04 13:44:29 +07:00
>
<template v-if="statusFilter !== 'ALL'" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="(statusFilter = 'ALL'), dataUpdate()"
class="cursor-pointer"
/>
</template>
</q-select>
2023-11-24 16:52:10 +07:00
</div>
<q-space />
<q-input
standout
dense
2023-12-27 15:50:41 +07:00
:model-value="inputfilter"
2023-11-24 16:52:10 +07:00
ref="filterRef"
@keydown.enter.prevent="filterFn"
2023-12-27 15:50:41 +07:00
@update:model-value="updateInput"
2023-11-24 16:52:10 +07:00
outlined
placeholder="ค้นหา"
style="max-width: 200px"
class="col-xs-12 col-sm-3 col-md-2"
>
<template v-slot:append>
2023-12-27 15:50:41 +07:00
<q-icon v-if="inputfilter == ''" name="search" />
2023-11-24 16:52:10 +07:00
<q-icon
2023-12-27 15:50:41 +07:00
v-if="inputfilter !== ''"
2023-11-24 16:52:10 +07:00
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
</template>
</q-input>
<q-select
:model-value="inputvisible"
@update:model-value="updateVisible"
:display-value="$q.lang.table.columns"
multiple
outlined
dense
:options="attrs.columns"
options-dense
option-value="name"
map-options
emit-value
class="col-xs-12 col-sm-3 col-md-2 gt-xs"
>
</q-select>
</div>
<d-table
ref="table"
flat
v-bind="attrs"
virtual-scroll
:virtual-scroll-sticky-size-start="48"
dense
:rows-per-page-options="[10, 25, 50, 100]"
:pagination="pagination"
@update:pagination="updateRowsPerPage"
2023-11-24 16:52:10 +07:00
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium" v-html="col.label" />
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
@click="openEdit(props.row.id)"
>
<div v-if="col.name == 'no'">
{{
(currentPage - 1) * Number(pagination.rowsPerPage) +
props.rowIndex +
1
}}
</div>
2024-01-17 11:23:10 +07:00
<div v-else-if="col.name === 'title'" class="table_ellipsis">
2024-07-04 13:44:29 +07:00
{{ props.row.title ?? "-" }}
2024-01-17 11:23:10 +07:00
</div>
<div v-else>
2024-07-04 13:44:29 +07:00
{{ col.value ?? "-" }}
</div>
</q-td>
</q-tr>
2023-11-24 16:52:10 +07:00
</template>
<template v-slot:pagination="scope">
งหมด {{ props.totalList }} รายการ
<q-pagination
v-model="currentPage"
active-color="primary"
color="dark"
:max="Number(props.maxPage)"
size="sm"
boundary-links
direction-links
></q-pagination>
</template>
2023-11-24 16:52:10 +07:00
</d-table>
</template>
<style lang="scss">
.icon-color {
color: #4154b3;
}
.custom-table2 {
max-height: 64vh;
.q-table tr:nth-child(odd) td {
background: white;
}
.q-table tr:nth-child(even) td {
background: #f8f8f8;
}
.q-table thead tr {
background: #ecebeb;
}
.q-table thead tr th {
position: sticky;
}
.q-table td:nth-of-type(2) {
z-index: 3 !important;
}
.q-table th:nth-of-type(2),
.q-table td:nth-of-type(2) {
position: sticky;
left: 0;
z-index: 1;
}
/* this will be the loading indicator */
.q-table thead tr:last-child th {
/* height of all previous header rows */
top: 48px;
}
.q-table thead tr:first-child th {
top: 0;
}
}
</style>