hrms-mgt/src/modules/09_leave/views/04_SpecialTimeMain.vue

466 lines
13 KiB
Vue
Raw Normal View History

<script setup lang="ts">
2025-10-08 10:37:36 +07:00
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import type { QTableProps } from "quasar";
2024-09-18 17:26:53 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-18 17:26:53 +07:00
import { useCounterMixin } from "@/stores/mixin";
import { useSpecialTimeStore } from "@/modules/09_leave/stores/SpecialTimeStore";
import { checkPermission } from "@/utils/permissions";
2025-10-08 10:37:36 +07:00
import { usePagination } from "@/composables/usePagination";
2023-12-15 09:58:02 +07:00
2025-10-08 10:37:36 +07:00
import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime";
import type { DataSpecialTime } from "@/modules/09_leave/interface/index/Main";
2023-11-29 10:45:23 +07:00
2023-12-15 09:58:02 +07:00
import DialogReason from "@/components/Dialogs/PopupReason.vue";
import DialogApprove from "@/modules/09_leave/components/04_SpecialTime/DialogApprove.vue";
2023-12-15 09:58:02 +07:00
const $q = useQuasar(); // show dialog
const mixin = useCounterMixin();
const store = useSpecialTimeStore();
const {
hideLoader,
monthYear2Thai,
messageError,
showLoader,
success,
date2Thai,
dialogConfirm,
} = mixin;
2025-10-08 10:37:36 +07:00
const { pagination, params, onRequest } = usePagination("", fetchData);
2023-12-15 09:58:02 +07:00
const emit = defineEmits(["update:change-page"]);
2025-10-08 10:37:36 +07:00
const toDay = ref<Date>(new Date());
const monthToday = toDay.value.getMonth();
const yearToday = toDay.value.getFullYear();
const month = ref<number>(monthToday + 1);
const year = ref<number>(yearToday);
2025-10-08 10:37:36 +07:00
const description = ref<string>("");
2023-12-15 09:58:02 +07:00
/**ตัวแปรที่ใช้ */
2024-09-18 17:26:53 +07:00
const modalUnapprove = ref<boolean>(false);
const modalApprove = ref<boolean>(false);
2025-10-08 10:37:36 +07:00
const detailData = ref<DataSpecialTime>();
const editCheck = ref<string>("");
const dialogTitle = ref<string>("");
const dialogDesc = ref<string>("");
const name = ref<string>("");
const id = ref<string>("");
const dateDialog = ref<string>("");
const dateFixDialog = ref<string>("");
const dateYear = ref<number>(new Date().getFullYear());
2023-11-29 10:45:23 +07:00
2024-09-18 17:26:53 +07:00
/** Function Date */
const dateMonth = ref<DataDateMonthObject>({
month: new Date().getMonth(),
year: new Date().getFullYear(),
});
// ค้นหาในตาราง
const filterKeyword = ref<string>("");
2025-10-08 10:37:36 +07:00
const rows = ref<DataSpecialTime[]>([]);
const visibleColumns = ref<String[]>([
"no",
2025-10-08 10:37:36 +07:00
"fullName",
"createdAt",
"checkDate",
"startTimeMorning",
"startTimeAfternoon",
"description",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "center",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2025-10-08 10:37:36 +07:00
name: "fullName",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
2025-10-08 10:37:36 +07:00
field: "fullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2025-10-08 10:37:36 +07:00
name: "createdAt",
align: "left",
label: "วันที่ยื่นเรื่อง",
sortable: true,
field: "date",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2025-10-08 10:37:36 +07:00
name: "checkDate",
align: "left",
label: "วันที่ขอแก้ไข",
sortable: true,
field: "dateFix",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2025-10-08 10:37:36 +07:00
name: "startTimeMorning",
align: "left",
label: "ช่วงเช้า",
2026-01-13 18:45:32 +07:00
sortable: false,
field: "timeMorning",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
2025-10-08 10:37:36 +07:00
name: "startTimeAfternoon",
align: "left",
label: "ช่วงบ่าย",
2026-01-13 18:45:32 +07:00
sortable: false,
field: "timeAfternoon",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "description",
align: "left",
label: "เหตุผลการขอลงเวลาพิเศษ",
sortable: true,
field: "description",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
2025-10-08 10:37:36 +07:00
/** ฟังก์ชั่นเรียกดูข้อมูลรายการลงเวลากรณีพิเศษ */
async function fetchData() {
showLoader();
await http
.get(config.API.specialTime(), {
params: {
...params.value,
year: year.value,
month: month.value,
keyword: filterKeyword.value.trim(),
},
})
.then(async (res) => {
const result = await res.data.result;
pagination.value.rowsNumber = result.total;
if (result.data.length > 0) {
rows.value = result.data.map((e: DataSpecialTime) => ({
...e,
date: date2Thai(new Date(e.createdAt), false, true),
dateFix: date2Thai(new Date(e.checkDate)),
timeMorning:
e.startTimeMorning == null
? "-"
: e.checkInEdit == true
? e.startTimeMorning + " - " + e.endTimeMorning
: "-",
timeAfternoon:
e.startTimeAfternoon == null
? "-"
: e.checkOutEdit == true
? e.startTimeAfternoon + " - " + e.endTimeAfternoon
: "-",
checkIn: e.checkInTime,
checkOut: e.checkOutTime,
checkInStatus: store.convertStatus(e.checkInStatus),
checkOutStatus: store.convertStatus(e.checkOutStatus),
}));
}
})
.catch((e) => {
rows.value = [];
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
2023-12-15 09:58:02 +07:00
/**
* งกนไมอน
* @param fullname
* @param personId personId
*/
async function unapprove(fullname: string, personId: string) {
id.value = personId;
2023-12-15 09:58:02 +07:00
dialogTitle.value = " ไม่อนุมัติคำขอ"; // + fullname;
name.value = fullname;
modalUnapprove.value = true;
2023-12-15 09:58:02 +07:00
}
2025-10-08 10:37:36 +07:00
/**
* งกนอน
* @param data อม
*/
function openModal(data: DataSpecialTime) {
id.value = data.id;
dateDialog.value = data.date;
description.value = data.description;
dateFixDialog.value = data.dateFix;
editCheck.value = data.status;
detailData.value = data;
modalApprove.value = true;
}
2023-12-15 09:58:02 +07:00
2025-10-08 10:37:36 +07:00
/** ฟังก์ชั่นปิด Dialog */
2024-09-18 17:26:53 +07:00
function closeDialog() {
modalUnapprove.value = false;
modalApprove.value = false;
2025-10-08 10:37:36 +07:00
description.value = "";
editCheck.value = "PENDING";
2024-09-18 17:26:53 +07:00
}
2025-10-08 10:37:36 +07:00
/**
* งกนบนทกขอมลไมอน
* @param reason เหตผลทไมอน
*/
2024-09-18 17:26:53 +07:00
async function clickSave(reason: string) {
dialogConfirm($q, async () => {
showLoader();
await http
2025-10-08 10:37:36 +07:00
.put(config.API.specialTimeReject(id.value), {
reason: reason,
})
.then(async () => {
await fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
2024-12-24 11:39:10 +07:00
modalUnapprove.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
2024-09-18 17:26:53 +07:00
}
2024-09-18 17:26:53 +07:00
/**
* งขอมลตามป
* @param e
*/
async function updateMonth(e: DataDateMonthObject) {
if (e != null) {
dateYear.value = e.year;
dateYear.value = year.value;
month.value = dateMonth.value.month + 1;
year.value = dateMonth.value.year;
2025-10-08 10:37:36 +07:00
onSearchData();
}
2024-09-18 17:26:53 +07:00
}
//แปลงเดือนเป็นไทย
2025-10-08 10:37:36 +07:00
function monthYearThai(val: DataDateMonthObject) {
2024-09-18 17:26:53 +07:00
if (val == null) return "";
else return monthYear2Thai(val.month, val.year);
}
2025-10-08 10:37:36 +07:00
/** ฟังก์ชั่นค้นหาข้อมูล */
function onSearchData() {
pagination.value.page = 1;
fetchData();
}
/**Hook */
onMounted(async () => {
//อัพเดทเป็นวันปัจจุบันเมื่อเข้าหน้านี้
const toDay = ref<Date>(new Date());
const monthToday = toDay.value.getMonth();
const yearToday = toDay.value.getFullYear();
month.value = monthToday + 1;
year.value = yearToday;
await fetchData();
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
รายการลงเวลากรณเศษ
</div>
2025-10-08 10:37:36 +07:00
<q-card flat bordered class="col-12 q-pa-md">
2023-11-03 15:08:53 +07:00
<div class="row col-12 q-col-gutter-sm q-mb-sm">
2025-10-08 10:37:36 +07:00
<div class="col-xs-12 col-sm-3 col-md-2">
2023-11-03 15:08:53 +07:00
<datepicker
v-model="dateMonth"
2023-11-03 15:08:53 +07:00
:locale="'th'"
autoApply
month-picker
:enableTimePicker="false"
@update:modelValue="updateMonth"
2023-11-03 15:08:53 +07:00
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
:model-value="monthYearThai(dateMonth)"
dense
outlined
hide-bottom-space
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<q-space />
2025-10-08 10:37:36 +07:00
<div class="col-xs-12 col-sm-3 col-md-2">
<q-input
standout
dense
v-model="filterKeyword"
outlined
placeholder="ค้นหาชื่อ-นามสกุล"
@keydown.enter.prevent="onSearchData()"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
</div>
2023-11-03 15:08:53 +07:00
2025-10-08 10:37:36 +07:00
<div class="col-xs-12 col-sm-3 col-md-2">
<q-select
v-model="visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="columns"
option-value="name"
/>
</div>
2023-11-03 15:08:53 +07:00
</div>
<div class="col-12">
2025-10-08 10:37:36 +07:00
<p-table
:columns="columns"
:rows="rows"
2024-12-24 11:39:10 +07:00
row-key="id"
2023-11-03 15:08:53 +07:00
flat
bordered
2023-11-29 10:45:23 +07:00
:paging="false"
2023-11-03 15:08:53 +07:00
dense
:visible-columns="visibleColumns"
:rows-per-page-options="[10, 25, 50, 100]"
2025-10-08 10:37:36 +07:00
v-model:pagination="pagination"
@request="onRequest"
2023-11-03 15:08:53 +07:00
>
<template v-slot:header="props">
<q-tr :props="props">
2024-07-24 16:37:04 +07:00
<q-th auto-width />
2023-11-03 15:08:53 +07:00
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
2024-07-24 16:37:04 +07:00
<q-td auto-width class="text-right">
2023-11-03 15:08:53 +07:00
<q-btn
v-if="
props.row.status == 'PENDING' &&
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
2023-11-03 15:08:53 +07:00
color="orange"
class="q-px-md"
dense
unelevated
2025-10-08 10:37:36 +07:00
@click="unapprove(props.row.fullName, props.row.id)"
2023-11-03 15:08:53 +07:00
>ไมอน</q-btn
>
<q-btn
v-if="
props.row.status == 'PENDING' &&
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
2023-11-03 15:08:53 +07:00
color="primary"
class="q-px-md q-ml-sm"
dense
unelevated
2025-10-08 10:37:36 +07:00
@click="openModal(props.row)"
2023-11-03 15:08:53 +07:00
>
2025-10-08 10:37:36 +07:00
อน
</q-btn>
<q-badge
v-if="props.row.status == 'APPROVE'"
rounded
outline
color="green"
label="อนุมัติ"
/>
<q-badge
v-if="props.row.status == 'REJECT'"
rounded
outline
color="red"
label="ไม่อนุมัติ"
/>
2023-11-03 15:08:53 +07:00
</q-td>
2024-07-24 16:37:04 +07:00
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'">
2025-10-08 10:37:36 +07:00
{{ props.rowIndex + 1 }}
2024-07-24 16:37:04 +07:00
</div>
<div
v-else-if="col.name === 'description'"
class="table_ellipsis"
>
2024-12-24 11:39:10 +07:00
{{ col.value ?? "-" }}
2024-07-24 16:37:04 +07:00
</div>
<div v-else>
2024-12-24 11:39:10 +07:00
{{ col.value ?? "-" }}
2024-07-24 16:37:04 +07:00
</div>
</q-td>
2023-11-03 15:08:53 +07:00
</q-tr>
</template>
2025-10-08 10:37:36 +07:00
</p-table>
</div>
</q-card>
2023-12-20 16:32:35 +07:00
<DialogReason
v-model:modal="modalUnapprove"
:title="dialogTitle"
:desc="dialogDesc"
label="เหตุผล"
:savaForm="clickSave"
/>
2024-07-24 16:37:04 +07:00
<DialogApprove
:modal="modalApprove"
:closeDialog="closeDialog"
:date="dateDialog"
:dateFix="dateFixDialog"
:id="id"
:description="description"
:editCheck="editCheck"
:detailData="detailData"
2024-12-24 11:39:10 +07:00
:fetch-data="fetchData"
/>
</template>
<style></style>