hrms-mgt/src/modules/03_recruiting/components/Table.vue

302 lines
7.8 KiB
Vue
Raw Normal View History

2024-09-17 15:56:06 +07:00
<script setup lang="ts">
import { checkPermission } from "@/utils/permissions";
import { ref, useAttrs, watch } from "vue";
2025-10-17 11:04:59 +07:00
import type {
Pagination,
ExamResultOption,
} from "@/modules/03_recruiting/interface/index/Main";
2024-09-17 15:56:06 +07:00
const attrs = ref<any>(useAttrs());
const table = ref<any>(null);
const filterRef = ref<any>(null);
2025-02-26 17:15:19 +07:00
2025-10-17 10:02:24 +07:00
const filter = defineModel<string>("filter", { required: false });
const examResult = defineModel<string>("examResult", {
required: false,
default: "",
});
const pagination = defineModel<Pagination>("pagination", { required: true });
2025-02-26 17:15:19 +07:00
2024-09-17 15:56:06 +07:00
const props = defineProps({
onSearch: Function,
fetchData: Function,
2024-09-17 15:56:06 +07:00
count: Number,
totalList: Number,
2025-09-24 11:37:49 +07:00
total: Number,
2024-09-17 15:56:06 +07:00
pass: Number,
notpass: Number,
missed_exam: Number,
other: Number,
2024-09-17 15:56:06 +07:00
inputfilter: String,
name: String,
icon: String,
inputvisible: Array,
editvisible: Boolean,
add: {
type: Function,
default: () => console.log("not function"),
},
validate: {
type: Function,
default: () => console.log("not function"),
},
nornmalData: {
type: Boolean,
defualt: true,
},
conclude: {
type: Boolean,
defualt: false,
},
});
2025-10-17 11:04:59 +07:00
const optionsStatus = ref<ExamResultOption[]>([
2025-10-17 10:02:24 +07:00
{ label: "ทั้งหมด", value: "" },
2025-10-17 11:04:59 +07:00
{ label: "ขาดสอบ", value: "missed_exam" },
2025-10-17 10:02:24 +07:00
{ label: "ผ่าน", value: "pass" },
{ label: "ไม่ผ่าน", value: "notpass" },
]);
2024-09-17 15:56:06 +07:00
const emit = defineEmits([
"update:inputfilter",
"update:inputvisible",
"update:editvisible",
]);
2024-09-17 15:56:06 +07:00
const updateVisible = (value: []) => {
emit("update:inputvisible", value);
};
/**
*
* @param start
* @param end
* @param total
*/
function paginationLabel(start: string, end: string, total: string) {
return start + "-" + end + " ใน " + total;
}
/** fn เพิ่มข้อมูล */
function checkAdd() {
props.add();
}
function updatePagination(newPagination: any) {
if (!props.nornmalData) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
}
2025-09-24 11:37:49 +07:00
function getList(enter?: string) {
if (enter == "enter") {
2025-09-23 18:01:15 +07:00
pagination.value.page = 1;
props.fetchData?.();
} else {
props.fetchData?.();
}
2024-09-17 15:56:06 +07:00
}
watch(
() => pagination.value.rowsPerPage,
async () => {
getList();
}
);
2024-09-17 15:56:06 +07:00
</script>
2025-10-17 10:02:24 +07:00
2023-06-01 12:54:58 +07:00
<template>
<div class="q-pb-sm row q-col-gutter-sm">
<div
class="q-gutter-sm"
v-if="nornmalData == true && checkPermission($route)?.attrIsCreate"
>
<q-btn
size="12px"
flat
round
2024-12-04 16:13:12 +07:00
color="primary"
@click="checkAdd"
icon="mdi-plus"
>
<q-tooltip>เพมขอม</q-tooltip>
</q-btn>
</div>
<div class="row q-gutter-sm q-pb-sm" v-if="conclude == true">
<q-card bordered flat class="q-px-md no-wrap row">
<div class="col-12 text-subtitle2 row items-center">
<span class="text-weight-medium text-dark">สมครสอบ</span>
<q-space />
<q-badge
color="white"
class="text-weight-bold text-subtitle1 text-blue-7"
:label="`${count?.toLocaleString()}`"
rounded
/>
</div>
</q-card>
<q-card bordered flat class="q-px-md no-wrap row">
<div class="col-12 text-subtitle2 row items-center">
<span class="text-weight-medium text-dark">สอบผาน</span>
<q-space />
<q-badge
color="white"
class="text-weight-bold text-subtitle1 text-primary"
:label="`${pass?.toLocaleString()}`"
rounded
/>
</div>
</q-card>
<q-card bordered flat class="q-px-md no-wrap row">
<div class="col-12 text-subtitle2 row items-center">
<span class="text-weight-medium text-dark">สอบไมาน</span>
<q-space />
<q-badge
color="white"
class="text-weight-bold text-subtitle1 text-pink"
:label="`${notpass?.toLocaleString()}`"
rounded
/>
</div>
</q-card>
<q-card
v-if="missed_exam && missed_exam !== 0"
bordered
flat
class="q-px-md no-wrap row"
>
<div class="col-12 text-subtitle2 row items-center">
<span class="text-weight-medium text-dark">ขาดสอบ</span>
<q-space />
<q-badge
color="white"
class="text-weight-bold text-subtitle1 text-orange"
:label="`${missed_exam?.toLocaleString()}`"
rounded
/>
</div>
</q-card>
<q-card
v-if="other && other !== 0"
bordered
flat
class="q-px-md no-wrap row"
>
<div class="col-12 text-subtitle2 row items-center">
<span class="text-weight-medium text-dark"> </span>
<q-space />
<q-badge
color="white"
class="text-weight-bold text-subtitle1 text-info"
:label="`${other?.toLocaleString()}`"
rounded
/>
</div>
</q-card>
</div>
<q-space />
<div class="items-center q-gutter-sm" style="display: flex">
2025-10-17 10:02:24 +07:00
<q-select
v-if="conclude"
dense
outlined
:options="optionsStatus"
option-value="value"
option-label="label"
label="ผลการสอบ"
map-options
emit-value
style="min-width: 140px"
:clearable="examResult !== ''"
@clear="examResult = ''"
v-model="examResult"
@update:model-value="
nornmalData ? props.onSearch?.() : getList('enter')
"
/>
<!-- นหาขอความใน table -->
<q-input
standout
dense
v-model="filter"
ref="filterRef"
outlined
placeholder="ค้นหา"
style="max-width: 200px"
2025-09-23 18:01:15 +07:00
@keydown.enter.prevent="
2025-09-24 11:37:49 +07:00
nornmalData ? props.onSearch?.() : getList('enter')
2025-09-23 18:01:15 +07:00
"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
<!-- แสดงคอลมนใน table -->
<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
2024-11-05 16:33:46 +07:00
style="min-width: 140px"
class="gt-xs"
>
<template> </template>
</q-select>
</div>
</div>
2025-07-07 15:18:37 +07:00
<d-table
ref="table"
flat
bordered
class="custom-header-table"
v-bind="attrs"
virtual-scroll
:virtual-scroll-sticky-size-start="48"
dense
:pagination-label="paginationLabel"
2025-09-10 11:19:39 +07:00
:rows-per-page-options="nornmalData ? [0] : [10, 25, 50, 100]"
@update:pagination="updatePagination"
>
<template v-slot:header="props">
<q-tr :props="props">
2024-07-24 16:37:04 +07:00
<q-th auto-width v-if="nornmalData == true" />
<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 #body="props">
<slot v-bind="props" name="columns"></slot>
</template>
<template v-if="!nornmalData" v-slot:pagination="scope">
2025-09-24 11:37:49 +07:00
งหมด {{ props.total?.toLocaleString() }} รายการ
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="totalList"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="getList"
></q-pagination>
</template>
2025-07-07 15:18:37 +07:00
</d-table>
2023-06-01 12:54:58 +07:00
</template>
2023-06-01 12:54:58 +07:00
<style lang="scss">
.icon-color {
color: #4154b3;
2023-06-01 12:54:58 +07:00
}
</style>