2023-11-02 16:44:02 +07:00
|
|
|
<script setup lang="ts">
|
2023-11-27 16:31:45 +07:00
|
|
|
import { onMounted, ref, watch } from "vue";
|
2023-11-02 16:44:02 +07:00
|
|
|
import { useQuasar } from "quasar";
|
2023-11-27 16:31:45 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
2023-12-15 09:58:02 +07:00
|
|
|
|
|
|
|
|
/** importType*/
|
2023-11-30 17:11:03 +07:00
|
|
|
import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime";
|
2023-11-29 10:45:23 +07:00
|
|
|
|
2023-12-15 09:58:02 +07:00
|
|
|
/** importComponents*/
|
|
|
|
|
import DialogReason from "@/components/Dialogs/PopupReason.vue";
|
|
|
|
|
import DialogApprove from "@/modules/09_leave/components/4_specialTime/DialogApprove.vue";
|
|
|
|
|
|
|
|
|
|
/** importStore*/
|
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
|
import { useSpecialTimeStore } from "@/modules/09_leave/stores/SpecialTimeStore";
|
|
|
|
|
|
2023-11-02 16:44:02 +07:00
|
|
|
const dataSpecialTime = useSpecialTimeStore();
|
|
|
|
|
const $q = useQuasar(); // show dialog
|
|
|
|
|
const mixin = useCounterMixin();
|
2023-12-15 09:58:02 +07:00
|
|
|
|
2023-11-27 16:31:45 +07:00
|
|
|
const { hideLoader, monthYear2Thai, messageError, showLoader, success } = mixin;
|
2023-12-15 09:58:02 +07:00
|
|
|
|
|
|
|
|
const emit = defineEmits(["update:change-page"]);
|
|
|
|
|
|
|
|
|
|
/**ตัวแปรที่ใช้ */
|
2023-11-02 16:44:02 +07:00
|
|
|
const modalUnapprove = ref(false);
|
2023-11-06 15:08:36 +07:00
|
|
|
const modalApprove = ref(false);
|
|
|
|
|
const detailData = ref<any>();
|
|
|
|
|
const editCheck = ref<string>("");
|
2023-11-02 16:44:02 +07:00
|
|
|
const dialogTitle = ref<string>("");
|
|
|
|
|
const dialogDesc = ref<string>("");
|
2023-11-06 15:08:36 +07:00
|
|
|
const name = ref<string>("");
|
2023-11-27 16:31:45 +07:00
|
|
|
const id = ref<string>("");
|
2023-11-06 15:08:36 +07:00
|
|
|
const dateDialog = ref<string>("");
|
|
|
|
|
const dateFixDialog = ref<string>("");
|
2023-11-30 17:11:03 +07:00
|
|
|
const dateYear = ref<number>(new Date().getFullYear());
|
2023-11-29 10:45:23 +07:00
|
|
|
|
2023-12-15 09:58:02 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชั่นไม่อนุมัติ
|
|
|
|
|
* @param fullname ชื่อ
|
|
|
|
|
* @param personId personId
|
|
|
|
|
*/
|
|
|
|
|
async function unapprove(fullname: string, personId: string) {
|
2023-11-27 16:31:45 +07:00
|
|
|
id.value = personId;
|
2023-12-15 09:58:02 +07:00
|
|
|
dialogTitle.value = " ไม่อนุมัติคำขอ"; // + fullname;
|
2023-11-02 16:44:02 +07:00
|
|
|
name.value = fullname;
|
|
|
|
|
modalUnapprove.value = true;
|
2023-12-15 09:58:02 +07:00
|
|
|
}
|
2023-11-30 17:11:03 +07:00
|
|
|
|
2023-12-15 09:58:02 +07:00
|
|
|
/** function openDialog */
|
2023-11-27 16:31:45 +07:00
|
|
|
function openModal(
|
|
|
|
|
data: any,
|
|
|
|
|
check: string,
|
|
|
|
|
date: string,
|
|
|
|
|
dateFix: string,
|
|
|
|
|
personId: string
|
|
|
|
|
) {
|
|
|
|
|
id.value = personId;
|
|
|
|
|
console.log(personId);
|
2023-11-06 15:08:36 +07:00
|
|
|
modalApprove.value = true;
|
|
|
|
|
dateDialog.value = date;
|
|
|
|
|
dateFixDialog.value = dateFix;
|
|
|
|
|
editCheck.value = check;
|
|
|
|
|
if (check === "PENDING") {
|
|
|
|
|
detailData.value = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-15 09:58:02 +07:00
|
|
|
|
|
|
|
|
/** function closeDialog */
|
2023-11-06 15:08:36 +07:00
|
|
|
const closeDialog = () => {
|
2023-11-02 16:44:02 +07:00
|
|
|
modalUnapprove.value = false;
|
2023-11-06 15:08:36 +07:00
|
|
|
modalApprove.value = false;
|
|
|
|
|
editCheck.value = "PENDING";
|
2023-11-02 16:44:02 +07:00
|
|
|
};
|
2023-11-27 16:31:45 +07:00
|
|
|
|
|
|
|
|
/** API reject */
|
|
|
|
|
const clickSave = async (reason: string) => {
|
2023-12-15 09:58:02 +07:00
|
|
|
showLoader();
|
2023-11-02 16:44:02 +07:00
|
|
|
modalUnapprove.value = false;
|
2023-11-27 16:31:45 +07:00
|
|
|
const body = {
|
|
|
|
|
reason: reason,
|
|
|
|
|
};
|
|
|
|
|
await http
|
|
|
|
|
.put(config.API.specialTimeReject(id.value), body)
|
2023-12-15 09:58:02 +07:00
|
|
|
.then(() => {
|
2023-11-27 16:31:45 +07:00
|
|
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
messageError($q, e);
|
|
|
|
|
})
|
2023-11-30 17:11:03 +07:00
|
|
|
.finally(async () => {
|
2023-12-15 09:58:02 +07:00
|
|
|
await dataSpecialTime.fetchData();
|
|
|
|
|
hideLoader();
|
2023-11-30 17:11:03 +07:00
|
|
|
});
|
2023-11-02 16:44:02 +07:00
|
|
|
};
|
|
|
|
|
|
2023-11-29 10:45:23 +07:00
|
|
|
// paging
|
|
|
|
|
const pageSize = ref<number>(10);
|
2023-12-15 09:58:02 +07:00
|
|
|
|
2023-11-29 10:45:23 +07:00
|
|
|
// Pagination - initial pagination
|
|
|
|
|
const initialPagination = ref<any>({
|
|
|
|
|
sortBy: null,
|
|
|
|
|
descending: false,
|
|
|
|
|
page: 1,
|
|
|
|
|
rowsPerPage: pageSize, // set ตาม page หลักส่งมา
|
|
|
|
|
});
|
2023-12-15 09:58:02 +07:00
|
|
|
|
2023-11-29 10:45:23 +07:00
|
|
|
// Pagination - page & change page & get new data
|
|
|
|
|
const currentPage = ref<number>(1);
|
|
|
|
|
watch(
|
|
|
|
|
[() => currentPage.value, () => initialPagination.value.rowsPerPage],
|
|
|
|
|
async () => {
|
|
|
|
|
dataSpecialTime.page = currentPage.value;
|
|
|
|
|
await dataSpecialTime.fetchData();
|
|
|
|
|
}
|
|
|
|
|
);
|
2023-11-30 17:11:03 +07:00
|
|
|
|
2023-11-29 10:45:23 +07:00
|
|
|
// Pagination - update rowsPerPage
|
2023-11-30 17:11:03 +07:00
|
|
|
async function updatePagination(initialPagination: any) {
|
2023-11-29 10:45:23 +07:00
|
|
|
currentPage.value = 1;
|
2023-11-30 17:11:03 +07:00
|
|
|
dataSpecialTime.pageSize = initialPagination.rowsPerPage;
|
2023-11-29 10:45:23 +07:00
|
|
|
dataSpecialTime.page = 1; // set current page เป็น 1 เสมอเมื่อเปลี่ยน per row
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 17:11:03 +07:00
|
|
|
// ค้นหาในตาราง
|
|
|
|
|
const filterKeyword = ref<string>("");
|
|
|
|
|
const filterRef = ref<HTMLInputElement | null>(null);
|
|
|
|
|
const resetFilter = () => {
|
|
|
|
|
filterKeyword.value = "";
|
|
|
|
|
dataSpecialTime.filter = filterKeyword.value;
|
|
|
|
|
dataSpecialTime.fetchData();
|
|
|
|
|
if (filterRef.value) {
|
|
|
|
|
filterRef.value.focus();
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-12-15 09:58:02 +07:00
|
|
|
|
2023-11-30 17:11:03 +07:00
|
|
|
/** function ค้นหาข้อมูลแล้วอัปเดท*/
|
|
|
|
|
function filterFn() {
|
|
|
|
|
updatePagination(filterKeyword.value);
|
|
|
|
|
console.log(filterKeyword.value);
|
|
|
|
|
dataSpecialTime.filter = filterKeyword.value;
|
|
|
|
|
dataSpecialTime.pageSize = pageSize.value;
|
|
|
|
|
dataSpecialTime.fetchData();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 10:45:23 +07:00
|
|
|
/** Function Date */
|
2023-11-03 15:08:53 +07:00
|
|
|
const dateMonth = ref<any>({
|
|
|
|
|
month: new Date().getMonth(),
|
|
|
|
|
year: new Date().getFullYear(),
|
|
|
|
|
});
|
2023-11-30 17:11:03 +07:00
|
|
|
const updateMonth = async (e: DataDateMonthObject) => {
|
|
|
|
|
// console.log(dateMonth.value);
|
|
|
|
|
if (e != null) {
|
|
|
|
|
dateYear.value = e.year;
|
|
|
|
|
dateYear.value = dataSpecialTime.year;
|
|
|
|
|
dataSpecialTime.month = dateMonth.value.month + 1;
|
|
|
|
|
dataSpecialTime.year = dateMonth.value.year;
|
|
|
|
|
// filterKeyword.value = "";
|
2023-12-06 12:07:56 +07:00
|
|
|
await dataSpecialTime.fetchData();
|
|
|
|
|
console.log(dateMonth);
|
2023-11-30 17:11:03 +07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-06 12:07:56 +07:00
|
|
|
/**Hook */
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
//อัพเดทเป็นวันปัจจุบันเมื่อเข้าหน้านี้
|
|
|
|
|
const toDay = ref<Date>(new Date());
|
|
|
|
|
const monthToday = toDay.value.getMonth();
|
|
|
|
|
const yearToday = toDay.value.getFullYear();
|
|
|
|
|
dataSpecialTime.month = monthToday + 1;
|
|
|
|
|
dataSpecialTime.year = yearToday;
|
|
|
|
|
await dataSpecialTime.fetchData();
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-30 17:11:03 +07:00
|
|
|
//แปลงเดือนเป็นไทย
|
2023-11-03 15:08:53 +07:00
|
|
|
const monthYearThai = (val: any) => {
|
|
|
|
|
if (val == null) return "";
|
|
|
|
|
else return monthYear2Thai(val.month, val.year);
|
|
|
|
|
};
|
2023-11-02 16:44:02 +07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="toptitle text-dark col-12 row items-center">
|
|
|
|
|
รายการลงเวลากรณีพิเศษ
|
|
|
|
|
</div>
|
|
|
|
|
<q-card flat bordered class="col-12 q-mt-sm q-pt-sm q-pa-md">
|
2023-11-03 15:08:53 +07:00
|
|
|
<div class="row col-12 q-col-gutter-sm q-mb-sm">
|
|
|
|
|
<div class="q-gutter-sm">
|
|
|
|
|
<datepicker
|
2023-11-30 17:11:03 +07:00
|
|
|
v-model="dateMonth"
|
2023-11-03 15:08:53 +07:00
|
|
|
:locale="'th'"
|
|
|
|
|
autoApply
|
|
|
|
|
month-picker
|
|
|
|
|
:enableTimePicker="false"
|
2023-11-30 17:11:03 +07:00
|
|
|
@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
|
|
|
|
|
style="width: 130px"
|
|
|
|
|
>
|
|
|
|
|
<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 />
|
|
|
|
|
|
|
|
|
|
<q-input
|
|
|
|
|
class="col-xs-12 col-sm-3 col-md-2"
|
|
|
|
|
standout
|
|
|
|
|
dense
|
|
|
|
|
v-model="filterKeyword"
|
|
|
|
|
ref="filterRef"
|
|
|
|
|
outlined
|
|
|
|
|
debounce="300"
|
2023-11-30 17:11:03 +07:00
|
|
|
placeholder="ค้นหาชื่อ-นามสกุล"
|
|
|
|
|
@keydown.enter.prevent="filterFn"
|
2023-11-03 15:08:53 +07:00
|
|
|
>
|
|
|
|
|
<template v-slot:append>
|
|
|
|
|
<q-icon v-if="filterKeyword == ''" name="search" />
|
|
|
|
|
<q-icon
|
|
|
|
|
v-if="filterKeyword !== ''"
|
|
|
|
|
name="clear"
|
|
|
|
|
class="cursor-pointer"
|
|
|
|
|
@click="resetFilter"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</q-input>
|
|
|
|
|
|
|
|
|
|
<q-select
|
|
|
|
|
v-model="dataSpecialTime.visibleColumns"
|
|
|
|
|
multiple
|
|
|
|
|
outlined
|
|
|
|
|
dense
|
|
|
|
|
options-dense
|
|
|
|
|
:display-value="$q.lang.table.columns"
|
|
|
|
|
emit-value
|
|
|
|
|
map-options
|
|
|
|
|
:options="dataSpecialTime.columns"
|
|
|
|
|
option-value="name"
|
|
|
|
|
options-cover
|
|
|
|
|
style="min-width: 150px"
|
|
|
|
|
class="col-xs-12 col-sm-3 col-md-2"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="col-12">
|
|
|
|
|
<d-table
|
|
|
|
|
:columns="dataSpecialTime.columns"
|
|
|
|
|
:rows="dataSpecialTime.rows"
|
|
|
|
|
row-key="tb-list"
|
|
|
|
|
flat
|
|
|
|
|
bordered
|
2023-11-29 10:45:23 +07:00
|
|
|
:paging="false"
|
2023-11-03 15:08:53 +07:00
|
|
|
dense
|
|
|
|
|
:visible-columns="dataSpecialTime.visibleColumns"
|
2023-11-30 17:11:03 +07:00
|
|
|
:rows-per-page-options="[10, 25, 50, 100]"
|
2023-11-29 10:45:23 +07:00
|
|
|
v-model:pagination="initialPagination"
|
|
|
|
|
@update:pagination="updatePagination"
|
2023-11-03 15:08:53 +07:00
|
|
|
>
|
2023-11-29 10:45:23 +07:00
|
|
|
<template v-slot:pagination="scope">
|
|
|
|
|
ทั้งหมด {{ dataSpecialTime.total }} รายการ
|
|
|
|
|
<q-pagination
|
|
|
|
|
v-model="currentPage"
|
|
|
|
|
active-color="primary"
|
|
|
|
|
color="dark"
|
|
|
|
|
:max-pages="5"
|
|
|
|
|
size="sm"
|
|
|
|
|
boundary-links
|
|
|
|
|
direction-links
|
|
|
|
|
:max="Number(dataSpecialTime.maxPage)"
|
|
|
|
|
></q-pagination>
|
|
|
|
|
</template>
|
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" class="cursor-pointer">
|
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'"
|
|
|
|
|
color="orange"
|
|
|
|
|
class="q-px-md"
|
|
|
|
|
dense
|
|
|
|
|
unelevated
|
2023-11-27 16:31:45 +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'"
|
|
|
|
|
color="primary"
|
|
|
|
|
class="q-px-md q-ml-sm"
|
|
|
|
|
dense
|
|
|
|
|
unelevated
|
2023-11-06 15:08:36 +07:00
|
|
|
@click="
|
|
|
|
|
openModal(
|
|
|
|
|
props.row,
|
|
|
|
|
'PENDING',
|
|
|
|
|
props.row.date,
|
2023-11-27 16:31:45 +07:00
|
|
|
props.row.dateFix,
|
|
|
|
|
props.row.id
|
2023-11-06 15:08:36 +07:00
|
|
|
)
|
|
|
|
|
"
|
2023-11-03 15:08:53 +07:00
|
|
|
>อนุมัติ</q-btn
|
|
|
|
|
>
|
2023-11-06 15:08:36 +07:00
|
|
|
<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'">
|
|
|
|
|
{{
|
|
|
|
|
(dataSpecialTime.page - 1) * dataSpecialTime.pageSize +
|
|
|
|
|
props.rowIndex +
|
|
|
|
|
1
|
|
|
|
|
}}
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
v-else-if="col.name === 'description'"
|
|
|
|
|
class="table_ellipsis"
|
|
|
|
|
>
|
|
|
|
|
{{ props.row.description }}
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
{{ col.value }}
|
|
|
|
|
</div>
|
|
|
|
|
</q-td>
|
2023-11-03 15:08:53 +07:00
|
|
|
</q-tr>
|
|
|
|
|
</template>
|
|
|
|
|
</d-table>
|
2023-11-02 16:44:02 +07:00
|
|
|
</div>
|
|
|
|
|
</q-card>
|
2023-12-20 16:32:35 +07:00
|
|
|
|
2023-11-02 16:44:02 +07:00
|
|
|
<DialogReason
|
2024-03-08 17:49:08 +07:00
|
|
|
v-model:modal="modalUnapprove"
|
2023-11-02 16:44:02 +07:00
|
|
|
:title="dialogTitle"
|
|
|
|
|
:desc="dialogDesc"
|
|
|
|
|
label="เหตุผล"
|
|
|
|
|
:savaForm="clickSave"
|
|
|
|
|
/>
|
2024-07-24 16:37:04 +07:00
|
|
|
|
2023-11-06 15:08:36 +07:00
|
|
|
<DialogApprove
|
|
|
|
|
:modal="modalApprove"
|
|
|
|
|
:closeDialog="closeDialog"
|
|
|
|
|
:date="dateDialog"
|
|
|
|
|
:dateFix="dateFixDialog"
|
2023-11-27 16:31:45 +07:00
|
|
|
:id="id"
|
2023-11-06 15:08:36 +07:00
|
|
|
:editCheck="editCheck"
|
|
|
|
|
:detailData="detailData"
|
|
|
|
|
/>
|
2023-11-02 16:44:02 +07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style></style>
|