fix(leave):sort
This commit is contained in:
parent
7a833e0ee5
commit
fb3902edce
15 changed files with 388 additions and 973 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from "vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import type { QTableProps } from "quasar";
|
||||
|
||||
|
|
@ -8,11 +8,10 @@ import config from "@/app.config";
|
|||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { useSpecialTimeStore } from "@/modules/09_leave/stores/SpecialTimeStore";
|
||||
import { checkPermission } from "@/utils/permissions";
|
||||
import { usePagination } from "@/composables/usePagination";
|
||||
|
||||
import type {
|
||||
DataDateMonthObject,
|
||||
DetailData,
|
||||
} from "@/modules/09_leave/interface/request/specialTime";
|
||||
import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime";
|
||||
import type { DataSpecialTime } from "@/modules/09_leave/interface/index/Main";
|
||||
|
||||
import DialogReason from "@/components/Dialogs/PopupReason.vue";
|
||||
import DialogApprove from "@/modules/09_leave/components/04_SpecialTime/DialogApprove.vue";
|
||||
|
|
@ -29,20 +28,22 @@ const {
|
|||
date2Thai,
|
||||
dialogConfirm,
|
||||
} = mixin;
|
||||
const { pagination, params, onRequest } = usePagination("", fetchData);
|
||||
|
||||
const emit = defineEmits(["update:change-page"]);
|
||||
const rows = ref<any[]>([]);
|
||||
|
||||
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);
|
||||
const description = ref<string>('')
|
||||
const description = ref<string>("");
|
||||
|
||||
/**ตัวแปรที่ใช้ */
|
||||
const modalUnapprove = ref<boolean>(false);
|
||||
const modalApprove = ref<boolean>(false);
|
||||
const detailData = ref<DetailData[]>([]);
|
||||
const detailData = ref<DataSpecialTime>();
|
||||
const editCheck = ref<string>("");
|
||||
const dialogTitle = ref<string>("");
|
||||
const dialogDesc = ref<string>("");
|
||||
|
|
@ -58,26 +59,16 @@ const dateMonth = ref<DataDateMonthObject>({
|
|||
year: new Date().getFullYear(),
|
||||
});
|
||||
|
||||
const total = ref<number>(0);
|
||||
const totalList = ref<number>(1);
|
||||
const pagination = ref({
|
||||
sortBy: "createdAt",
|
||||
descending: true,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
// ค้นหาในตาราง
|
||||
const filterKeyword = ref<string>("");
|
||||
const filterRef = ref<HTMLInputElement | null>(null);
|
||||
|
||||
const rows = ref<DataSpecialTime[]>([]);
|
||||
const visibleColumns = ref<String[]>([
|
||||
"no",
|
||||
"fullname",
|
||||
"date",
|
||||
"dateFix",
|
||||
"timeMorning",
|
||||
"timeAfternoon",
|
||||
"fullName",
|
||||
"createdAt",
|
||||
"checkDate",
|
||||
"startTimeMorning",
|
||||
"startTimeAfternoon",
|
||||
"description",
|
||||
]);
|
||||
const columns = ref<QTableProps["columns"]>([
|
||||
|
|
@ -91,16 +82,16 @@ const columns = ref<QTableProps["columns"]>([
|
|||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "fullname",
|
||||
name: "fullName",
|
||||
align: "left",
|
||||
label: "ชื่อ-นามสกุล",
|
||||
sortable: true,
|
||||
field: "fullname",
|
||||
field: "fullName",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "date",
|
||||
name: "createdAt",
|
||||
align: "left",
|
||||
label: "วันที่ยื่นเรื่อง",
|
||||
sortable: true,
|
||||
|
|
@ -109,7 +100,7 @@ const columns = ref<QTableProps["columns"]>([
|
|||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "dateFix",
|
||||
name: "checkDate",
|
||||
align: "left",
|
||||
label: "วันที่ขอแก้ไข",
|
||||
sortable: true,
|
||||
|
|
@ -118,7 +109,7 @@ const columns = ref<QTableProps["columns"]>([
|
|||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "timeMorning",
|
||||
name: "startTimeMorning",
|
||||
align: "left",
|
||||
label: "ช่วงเช้า",
|
||||
sortable: true,
|
||||
|
|
@ -127,7 +118,7 @@ const columns = ref<QTableProps["columns"]>([
|
|||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "timeAfternoon",
|
||||
name: "startTimeAfternoon",
|
||||
align: "left",
|
||||
label: "ช่วงบ่าย",
|
||||
sortable: true,
|
||||
|
|
@ -146,6 +137,54 @@ const columns = ref<QTableProps["columns"]>([
|
|||
},
|
||||
]);
|
||||
|
||||
/** ฟังก์ชั่นเรียกดูข้อมูลรายการลงเวลากรณีพิเศษ */
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชั่นไม่อนุมัติ
|
||||
* @param fullname ชื่อ
|
||||
|
|
@ -158,43 +197,39 @@ async function unapprove(fullname: string, personId: string) {
|
|||
modalUnapprove.value = true;
|
||||
}
|
||||
|
||||
/** function openDialog */
|
||||
function openModal(
|
||||
data: any,
|
||||
check: string,
|
||||
date: string,
|
||||
dateFix: string,
|
||||
personId: string,
|
||||
detail: string,
|
||||
) {
|
||||
id.value = personId;
|
||||
/**
|
||||
* ฟังก์ชั่นอนุมัติ
|
||||
* @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;
|
||||
dateDialog.value = date;
|
||||
description.value= detail
|
||||
dateFixDialog.value = dateFix;
|
||||
editCheck.value = check;
|
||||
if (check === "PENDING") {
|
||||
detailData.value = data;
|
||||
}
|
||||
}
|
||||
|
||||
/** function closeDialog */
|
||||
/** ฟังก์ชั่นปิด Dialog */
|
||||
function closeDialog() {
|
||||
modalUnapprove.value = false;
|
||||
modalApprove.value = false;
|
||||
description.value = '';
|
||||
description.value = "";
|
||||
editCheck.value = "PENDING";
|
||||
}
|
||||
|
||||
/** API reject */
|
||||
/**
|
||||
* ฟังก์ชั่นบันทึกข้อมูลไม่อนุมัติ
|
||||
* @param reason เหตุผลที่ไม่อนุมัติ
|
||||
*/
|
||||
async function clickSave(reason: string) {
|
||||
dialogConfirm($q, async () => {
|
||||
showLoader();
|
||||
const body = {
|
||||
reason: reason,
|
||||
};
|
||||
await http
|
||||
.put(config.API.specialTimeReject(id.value), body)
|
||||
.put(config.API.specialTimeReject(id.value), {
|
||||
reason: reason,
|
||||
})
|
||||
.then(async () => {
|
||||
await fetchData();
|
||||
success($q, "บันทึกข้อมูลสำเร็จ");
|
||||
|
|
@ -219,97 +254,22 @@ async function updateMonth(e: DataDateMonthObject) {
|
|||
dateYear.value = year.value;
|
||||
month.value = dateMonth.value.month + 1;
|
||||
year.value = dateMonth.value.year;
|
||||
getSearch();
|
||||
onSearchData();
|
||||
}
|
||||
}
|
||||
|
||||
//แปลงเดือนเป็นไทย
|
||||
function monthYearThai(val: any) {
|
||||
function monthYearThai(val: DataDateMonthObject) {
|
||||
if (val == null) return "";
|
||||
else return monthYear2Thai(val.month, val.year);
|
||||
}
|
||||
|
||||
function updatePagination(newPagination: any) {
|
||||
pagination.value.page = 1;
|
||||
pagination.value.rowsPerPage = newPagination.rowsPerPage;
|
||||
}
|
||||
|
||||
function getSearch() {
|
||||
/** ฟังก์ชั่นค้นหาข้อมูล */
|
||||
function onSearchData() {
|
||||
pagination.value.page = 1;
|
||||
fetchData();
|
||||
}
|
||||
|
||||
watch(
|
||||
() => pagination.value.rowsPerPage,
|
||||
async () => {
|
||||
getSearch();
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* ฟังชั้นเรียกดูข้อมูล
|
||||
*/
|
||||
async function fetchData() {
|
||||
showLoader();
|
||||
await http
|
||||
.get(
|
||||
config.API.specialTime() +
|
||||
`?year=${year.value}&month=${month.value}&page=${
|
||||
pagination.value.page
|
||||
}&pageSize=${
|
||||
pagination.value.rowsPerPage
|
||||
}&keyword=${filterKeyword.value.trim()}`
|
||||
)
|
||||
.then(async (res) => {
|
||||
let data = await res.data.result.data;
|
||||
total.value = res.data.result.total;
|
||||
totalList.value = Math.ceil(
|
||||
res.data.result.total / pagination.value.rowsPerPage
|
||||
);
|
||||
total.value = res.data.result.total;
|
||||
rows.value = [];
|
||||
data.map((e: any) => {
|
||||
rows.value.push({
|
||||
id: e.id,
|
||||
fullname: e.fullName,
|
||||
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
|
||||
: "-",
|
||||
startTimeMorning: e.startTimeMorning,
|
||||
endTimeMorning: e.endTimeMorning,
|
||||
startTimeAfternoon: e.startTimeAfternoon,
|
||||
endTimeAfternoon: e.endTimeAfternoon,
|
||||
checkIn: e.checkInTime,
|
||||
checkOut: e.checkOutTime,
|
||||
status: e.status,
|
||||
checkInStatus: store.convertStatus(e.checkInStatus),
|
||||
checkOutStatus: store.convertStatus(e.checkOutStatus),
|
||||
reason: e.reason,
|
||||
description: e.description,
|
||||
checkInEdit: e.checkInEdit,
|
||||
checkOutEdit: e.checkOutEdit,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/**Hook */
|
||||
onMounted(async () => {
|
||||
//อัพเดทเป็นวันปัจจุบันเมื่อเข้าหน้านี้
|
||||
|
|
@ -326,9 +286,10 @@ onMounted(async () => {
|
|||
<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">
|
||||
|
||||
<q-card flat bordered class="col-12 q-pa-md">
|
||||
<div class="row col-12 q-col-gutter-sm q-mb-sm">
|
||||
<div class="q-gutter-sm">
|
||||
<div class="col-xs-12 col-sm-3 col-md-2">
|
||||
<datepicker
|
||||
v-model="dateMonth"
|
||||
:locale="'th'"
|
||||
|
|
@ -347,7 +308,6 @@ onMounted(async () => {
|
|||
dense
|
||||
outlined
|
||||
hide-bottom-space
|
||||
style="width: 130px"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
|
|
@ -363,39 +323,38 @@ onMounted(async () => {
|
|||
</div>
|
||||
|
||||
<q-space />
|
||||
<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>
|
||||
|
||||
<q-input
|
||||
class="col-xs-12 col-sm-3 col-md-2"
|
||||
standout
|
||||
dense
|
||||
v-model="filterKeyword"
|
||||
ref="filterRef"
|
||||
outlined
|
||||
placeholder="ค้นหาชื่อ-นามสกุล"
|
||||
@keydown.enter.prevent="getSearch()"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</q-input>
|
||||
|
||||
<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"
|
||||
style="min-width: 140px"
|
||||
class="col-xs-12 col-sm-3 col-md-2"
|
||||
/>
|
||||
<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>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<d-table
|
||||
<p-table
|
||||
:columns="columns"
|
||||
:rows="rows"
|
||||
row-key="id"
|
||||
|
|
@ -405,7 +364,8 @@ onMounted(async () => {
|
|||
dense
|
||||
:visible-columns="visibleColumns"
|
||||
:rows-per-page-options="[10, 25, 50, 100]"
|
||||
@update:pagination="updatePagination"
|
||||
v-model:pagination="pagination"
|
||||
@request="onRequest"
|
||||
>
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
|
|
@ -428,7 +388,7 @@ onMounted(async () => {
|
|||
class="q-px-md"
|
||||
dense
|
||||
unelevated
|
||||
@click="unapprove(props.row.fullname, props.row.id)"
|
||||
@click="unapprove(props.row.fullName, props.row.id)"
|
||||
>ไม่อนุมัติ</q-btn
|
||||
>
|
||||
<q-btn
|
||||
|
|
@ -441,18 +401,10 @@ onMounted(async () => {
|
|||
class="q-px-md q-ml-sm"
|
||||
dense
|
||||
unelevated
|
||||
@click="
|
||||
openModal(
|
||||
props.row,
|
||||
'PENDING',
|
||||
props.row.date,
|
||||
props.row.dateFix,
|
||||
props.row.id,
|
||||
props.row.description
|
||||
)
|
||||
"
|
||||
>อนุมัติ</q-btn
|
||||
@click="openModal(props.row)"
|
||||
>
|
||||
อนุมัติ
|
||||
</q-btn>
|
||||
|
||||
<q-badge
|
||||
v-if="props.row.status == 'APPROVE'"
|
||||
|
|
@ -471,11 +423,7 @@ onMounted(async () => {
|
|||
</q-td>
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<div v-if="col.name == 'no'">
|
||||
{{
|
||||
(pagination.page - 1) * pagination.rowsPerPage +
|
||||
props.rowIndex +
|
||||
1
|
||||
}}
|
||||
{{ props.rowIndex + 1 }}
|
||||
</div>
|
||||
<div
|
||||
v-else-if="col.name === 'description'"
|
||||
|
|
@ -489,22 +437,7 @@ onMounted(async () => {
|
|||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
|
||||
<template v-slot:pagination="scope">
|
||||
ทั้งหมด {{ total }} รายการ
|
||||
<q-pagination
|
||||
v-model="pagination.page"
|
||||
active-color="primary"
|
||||
color="dark"
|
||||
:max="Number(totalList)"
|
||||
size="sm"
|
||||
boundary-links
|
||||
direction-links
|
||||
:max-pages="5"
|
||||
@update:model-value="fetchData()"
|
||||
></q-pagination>
|
||||
</template>
|
||||
</d-table>
|
||||
</p-table>
|
||||
</div>
|
||||
</q-card>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue