start commit for admin system
This commit is contained in:
commit
badb676529
300 changed files with 58634 additions and 0 deletions
855
src/modules/01_metadata/components/calendar/Calendar.vue
Normal file
855
src/modules/01_metadata/components/calendar/Calendar.vue
Normal file
|
|
@ -0,0 +1,855 @@
|
|||
<!-- tab ปฏิทิน หน้าปฏิทินวันหยุด -->
|
||||
<template>
|
||||
<div class="q-mt-md">
|
||||
<div class="row q-gutter-sm q-pb-sm main-content">
|
||||
<div class="demo-app-main">
|
||||
<!-- แสดงปฏิทิน -->
|
||||
<FullCalendar
|
||||
ref="fullCalendar"
|
||||
class="demo-app-calendar"
|
||||
:options="calendarOptions"
|
||||
>
|
||||
<template v-slot:eventContent="arg">
|
||||
<b>{{ arg.timeText }}</b>
|
||||
<i>{{ arg.event.title }}</i>
|
||||
<q-tooltip style="font-size: 15px">{{ arg.event.title }}</q-tooltip>
|
||||
</template>
|
||||
</FullCalendar>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row q-col-gutter-md">
|
||||
<div class="items-center row">
|
||||
<q-icon color="blue" name="mdi-circle" class="q-mr-sm" />
|
||||
วันทำงาน 5 วัน
|
||||
</div>
|
||||
<div class="items-center row">
|
||||
<q-icon color="orange" name="mdi-circle" class="q-mr-sm" />
|
||||
วันทำงาน 6 วัน
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- modal เพิ่มวันหยุด -->
|
||||
<q-dialog v-model="modalAdd" persistent>
|
||||
<q-card style="min-width: 550px">
|
||||
<q-form ref="formDate" @submit.prevent.stop="onSubmit">
|
||||
<q-card-section class="row items-center q-pa-sm">
|
||||
<div class="text-bold" v-if="showEdit">แก้ไขวันหยุด</div>
|
||||
<div class="text-bold" v-else>เพิ่มวันหยุด</div>
|
||||
<q-space />
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
round
|
||||
dense
|
||||
v-close-popup
|
||||
style="color: #ff8080; background-color: #ffdede"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section class="q-p-md row q-gutter-y-md">
|
||||
<div class="row col-12">
|
||||
<div class="col-12" v-if="!showEdit">
|
||||
{{ dateThaiRange(dateRange) }}
|
||||
</div>
|
||||
<datepicker
|
||||
v-else
|
||||
:readonly="!edit"
|
||||
v-model="dateRange"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
range
|
||||
:enableTimePicker="false"
|
||||
week-start="0"
|
||||
>
|
||||
<template #year="{ year }">
|
||||
{{ year + 543 }}
|
||||
</template>
|
||||
<template #year-overlay-value="{ value }">
|
||||
{{ parseInt(value + 543) }}
|
||||
</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:class="getClass(edit)"
|
||||
hide-bottom-space
|
||||
:outlined="edit"
|
||||
dense
|
||||
label="วันที่"
|
||||
:borderless="!edit"
|
||||
:model-value="dateThaiRange(dateRange)"
|
||||
>
|
||||
<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-input
|
||||
:class="getClass(edit)"
|
||||
hide-bottom-space
|
||||
:outlined="edit"
|
||||
label="คำอธิบาย"
|
||||
dense
|
||||
lazy-rules
|
||||
:readonly="!edit"
|
||||
:borderless="!edit"
|
||||
v-model="name"
|
||||
autogrow
|
||||
:rules="[(val) => (val && val.length > 0) || '']"
|
||||
/>
|
||||
<q-option-group
|
||||
v-if="showEdit == false"
|
||||
v-model="category"
|
||||
:options="categoryOptions"
|
||||
color="primary"
|
||||
inline
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn
|
||||
v-if="showEdit && edit"
|
||||
flat
|
||||
color="red"
|
||||
@click="cancelClick()"
|
||||
label="ยกเลิกแก้ไข"
|
||||
>
|
||||
<!-- icon="mdi-undo"
|
||||
<q-tooltip>ยกเลิก</q-tooltip> -->
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="showEdit && edit"
|
||||
unelevated
|
||||
color="red"
|
||||
@click="deleteClick()"
|
||||
label="ลบวันหยุด"
|
||||
>
|
||||
<!-- icon="mdi-delete"
|
||||
<q-tooltip>ลบ</q-tooltip> -->
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="edit"
|
||||
unelevated
|
||||
color="public"
|
||||
label="บันทึก"
|
||||
type="submit"
|
||||
>
|
||||
<!-- icon="mdi-content-save-outline"
|
||||
<q-tooltip>บันทึก</q-tooltip> -->
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="!edit"
|
||||
outline
|
||||
color="primary"
|
||||
@click="editClick"
|
||||
label="แก้ไขข้อมูล"
|
||||
>
|
||||
<!-- icon="mdi-pencil-outline"
|
||||
<q-tooltip>แก้ไขข้อมูล</q-tooltip> -->
|
||||
</q-btn>
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<!-- modal ลบวันหยุด -->
|
||||
<q-dialog v-model="modalDelete" persistent>
|
||||
<q-card style="min-width: 550px">
|
||||
<q-card-section class="row items-center q-pb-xs">
|
||||
<div class="text-bold">ต้องการลบข้อมูลนี้หรือไม่?</div>
|
||||
<q-space />
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
round
|
||||
dense
|
||||
v-close-popup
|
||||
style="color: #ff8080; background-color: #ffdede"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section class="row items-center">
|
||||
<div class="q-pr-md">
|
||||
<q-avatar
|
||||
icon="mdi-trash-can-outline"
|
||||
font-size="25px"
|
||||
size="lg"
|
||||
color="red-1"
|
||||
text-color="red"
|
||||
/>
|
||||
</div>
|
||||
<div class="col text-dark">
|
||||
<span>ข้อมูลที่กำลังถูกลบนี้จะมีผลใช้งานทันที</span>
|
||||
</div>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-actions align="right" class="bg-white text-teal">
|
||||
<q-btn label="ยกเลิก" flat color="grey-8" @click="cancelClick" />
|
||||
<q-btn label="ตกลง" color="primary" @click="deleteData" />
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import FullCalendar from "@fullcalendar/vue3";
|
||||
import dayGridPlugin from "@fullcalendar/daygrid";
|
||||
import timeGridPlugin from "@fullcalendar/timegrid";
|
||||
import interactionPlugin from "@fullcalendar/interaction";
|
||||
import allLocales from "@fullcalendar/core/locales-all";
|
||||
import listPlugin from "@fullcalendar/list";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
import type {
|
||||
RequestItemsObject,
|
||||
DataDateRowObject,
|
||||
DataDateAddObject,
|
||||
} from "@/modules/01_metadata/interface/index/Calendar";
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
const props = defineProps({
|
||||
dateYear: {
|
||||
//filter ปี วันหยุด
|
||||
type: Number,
|
||||
default: () => new Date().getFullYear(),
|
||||
},
|
||||
dateMonth: {
|
||||
//filter เดือน วันหยุด
|
||||
type: Number,
|
||||
default: () => new Date().getMonth(),
|
||||
},
|
||||
refreshData: {
|
||||
//หน้า main มีการอัพเดทค่าให้ refresh data
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
fetchDataSummaryCalendar: {
|
||||
//ฟังก์ชันอัพเดทสรุปวันหยุด
|
||||
type: Function,
|
||||
default: () => console.log("not function"),
|
||||
},
|
||||
});
|
||||
|
||||
const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง
|
||||
const { success, dateToISO, date2Thai, messageError, showLoader, hideLoader } =
|
||||
mixin;
|
||||
const $q = useQuasar(); //ใช้ noti quasar
|
||||
const modalAdd = ref<boolean>(false); //modal เพิ่มวันหยุด
|
||||
const modalDelete = ref<boolean>(false); //modal ลบวันหยุด
|
||||
const edit = ref<boolean>(false); //modal เลือกวันหยุดกับวันลบวันหยุด
|
||||
const showEdit = ref<boolean>(false); //กด event แก้ไขหรือเพิ่ม
|
||||
const name = ref<string>(""); //ชื่อวันหยุด
|
||||
const type = ref<string>(""); //ประเภทวันหยุด
|
||||
const isSpecial = ref<boolean>(true); //เช็ควันหยุด
|
||||
const id = ref<string>(""); //id ที่แก้ไขวันหยุด
|
||||
const fullCalendar = ref<any>(); //ref calendar
|
||||
const dateRange = ref<[Date, Date]>([new Date(), new Date()]); //วันที่ ที่เพิ่มเป็นวันหยุด
|
||||
const formDate = ref<any>(); //ref เพิ่ม แก้ไข วันหยุดสำหรับ validate
|
||||
|
||||
const category = ref<string>("all");
|
||||
const categoryOptions = ref<any>([
|
||||
{
|
||||
label: "ทั้งหมด",
|
||||
value: "all",
|
||||
},
|
||||
{
|
||||
label: "ทำงาน 5 วัน",
|
||||
value: "normal",
|
||||
},
|
||||
{
|
||||
label: "ทำงาน 6 วัน",
|
||||
value: "6days",
|
||||
},
|
||||
]);
|
||||
const dataHistory = ref<RequestItemsObject[]>([]);
|
||||
const dataNormalRaw = ref<RequestItemsObject[]>([]);
|
||||
const dataSixDaysRaw = ref<RequestItemsObject[]>([]);
|
||||
|
||||
/**
|
||||
* เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้
|
||||
*/
|
||||
onMounted(async () => {
|
||||
hideLoader();
|
||||
const calen = fullCalendar.value.getApi();
|
||||
const date = new Date(props.dateYear, props.dateMonth);
|
||||
calen.gotoDate(date);
|
||||
await fetchData();
|
||||
});
|
||||
|
||||
/**
|
||||
* ค่า props(วันเดือนปีที่เลือก) ตอนอัพเดท ค่าฏิทินให้อัพเดทใหม่
|
||||
*/
|
||||
watch(props, async (count, prevCount) => {
|
||||
const calen = fullCalendar.value.getApi();
|
||||
const date = new Date(props.dateYear, props.dateMonth);
|
||||
calen.gotoDate(date);
|
||||
await fetchData();
|
||||
});
|
||||
|
||||
/**
|
||||
* เลือกค่าปฏิทินในช่องว่าง
|
||||
* @param selectInfo ค่าที่เลือกในฏิทิน
|
||||
*/
|
||||
const handleDateSelect = async (selectInfo: any) => {
|
||||
edit.value = true;
|
||||
category.value = "all";
|
||||
selectInfo.start;
|
||||
const checkNormalDate = dataNormalRaw.value.filter(
|
||||
(r: RequestItemsObject) =>
|
||||
dateToISO(new Date(r.holidayDate)) == dateToISO(selectInfo.start)
|
||||
);
|
||||
const checkSixDaysDate = dataSixDaysRaw.value.filter(
|
||||
(r: RequestItemsObject) =>
|
||||
dateToISO(new Date(r.holidayDate)) == dateToISO(selectInfo.start)
|
||||
);
|
||||
if (checkNormalDate.length == 0 || checkSixDaysDate.length == 0) {
|
||||
name.value = "";
|
||||
isSpecial.value = true;
|
||||
dateRange.value = [
|
||||
selectInfo.startStr,
|
||||
new Date(
|
||||
new Date(selectInfo.endStr).setDate(
|
||||
new Date(selectInfo.endStr).getDate() - 1
|
||||
)
|
||||
),
|
||||
];
|
||||
showEdit.value = false;
|
||||
modalAdd.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* เลือกค่า event ในปฏิทิน
|
||||
* @param selectInfo ค่าที่เลือกในฏิทิน
|
||||
*/
|
||||
const handleEventClick = async (selectInfo: any) => {
|
||||
modalAdd.value = true;
|
||||
edit.value = false;
|
||||
showEdit.value = true;
|
||||
name.value = selectInfo.event.title;
|
||||
type.value = selectInfo.event.id;
|
||||
isSpecial.value = true;
|
||||
id.value = selectInfo.event.groupId;
|
||||
dataHistory.value = selectInfo.event.extendedProps.dataRangeRow;
|
||||
dateRange.value = [
|
||||
selectInfo.event.startStr,
|
||||
selectInfo.event.endStr == ""
|
||||
? selectInfo.event.startStr
|
||||
: dateToISO(
|
||||
new Date(
|
||||
new Date(selectInfo.event.endStr).setDate(
|
||||
new Date(selectInfo.event.endStr).getDate() - 1
|
||||
)
|
||||
)
|
||||
),
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* กดปุ่มแก้ไขให้แสดง modal แก้ไข
|
||||
*/
|
||||
const editClick = async () => {
|
||||
showEdit.value = true;
|
||||
edit.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* กดปุ่มลบให้แสดง modal ลบ
|
||||
*/
|
||||
const deleteClick = async () => {
|
||||
modalDelete.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* ปุ่มยกเลิกให้ย้อนกลับไป modal เลือกแก้ไขหรือลบ
|
||||
*/
|
||||
const cancelClick = async () => {
|
||||
modalDelete.value = false;
|
||||
modalAdd.value = true;
|
||||
edit.value = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* option calendar
|
||||
*/
|
||||
const calendarOptions = ref<any>({
|
||||
plugins: [
|
||||
dayGridPlugin,
|
||||
timeGridPlugin,
|
||||
interactionPlugin, // needed for dateClick
|
||||
listPlugin,
|
||||
],
|
||||
headerToolbar: null,
|
||||
selectable: true,
|
||||
select: handleDateSelect,
|
||||
eventClick: handleEventClick,
|
||||
locale: "th",
|
||||
locales: allLocales,
|
||||
height: "100%",
|
||||
eventColor: "#e4f3ff",
|
||||
eventTextColor: "#50a5fc",
|
||||
eventBorderColor: "#50a5fc",
|
||||
events: <any>[],
|
||||
firstDay: 0,
|
||||
});
|
||||
|
||||
/**
|
||||
* ปุ่มบันทึกข้อมูลวันหยุด
|
||||
*/
|
||||
const onSubmit = async () => {
|
||||
if (showEdit.value === true) {
|
||||
await editData();
|
||||
} else {
|
||||
await addDate();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* fetch วันหยุดในปฏิทิน
|
||||
*/
|
||||
const fetchData = async () => {
|
||||
calendarOptions.value.events = [];
|
||||
showLoader();
|
||||
await http
|
||||
.get(
|
||||
config.API.listHolidayHistoryYearMonth(
|
||||
props.dateYear,
|
||||
props.dateMonth + 1
|
||||
)
|
||||
)
|
||||
.then((res) => {
|
||||
const dataNormal = res.data.result.normal;
|
||||
const dataSixDays = res.data.result.sixDays;
|
||||
const dateStart = ref<Date | null>();
|
||||
const firstEvent = ref<boolean>(true);
|
||||
const dateRow = ref<DataDateRowObject[]>([]);
|
||||
dataNormalRaw.value = res.data.result.normal;
|
||||
dataSixDaysRaw.value = res.data.result.sixDays;
|
||||
dataNormal.map((e: RequestItemsObject, index: number) => {
|
||||
dateRow.value.push({
|
||||
holidayDate: new Date(e.holidayDate),
|
||||
name: e.name,
|
||||
isSpecial: true,
|
||||
id: e.id,
|
||||
});
|
||||
if (
|
||||
index == dataNormal.length - 1 ||
|
||||
dataNormal[index + 1].name != e.name ||
|
||||
(dataNormal[index + 1].name == e.name &&
|
||||
dateToISO(new Date(dataNormal[index + 1].holidayDate)) !=
|
||||
dateToISO(
|
||||
new Date(
|
||||
new Date(e.holidayDate).setDate(
|
||||
new Date(e.holidayDate).getDate() + 1
|
||||
)
|
||||
)
|
||||
))
|
||||
) {
|
||||
firstEvent.value = true;
|
||||
calendarOptions.value.events.push({
|
||||
id: "normal",
|
||||
groupId: e.id,
|
||||
title:
|
||||
dateToISO(new Date(e.holidayDate)) ==
|
||||
dateToISO(new Date(e.originalDate))
|
||||
? e.name
|
||||
: `ชดเชย ${e.name}`,
|
||||
start: dateStart.value ? dateStart.value : new Date(e.holidayDate),
|
||||
end: new Date(
|
||||
new Date(e.holidayDate).setDate(
|
||||
new Date(e.holidayDate).getDate() + 1
|
||||
)
|
||||
),
|
||||
isSpecial: true,
|
||||
allDay: true,
|
||||
dataRangeRow: dateRow.value,
|
||||
backgroundColor: "#CCE5FF",
|
||||
textColor: "#0080FF",
|
||||
});
|
||||
dateStart.value = null;
|
||||
dateRow.value = [];
|
||||
} else if (firstEvent.value == true) {
|
||||
firstEvent.value = false;
|
||||
dateStart.value = new Date(e.holidayDate);
|
||||
}
|
||||
});
|
||||
dataSixDays.map((e: RequestItemsObject, index: number) => {
|
||||
dateRow.value.push({
|
||||
holidayDate: new Date(e.holidayDate),
|
||||
name: e.name,
|
||||
isSpecial: true,
|
||||
id: e.id,
|
||||
});
|
||||
if (
|
||||
index == dataSixDays.length - 1 ||
|
||||
dataSixDays[index + 1].name != e.name ||
|
||||
(dataSixDays[index + 1].name == e.name &&
|
||||
dateToISO(new Date(dataSixDays[index + 1].holidayDate)) !=
|
||||
dateToISO(
|
||||
new Date(
|
||||
new Date(e.holidayDate).setDate(
|
||||
new Date(e.holidayDate).getDate() + 1
|
||||
)
|
||||
)
|
||||
))
|
||||
) {
|
||||
firstEvent.value = true;
|
||||
calendarOptions.value.events.push({
|
||||
id: "sixdays",
|
||||
groupId: e.id,
|
||||
title:
|
||||
dateToISO(new Date(e.holidayDate)) ==
|
||||
dateToISO(new Date(e.originalDate))
|
||||
? e.name
|
||||
: `ชดเชย ${e.name}`,
|
||||
start: dateStart.value ? dateStart.value : new Date(e.holidayDate),
|
||||
end: new Date(
|
||||
new Date(e.holidayDate).setDate(
|
||||
new Date(e.holidayDate).getDate() + 1
|
||||
)
|
||||
),
|
||||
isSpecial: true,
|
||||
allDay: true,
|
||||
dataRangeRow: dateRow.value,
|
||||
backgroundColor: "#FFE5CC",
|
||||
textColor: "#FF8000",
|
||||
});
|
||||
dateStart.value = null;
|
||||
dateRow.value = [];
|
||||
} else if (firstEvent.value == true) {
|
||||
firstEvent.value = false;
|
||||
dateStart.value = new Date(e.holidayDate);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
await props.fetchDataSummaryCalendar();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* บันทึกแก้ไขวันหยุด
|
||||
*/
|
||||
const editData = async () => {
|
||||
await formDate.value.validate().then(async (result: boolean) => {
|
||||
if (result) {
|
||||
const dataEdit = ref<DataDateAddObject[]>([]);
|
||||
let i = 0;
|
||||
const dateStart = ref<Date>(dateRange.value[0]);
|
||||
do {
|
||||
i = i + 1;
|
||||
dataEdit.value.push({
|
||||
year: new Date(dateStart.value).getFullYear(),
|
||||
holidayDate: dateToISO(new Date(dateStart.value)),
|
||||
name: name.value,
|
||||
isSpecial: true,
|
||||
});
|
||||
dateStart.value = new Date(
|
||||
new Date(dateStart.value).setDate(
|
||||
new Date(dateStart.value).getDate() + 1
|
||||
)
|
||||
);
|
||||
} while (new Date(dateStart.value) <= new Date(dateRange.value[1]));
|
||||
|
||||
const _dataHistory = ref<RequestItemsObject[]>([]);
|
||||
dataHistory.value.map((e: RequestItemsObject, index: number) => {
|
||||
_dataHistory.value.push({
|
||||
...e,
|
||||
holidayDate: dateToISO(new Date(e.holidayDate)),
|
||||
});
|
||||
});
|
||||
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.listHolidayHistoryEdit(type.value), {
|
||||
history: _dataHistory.value,
|
||||
updated: dataEdit.value,
|
||||
})
|
||||
.then((res) => {
|
||||
modalAdd.value = false;
|
||||
success($q, "แก้ไขข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
await fetchData();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* บันทึกเพิ่มวันหยุด
|
||||
*/
|
||||
const addDate = async () => {
|
||||
await formDate.value.validate().then(async (result: boolean) => {
|
||||
if (result) {
|
||||
const dataAdd = ref<DataDateAddObject[]>([]);
|
||||
let i = 0;
|
||||
const dateStart = ref<Date>(dateRange.value[0]);
|
||||
do {
|
||||
i = i + 1;
|
||||
dataAdd.value.push({
|
||||
year: new Date(dateStart.value).getFullYear(),
|
||||
holidayDate: dateToISO(new Date(dateStart.value)),
|
||||
name: name.value,
|
||||
isSpecial: true,
|
||||
});
|
||||
dateStart.value = new Date(
|
||||
new Date(dateStart.value).setDate(
|
||||
new Date(dateStart.value).getDate() + 1
|
||||
)
|
||||
);
|
||||
} while (new Date(dateStart.value) <= new Date(dateRange.value[1]));
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.listHolidayHistoryAdd(category.value), dataAdd.value)
|
||||
.then((res) => {
|
||||
modalAdd.value = false;
|
||||
success($q, "เพิ่มข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
await fetchData();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* ลบข้อมูลวันหยุด
|
||||
*/
|
||||
const deleteData = async () => {
|
||||
modalDelete.value = false;
|
||||
const dataDelete = ref<DataDateAddObject[]>([]);
|
||||
let i = 0;
|
||||
const dateStart = ref<Date>(dateRange.value[0]);
|
||||
do {
|
||||
i = i + 1;
|
||||
dataDelete.value.push({
|
||||
year: new Date(dateStart.value).getFullYear(),
|
||||
holidayDate: dateToISO(new Date(dateStart.value)),
|
||||
name: name.value,
|
||||
isSpecial: true,
|
||||
});
|
||||
dateStart.value = new Date(
|
||||
new Date(dateStart.value).setDate(new Date(dateStart.value).getDate() + 1)
|
||||
);
|
||||
} while (new Date(dateStart.value) <= new Date(dateRange.value[1]));
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.listHolidayHistoryDelete(type.value), dataDelete.value)
|
||||
.then((res) => {
|
||||
success($q, "ลบข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
modalAdd.value = false;
|
||||
await fetchData();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง
|
||||
* @param val ช่วงวันที่
|
||||
*/
|
||||
const dateThaiRange = (val: [Date, Date]) => {
|
||||
if (val === null) {
|
||||
} else if (date2Thai(val[0]) === date2Thai(val[1])) {
|
||||
return `${date2Thai(val[0])}`;
|
||||
} else {
|
||||
return `${date2Thai(val[0])} - ${date2Thai(val[1])} `;
|
||||
}
|
||||
};
|
||||
|
||||
const getClass = (val: boolean) => {
|
||||
return {
|
||||
"full-width inputgreen cursor-pointer": val,
|
||||
"full-width cursor-pointer": !val,
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scope lang="scss">
|
||||
.main-content {
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
.color-main {
|
||||
color: #18a259;
|
||||
}
|
||||
|
||||
.padding-content {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.demo-app-main {
|
||||
flex-grow: 1;
|
||||
/* padding: 3em; */
|
||||
}
|
||||
|
||||
.fc {
|
||||
/* the calendar root */
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.fc-day-today {
|
||||
background-color: rgb(255, 255, 255) !important;
|
||||
}
|
||||
|
||||
// .fc-day-sun {
|
||||
// background-color: rgba(207, 205, 205, 0.177) !important;
|
||||
// width: 80px;
|
||||
// }
|
||||
|
||||
// .fc-day-sat {
|
||||
// background-color: rgba(207, 205, 205, 0.177) !important;
|
||||
// width: 80px;
|
||||
// }
|
||||
|
||||
.fc-day-today .fc-daygrid-day-number {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/* border: 2px solid #17a259; */
|
||||
border-radius: 50%;
|
||||
height: 25px;
|
||||
width: 25px;
|
||||
font-weight: bold;
|
||||
color: white !important;
|
||||
background: #17a259;
|
||||
}
|
||||
|
||||
.fc-day-today .fc-daygrid-day-frame {
|
||||
padding: 5%;
|
||||
}
|
||||
|
||||
.fc .fc-button-group > .fc-button {
|
||||
color: black;
|
||||
background-color: #fafafa;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.fc .fc-button-group > .fc-button:active {
|
||||
color: white;
|
||||
background-color: #22a15e;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.fc .fc-button-group > .fc-button.fc-button-active {
|
||||
color: white;
|
||||
background-color: #22a15e;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.fc-header-toolbar {
|
||||
background-color: white;
|
||||
padding: 0px 10px 0px 10px;
|
||||
border-radius: 10px 10px 0px 0px;
|
||||
}
|
||||
|
||||
.fc .fc-scrollgrid-liquid > thead {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.dp-custom-cell {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.dp__today {
|
||||
border: 1px solid var(--q-primary);
|
||||
}
|
||||
|
||||
.dp__range_end,
|
||||
.dp__range_start,
|
||||
.dp__active_date {
|
||||
background: var(--q-primary);
|
||||
color: var(--dp-primary-text-color);
|
||||
}
|
||||
|
||||
.datepicker .q-field__label {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.datepicker .q-field__messages {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.datepicker .q-field__native {
|
||||
padding-left: 5px;
|
||||
color: var(--q-primary) !important;
|
||||
}
|
||||
|
||||
.datepicker .q-field__prepend {
|
||||
padding-left: 6px;
|
||||
}
|
||||
|
||||
.datepicker .q-field__append {
|
||||
padding-right: 6px;
|
||||
}
|
||||
|
||||
.datepicker .q-field__after {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.fc .fc-popover {
|
||||
z-index: 6000;
|
||||
}
|
||||
|
||||
.fc-direction-ltr .fc-daygrid-event.fc-event-end,
|
||||
.fc-direction-rtl .fc-daygrid-event.fc-event-start {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.subName {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.subInput {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.fc-event {
|
||||
overflow: hidden;
|
||||
border-color: transparent !important;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.fc-event-main {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fc-direction-ltr .fc-daygrid-event.fc-event-end,
|
||||
.fc-direction-rtl .fc-daygrid-event.fc-event-start {
|
||||
padding-left: 0px;
|
||||
}
|
||||
</style>
|
||||
651
src/modules/01_metadata/components/calendar/CalendarList.vue
Normal file
651
src/modules/01_metadata/components/calendar/CalendarList.vue
Normal file
|
|
@ -0,0 +1,651 @@
|
|||
<!-- tab รายการ หน้าปฏิทินวันหยุด -->
|
||||
<template>
|
||||
<q-card class="q-mt-md" flat bordered>
|
||||
<!-- list รายการันหยุด -->
|
||||
<q-tabs
|
||||
dense
|
||||
v-model="currentTab"
|
||||
indicator-color="primary"
|
||||
active-color="primary bg-teal-1"
|
||||
class="text-body2 text-grey-7"
|
||||
>
|
||||
<q-tab
|
||||
v-for="tab in tabs"
|
||||
:key="tab.value"
|
||||
v-on:click="changeTab(tab.value)"
|
||||
:label="tab.label"
|
||||
:name="tab.value"
|
||||
class="q-py-xs col-6 row"
|
||||
/>
|
||||
</q-tabs>
|
||||
<q-separator />
|
||||
|
||||
<q-tab-panels v-model="currentTab" animated>
|
||||
<q-tab-panel name="normal">
|
||||
<q-table
|
||||
ref="table"
|
||||
flat
|
||||
bordered
|
||||
class="custom-header-table"
|
||||
virtual-scroll
|
||||
:rows="calendarData"
|
||||
:columns="columns"
|
||||
dense
|
||||
:rows-per-page-options="[0]"
|
||||
hide-header
|
||||
>
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props">
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<div v-if="col.name == 'week'" class="">
|
||||
{{ dayThaiRange(props.row.dateRange) }}
|
||||
</div>
|
||||
<div v-else-if="col.name == 'holidayDate'" class="">
|
||||
{{ dateThaiRange(props.row.dateRange) }}
|
||||
</div>
|
||||
<div v-else class="my-table-details">
|
||||
{{ col.value }}
|
||||
</div>
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
color="grey"
|
||||
@click.stop
|
||||
size="10px"
|
||||
icon="more_vert"
|
||||
>
|
||||
<q-menu>
|
||||
<q-list>
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="editCalendar(props.row)"
|
||||
>
|
||||
<q-item-section>
|
||||
<q-item-label>แก้ไขวันหยุด</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="deleteClick(props.row)"
|
||||
>
|
||||
<q-item-section>
|
||||
<q-item-label>ลบวันหยุด</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-tab-panel>
|
||||
|
||||
<q-tab-panel name="6day">
|
||||
<q-table
|
||||
ref="table"
|
||||
flat
|
||||
bordered
|
||||
class="custom-header-table"
|
||||
virtual-scroll
|
||||
:rows="calendarData"
|
||||
:columns="columns"
|
||||
dense
|
||||
:rows-per-page-options="[0]"
|
||||
hide-header
|
||||
>
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props">
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<div v-if="col.name == 'week'" class="">
|
||||
{{ dayThaiRange(props.row.dateRange) }}
|
||||
</div>
|
||||
<div v-else-if="col.name == 'holidayDate'" class="">
|
||||
{{ dateThaiRange(props.row.dateRange) }}
|
||||
</div>
|
||||
<div v-else class="my-table-details">
|
||||
{{ col.value }}
|
||||
</div>
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
color="grey"
|
||||
@click.stop
|
||||
size="10px"
|
||||
icon="more_vert"
|
||||
>
|
||||
<q-menu>
|
||||
<q-list>
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="editCalendar(props.row)"
|
||||
>
|
||||
<q-item-section>
|
||||
<q-item-label>แก้ไขวันหยุด</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="deleteClick(props.row)"
|
||||
>
|
||||
<q-item-section>
|
||||
<q-item-label>ลบวันหยุด</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-tab-panel>
|
||||
</q-tab-panels>
|
||||
</q-card>
|
||||
|
||||
<!-- modal เพิ่มวันหยุด -->
|
||||
<q-dialog v-model="modalAdd" persistent>
|
||||
<q-card style="min-width: 550px">
|
||||
<q-form ref="formDate" @submit.prevent.stop="editData">
|
||||
<q-card-section class="row items-center q-pb-xs">
|
||||
<div class="text-bold">แก้ไขวันหยุด</div>
|
||||
<q-space />
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
round
|
||||
dense
|
||||
v-close-popup
|
||||
style="color: #ff8080; background-color: #ffdede"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section class="q-p-sm">
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<div class="col-2 subName">
|
||||
<label>เลือกวันที่</label>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<datepicker
|
||||
v-model="dateAdd"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
range
|
||||
:enableTimePicker="false"
|
||||
week-start="0"
|
||||
>
|
||||
<template #year="{ year }">
|
||||
{{ year + 543 }}
|
||||
</template>
|
||||
<template #year-overlay-value="{ value }">
|
||||
{{ parseInt(value + 543) }}
|
||||
</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
outlined
|
||||
dense
|
||||
class="full-width datepicker"
|
||||
:model-value="dateThaiRange(dateAdd)"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<div class="col-2 subName">
|
||||
<label>คำอธิบาย</label>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<q-input
|
||||
dense
|
||||
borderless
|
||||
class="full-width datepicker q-pb-none"
|
||||
v-model="name"
|
||||
type="textarea"
|
||||
:rules="[(val) => (val && val.length > 0) || '']"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn unelevated label="บันทึก" color="public" type="submit">
|
||||
<!-- icon="mdi-content-save-outline"
|
||||
<q-tooltip>บันทึก</q-tooltip> -->
|
||||
</q-btn>
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<!-- modal ลบวันหยุด -->
|
||||
<q-dialog v-model="modalDelete" persistent>
|
||||
<q-card style="min-width: 550px">
|
||||
<q-card-section class="row items-center q-pb-xs">
|
||||
<div class="text-bold">ต้องการลบข้อมูลนี้หรือไม่?</div>
|
||||
<q-space />
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
round
|
||||
dense
|
||||
v-close-popup
|
||||
style="color: #ff8080; background-color: #ffdede"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section class="row items-center">
|
||||
<div class="q-pr-md">
|
||||
<q-avatar
|
||||
icon="mdi-trash-can-outline"
|
||||
font-size="25px"
|
||||
size="lg"
|
||||
color="red-1"
|
||||
text-color="red"
|
||||
/>
|
||||
</div>
|
||||
<div class="col text-dark">
|
||||
<span>ข้อมูลที่กำลังถูกลบนี้จะมีผลใช้งานทันที</span>
|
||||
</div>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-actions align="right" class="bg-white text-teal">
|
||||
<q-btn label="ตกลง" color="primary" @click="deleteConfirm" />
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
import type {
|
||||
RequestItemsObject,
|
||||
DataDateRowObject,
|
||||
DataDateAddObject,
|
||||
DataDateListsObject,
|
||||
TabsObject,
|
||||
} from "@/modules/01_metadata/interface/index/Calendar";
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
const props = defineProps({
|
||||
dateYear: {
|
||||
//filter ปี วันหยุด
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
refreshData: {
|
||||
//หน้า main มีการอัพเดทค่าให้ refresh data
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
fetchDataSummaryCalendar: {
|
||||
//ฟังก์ชันอัพเดทสรุปวันหยุด
|
||||
type: Function,
|
||||
default: () => console.log("not function"),
|
||||
},
|
||||
});
|
||||
|
||||
const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง
|
||||
const {
|
||||
success,
|
||||
dateToISO,
|
||||
dateMonth2Thai,
|
||||
weekThai,
|
||||
messageError,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
} = mixin;
|
||||
const $q = useQuasar(); //ใช้ noti quasar
|
||||
const calendarData = ref<DataDateListsObject[]>([]); //data วันหยุด
|
||||
const modalAdd = ref<boolean>(false); //modal เพิ่มวันหยุด
|
||||
const modalDelete = ref<boolean>(false); //modal ลบวันหยุด
|
||||
const name = ref<string>(""); //ชื่อวันหยุด
|
||||
const isSpecial = ref<boolean>(true); //เช็ควันหยุด
|
||||
const dateAdd = ref<[Date, Date]>([new Date(), new Date()]); //วันที่ ที่เพิ่มเป็นวันหยุด
|
||||
const rowData = ref<DataDateListsObject>(); //data ที่ถูกเลือกใน row นั้น
|
||||
const formDate = ref<any>(); //ref เพิ่ม แก้ไข วันหยุดสำหรับ validate
|
||||
|
||||
const currentTab = ref<string>("normal"); //เลือก tab ประเภทวันหยุด
|
||||
const tabs = ref<TabsObject[]>([
|
||||
{ label: "ทำงานจันทร์-ศุกร์ (5 วัน)", value: "normal" },
|
||||
{ label: "ทำงานจันทร์-เสาร์ (6 วัน)", value: "6day" },
|
||||
]); //tab ประเภทวันหยุดทั้งหมด
|
||||
|
||||
//columns รายการวันหยุด
|
||||
const columns = ref<any>([
|
||||
{
|
||||
name: "week",
|
||||
align: "left",
|
||||
label: "-",
|
||||
sortable: true,
|
||||
field: "week",
|
||||
style: "font-size: 15px",
|
||||
},
|
||||
{
|
||||
name: "holidayDate",
|
||||
align: "left",
|
||||
label: "-",
|
||||
sortable: true,
|
||||
field: "holidayDate",
|
||||
style: "font-size: 15px",
|
||||
},
|
||||
{
|
||||
name: "detail",
|
||||
align: "left",
|
||||
label: "-",
|
||||
sortable: true,
|
||||
field: "detail",
|
||||
style: "font-size: 15px",
|
||||
},
|
||||
]);
|
||||
|
||||
/**
|
||||
* เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้
|
||||
*/
|
||||
onMounted(async () => {
|
||||
await fetchData();
|
||||
});
|
||||
|
||||
/**
|
||||
* ค่า props(วันปีที่เลือก และเพิ่มหรือแก้ไข) ตอนอัพเดท ค่าฏิทินให้อัพเดทใหม่
|
||||
*/
|
||||
watch(props, async (count, prevCount) => {
|
||||
await fetchData();
|
||||
});
|
||||
|
||||
/**
|
||||
* กดปุ่มแก้ไขวันหยุด
|
||||
* @param val data วันหยุดทั้ง row
|
||||
*/
|
||||
const editCalendar = async (val: DataDateListsObject) => {
|
||||
rowData.value = val;
|
||||
dateAdd.value = [val.dateRange[0], val.dateRange[1]];
|
||||
name.value = val.detail;
|
||||
isSpecial.value = true;
|
||||
modalAdd.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* กดปุ่มลบวันหยุด
|
||||
* @param val data วันหยุดทั้ง row
|
||||
*/
|
||||
const deleteClick = async (val: DataDateListsObject) => {
|
||||
rowData.value = val;
|
||||
modalDelete.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* fetch วันหยุดในรายการ
|
||||
*/
|
||||
const fetchData = async () => {
|
||||
calendarData.value = [];
|
||||
showLoader();
|
||||
await http
|
||||
.get(config.API.listHolidayHistoryYear(props.dateYear))
|
||||
.then((res) => {
|
||||
let data = res.data.result.normal;
|
||||
if (currentTab.value == "6day") {
|
||||
data = res.data.result.sixDays;
|
||||
}
|
||||
const dateStart = ref<Date | null>();
|
||||
const firstEvent = ref<boolean>(true);
|
||||
const dateRow = ref<DataDateRowObject[]>([]);
|
||||
data.map((e: RequestItemsObject, index: number) => {
|
||||
dateRow.value.push({
|
||||
holidayDate: new Date(e.holidayDate),
|
||||
name: e.name,
|
||||
isSpecial: true,
|
||||
id: e.id,
|
||||
});
|
||||
if (
|
||||
index == data.length - 1 ||
|
||||
data[index + 1].name != e.name ||
|
||||
(data[index + 1].name == e.name &&
|
||||
dateToISO(new Date(data[index + 1].holidayDate)) !=
|
||||
dateToISO(
|
||||
new Date(
|
||||
new Date(e.holidayDate).setDate(
|
||||
new Date(e.holidayDate).getDate() + 1
|
||||
)
|
||||
)
|
||||
))
|
||||
) {
|
||||
firstEvent.value = true;
|
||||
calendarData.value.push({
|
||||
id: e.id,
|
||||
dateRange: [
|
||||
dateStart.value ? dateStart.value : new Date(e.holidayDate),
|
||||
new Date(e.holidayDate),
|
||||
],
|
||||
dataRangeRow: dateRow.value,
|
||||
detail:
|
||||
dateToISO(new Date(e.holidayDate)) ==
|
||||
dateToISO(new Date(e.originalDate))
|
||||
? e.name
|
||||
: `ชดเชย ${e.name}`,
|
||||
isSpecial: true,
|
||||
});
|
||||
dateStart.value = null;
|
||||
dateRow.value = [];
|
||||
} else if (firstEvent.value == true) {
|
||||
firstEvent.value = false;
|
||||
dateStart.value = new Date(e.holidayDate);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
await props.fetchDataSummaryCalendar();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* ลบข้อมูลวันหยุด
|
||||
*/
|
||||
const deleteConfirm = async () => {
|
||||
modalDelete.value = false;
|
||||
const dataDelete = ref<DataDateAddObject[]>([]);
|
||||
if (rowData.value != null) {
|
||||
await rowData.value.dataRangeRow.map((e: DataDateRowObject) => {
|
||||
dataDelete.value.push({
|
||||
year: new Date(e.holidayDate).getFullYear(),
|
||||
holidayDate: dateToISO(e.holidayDate),
|
||||
name: e.name,
|
||||
isSpecial: true,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
showLoader();
|
||||
await http
|
||||
.post(
|
||||
config.API.listHolidayHistoryDelete(currentTab.value),
|
||||
dataDelete.value
|
||||
)
|
||||
.then((res) => {
|
||||
success($q, "ลบข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
await fetchData();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* บันทึกแก้ไขวันหยุด
|
||||
*/
|
||||
const editData = async () => {
|
||||
await formDate.value.validate().then(async (result: boolean) => {
|
||||
if (result) {
|
||||
const dataEdit = ref<DataDateAddObject[]>([]);
|
||||
let i = 0;
|
||||
const dateStart = ref<Date>(dateAdd.value[0]);
|
||||
do {
|
||||
i = i + 1;
|
||||
dataEdit.value.push({
|
||||
year: new Date(dateStart.value).getFullYear(),
|
||||
holidayDate: dateToISO(new Date(dateStart.value)),
|
||||
name: name.value,
|
||||
isSpecial: true,
|
||||
});
|
||||
dateStart.value = new Date(
|
||||
new Date(dateStart.value).setDate(
|
||||
new Date(dateStart.value).getDate() + 1
|
||||
)
|
||||
);
|
||||
} while (new Date(dateStart.value) <= new Date(dateAdd.value[1]));
|
||||
const _dataHistory = ref<DataDateAddObject[]>([]);
|
||||
if (rowData.value != null) {
|
||||
rowData.value.dataRangeRow.map(
|
||||
(e: DataDateRowObject, index: number) => {
|
||||
_dataHistory.value.push({
|
||||
year: new Date(e.holidayDate).getFullYear(),
|
||||
holidayDate: dateToISO(e.holidayDate),
|
||||
name: e.name,
|
||||
isSpecial: true,
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.listHolidayHistoryEdit(currentTab.value), {
|
||||
history: _dataHistory.value,
|
||||
updated: dataEdit.value,
|
||||
})
|
||||
.then((res) => {
|
||||
modalAdd.value = false;
|
||||
success($q, "แก้ไขข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
await fetchData();
|
||||
});
|
||||
} else {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* เปลี่ยน tab ดูวันหยุดตามประเภท
|
||||
* @param tab tab ประเภทวันหยุดที่เลือก
|
||||
*/
|
||||
const changeTab = async (tab: string) => {
|
||||
currentTab.value = tab;
|
||||
await fetchData();
|
||||
};
|
||||
|
||||
/**
|
||||
* แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง
|
||||
* @param val ช่วงวันที่
|
||||
*/
|
||||
const dateThaiRange = (val: [Date, Date]) => {
|
||||
if (val === null) {
|
||||
return "";
|
||||
} else if (dateMonth2Thai(val[0], true) === dateMonth2Thai(val[1], true)) {
|
||||
return `${dateMonth2Thai(val[0], true)}`;
|
||||
} else {
|
||||
return `${dateMonth2Thai(val[0], true)} - ${dateMonth2Thai(val[1], true)}`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง(เช่นวันจันทร์ -วันศุกร์)
|
||||
* @param val ช่วงวันที่
|
||||
*/
|
||||
const dayThaiRange = (val: [Date, Date]) => {
|
||||
if (val === null) {
|
||||
} else if (dateToISO(val[0]) == dateToISO(val[1])) {
|
||||
return `${weekThai(new Date(val[0]).getDay())}`;
|
||||
} else {
|
||||
return `${weekThai(new Date(val[0]).getDay())} - ${weekThai(
|
||||
new Date(val[1]).getDay()
|
||||
)}`;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scope>
|
||||
.custom-header-table {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.my-table-details {
|
||||
white-space: -moz-pre-wrap !important;
|
||||
/* Mozilla, since 1999 */
|
||||
white-space: -webkit-pre-wrap;
|
||||
/* Chrome & Safari */
|
||||
white-space: -pre-wrap;
|
||||
/* Opera 4-6 */
|
||||
white-space: -o-pre-wrap;
|
||||
/* Opera 7 */
|
||||
white-space: pre-wrap;
|
||||
/* CSS3 */
|
||||
word-wrap: break-word;
|
||||
/* Internet Explorer 5.5+ */
|
||||
word-break: break-all;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.table_ellipsis {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: wrap;
|
||||
max-width: 250px;
|
||||
}
|
||||
</style>
|
||||
589
src/modules/01_metadata/components/calendar/calendarMain.vue
Normal file
589
src/modules/01_metadata/components/calendar/calendarMain.vue
Normal file
|
|
@ -0,0 +1,589 @@
|
|||
<!-- page:จัดการข้อมูลหลัก tab วันหยุด -->
|
||||
<template>
|
||||
<div>
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<div class="row items-center">
|
||||
<!-- filter เลือกเดือนปี -->
|
||||
<datepicker
|
||||
v-model="dateMonth"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
month-picker
|
||||
:enableTimePicker="false"
|
||||
v-if="currentTab === 'calendar'"
|
||||
@update:modelValue="updateMonth"
|
||||
>
|
||||
<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
|
||||
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>
|
||||
|
||||
<!-- filter เลือกปี -->
|
||||
<datepicker
|
||||
v-model="dateYear"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
year-picker
|
||||
:enableTimePicker="false"
|
||||
v-if="currentTab === 'list'"
|
||||
@update:modelValue="updateYear"
|
||||
>
|
||||
<template #year="{ year }">{{ year + 543 }}</template>
|
||||
<template #year-overlay-value="{ value }">{{
|
||||
parseInt(value + 543)
|
||||
}}</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:model-value="dateYear + 543"
|
||||
dense
|
||||
outlined
|
||||
style="width: 100px"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
<div class="q-ml-sm">
|
||||
<!-- icon เพิ่มวันหยุด -->
|
||||
<q-btn round dense flat size="13px" class="q-px-sm">
|
||||
<q-icon
|
||||
name="mdi-plus"
|
||||
size="25px"
|
||||
color="primary"
|
||||
@click="addCalendar()"
|
||||
/>
|
||||
<q-tooltip>เพิ่มวันหยุด</q-tooltip>
|
||||
</q-btn>
|
||||
<!-- icon คัดลอกวันหยุด -->
|
||||
<q-btn round dense flat size="13px" class="q-px-sm">
|
||||
<q-icon
|
||||
name="mdi-content-copy"
|
||||
size="22px"
|
||||
color="blue-6"
|
||||
@click="copyCalendar()"
|
||||
/>
|
||||
<q-tooltip>คัดลอกวันหยุด</q-tooltip>
|
||||
</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
<q-space />
|
||||
<div class="justify-center row q-gutter-md items-center">
|
||||
<!-- tab รูปแบบแสดงวันหยุด ปฏิทินกับรายการ -->
|
||||
<q-tabs
|
||||
v-model="currentTab"
|
||||
indicator-color="transparent"
|
||||
align="left"
|
||||
active-color="activetab"
|
||||
class="text-nativetab"
|
||||
inline-label
|
||||
dense
|
||||
>
|
||||
<q-btn
|
||||
name="calendar"
|
||||
round
|
||||
flat
|
||||
icon="mdi-calendar-month"
|
||||
@click="currentTab = 'calendar'"
|
||||
:color="currentTab == 'calendar' ? 'primary' : ''"
|
||||
class="q-mr-sm"
|
||||
>
|
||||
<q-tooltip>ปฏิทิน</q-tooltip>
|
||||
</q-btn>
|
||||
<q-separator vertical inset />
|
||||
<q-btn
|
||||
name="list"
|
||||
round
|
||||
flat
|
||||
icon="mdi-format-list-bulleted"
|
||||
@click="currentTab = 'list'"
|
||||
:color="currentTab == 'list' ? 'primary' : ''"
|
||||
class="q-ml-sm"
|
||||
>
|
||||
<q-tooltip>รายการ</q-tooltip>
|
||||
</q-btn>
|
||||
</q-tabs>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<!-- component ปฏิทินวันหยุด -->
|
||||
<subCalendarComponent
|
||||
v-if="currentTab === 'calendar'"
|
||||
:dateYear="dateMonth.year"
|
||||
:dateMonth="dateMonth.month"
|
||||
:refreshData="refreshData"
|
||||
:fetchDataSummaryCalendar="fetchDataSummaryCalendar"
|
||||
/>
|
||||
<!-- component รายการวันหยุด -->
|
||||
<subCalendarListComponent
|
||||
v-if="currentTab === 'list'"
|
||||
:dateYear="dateYear"
|
||||
:refreshData="refreshData"
|
||||
:fetchDataSummaryCalendar="fetchDataSummaryCalendar"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<!-- modal เพิ่มวันหยุด -->
|
||||
<q-dialog v-model="modalAdd" persistent>
|
||||
<q-card style="min-width: 550px">
|
||||
<q-form ref="formDate" @submit.prevent.stop="onSubmit">
|
||||
<q-card-section class="row items-center q-py-sm">
|
||||
<div class="text-bold">เพิ่มวันหยุด</div>
|
||||
<q-space />
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
round
|
||||
dense
|
||||
v-close-popup
|
||||
style="color: #ff8080; background-color: #ffdede"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section class="q-p-md row q-gutter-y-sm">
|
||||
<datepicker
|
||||
v-model="dateAdd"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
range
|
||||
:enableTimePicker="false"
|
||||
week-start="0"
|
||||
>
|
||||
<template #year="{ year }">
|
||||
{{ year + 543 }}
|
||||
</template>
|
||||
<template #year-overlay-value="{ value }">
|
||||
{{ parseInt(value + 543) }}
|
||||
</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:model-value="dateThaiRange(dateAdd)"
|
||||
outlined
|
||||
label="เลือกวันที่"
|
||||
dense
|
||||
class="full-width datepicker"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
<q-input
|
||||
dense
|
||||
label="คำอธิบาย"
|
||||
outlined
|
||||
class="full-width datepicker q-pb-none"
|
||||
v-model="name"
|
||||
type="textarea"
|
||||
:rules="[(val) => (val && val.length > 0) || '']"
|
||||
/>
|
||||
<q-option-group
|
||||
dense
|
||||
v-model="category"
|
||||
:options="categoryOptions"
|
||||
color="primary"
|
||||
inline
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn unelevated label="บันทึก" color="public" type="submit">
|
||||
<!-- icon="mdi-content-save-outline"
|
||||
<q-tooltip>บันทึก</q-tooltip> -->
|
||||
</q-btn>
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<!-- modal คัดลอกวันหยุด -->
|
||||
<q-dialog v-model="modalCopy" persistent>
|
||||
<q-card style="min-width: 500px">
|
||||
<q-form @submit.prevent.stop="onSubmitCopy">
|
||||
<q-card-section class="row items-center q-py-sm">
|
||||
<div class="text-bold">คัดลอกวันหยุดปีก่อนหน้า</div>
|
||||
<q-space />
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
round
|
||||
dense
|
||||
v-close-popup
|
||||
style="color: #ff8080; background-color: #ffdede"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section class="q-p-sm">
|
||||
<div class="row col-12 q-col-gutter-sm">
|
||||
<datepicker
|
||||
v-model="dateYearStart"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
year-picker
|
||||
:enableTimePicker="false"
|
||||
>
|
||||
<template #year="{ year }">{{ year + 543 }}</template>
|
||||
<template #year-overlay-value="{ value }">{{
|
||||
parseInt(value + 543)
|
||||
}}</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:model-value="dateYearStart + 543"
|
||||
dense
|
||||
outlined
|
||||
class="q-pb-sm"
|
||||
label="ปีที่คัดลอกวันหยุด"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
<datepicker
|
||||
v-model="dateYearEnd"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
year-picker
|
||||
:enableTimePicker="false"
|
||||
:min-date="minDate"
|
||||
>
|
||||
<template #year="{ year }">{{ year + 543 }}</template>
|
||||
<template #year-overlay-value="{ value }">{{
|
||||
parseInt(value + 543)
|
||||
}}</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
:model-value="dateYearEnd + 543"
|
||||
dense
|
||||
outlined
|
||||
label="ปีที่ลงวันหยุดคัดลอก"
|
||||
class="q-pb-sm"
|
||||
>
|
||||
<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-card-section>
|
||||
<q-separator />
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn unelevated label="บันทึก" color="public" type="submit">
|
||||
<!-- icon="mdi-content-save-outline"
|
||||
<q-tooltip>บันทึก</q-tooltip> -->
|
||||
</q-btn>
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted } from "vue";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
import { useQuasar } from "quasar";
|
||||
|
||||
import type {
|
||||
DataDateMonthObject,
|
||||
DataDateAddObject,
|
||||
} from "@/modules/01_metadata/interface/index/Calendar";
|
||||
|
||||
import subCalendarComponent from "@/modules/01_metadata/components/calendar/Calendar.vue";
|
||||
import subCalendarListComponent from "@/modules/01_metadata/components/calendar/CalendarList.vue";
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
const props = defineProps({
|
||||
dateYear: Number, //ปีที่ส่งไป parent สรุปวันหยุด
|
||||
fetchDataSummaryCalendar: {
|
||||
//ฟังก์ชันอัพเดทสรุปวันหยุด
|
||||
type: Function,
|
||||
default: () => console.log("not function"),
|
||||
},
|
||||
});
|
||||
|
||||
const $q = useQuasar(); //ใช้ noti quasar
|
||||
const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง
|
||||
const {
|
||||
success,
|
||||
dateToISO,
|
||||
monthYear2Thai,
|
||||
date2Thai,
|
||||
messageError,
|
||||
dialogMessage,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
} = mixin;
|
||||
|
||||
const currentTab = ref<string>("calendar"); //ระบุ tab ใช้งานอยู่ calendar=รายการ list=รายการ
|
||||
const modalAdd = ref<boolean>(false); //แสดง modal add calendar
|
||||
const modalCopy = ref<boolean>(false); //แสดง modal copy calendar
|
||||
const dateMonth = ref<DataDateMonthObject>({
|
||||
month: new Date().getMonth(),
|
||||
year: new Date().getFullYear(),
|
||||
}); //ค่าเดือนที่เลือก tab ปฏิทิน
|
||||
const dateYear = ref<number>(new Date().getFullYear()); //ค่าปีที่เลือก tab รายการ
|
||||
const dateYearStart = ref<number>(new Date().getFullYear()); //ค่าปีที่ copy วันหยุด
|
||||
const dateYearEnd = ref<number>(new Date().getFullYear()); //ค่าปีที่จะลงวันหยุด copy
|
||||
const dateAdd = ref<[Date, Date]>([new Date(), new Date()]); //วันที่ ที่เพิ่มเป็นวันหยุด
|
||||
const formDate = ref<any>(); //ref เช็ค validate เพิ่มวันหยุด
|
||||
const name = ref<string>(""); //ชื่อวันหยุด
|
||||
const isSpecial = ref<boolean>(true); //เช็ควันหยุดพิเศษ
|
||||
|
||||
const category = ref<string>("all");
|
||||
const categoryOptions = ref<any>([
|
||||
{
|
||||
label: "ทั้งหมด",
|
||||
value: "all",
|
||||
},
|
||||
{
|
||||
label: "ทำงาน 5 วัน",
|
||||
value: "normal",
|
||||
},
|
||||
{
|
||||
label: "ทำงาน 6 วัน",
|
||||
value: "6days",
|
||||
},
|
||||
]);
|
||||
const minDate = ref<Date>();
|
||||
const refreshData = ref<boolean>(false); //ส่งค่าให้ component refresh data วันหยุด
|
||||
const emit = defineEmits(["update:dateYear"]);
|
||||
|
||||
/**
|
||||
* มีการเลือก datepicker ให้แปลงค่าเป็น text ที่แสดง
|
||||
*/
|
||||
watch(dateYearStart, () => {
|
||||
dateYearEnd.value = dateYearStart.value + 1;
|
||||
minDate.value = new Date(`${dateYearStart.value + 1}-01-01`);
|
||||
});
|
||||
|
||||
/**
|
||||
* เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้
|
||||
*/
|
||||
onMounted(async () => {
|
||||
dateYearEnd.value = dateYearStart.value + 1;
|
||||
minDate.value = new Date(`${dateYearStart.value + 1}-01-01`);
|
||||
});
|
||||
|
||||
/**
|
||||
* ค่าเดือนปีที่ถูกเลือกใน component ปฏิทินจะให้อัพเดทค่าสรุปวันหยุดรวม
|
||||
* @param e เลือกเดือนปี tab ปฏิทิน
|
||||
*/
|
||||
const updateMonth = async (e: DataDateMonthObject) => {
|
||||
if (e != null) {
|
||||
dateYear.value = e.year;
|
||||
emit("update:dateYear", e.year);
|
||||
await props.fetchDataSummaryCalendar();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* ค่าปีที่ถูกเลือกใน component รายการจะให้อัพเดทค่าสรุปวันหยุดรวม
|
||||
* @param e เลือกปี tab รายการ
|
||||
*/
|
||||
const updateYear = async (e: number) => {
|
||||
dateMonth.value = { month: 0, year: e };
|
||||
emit("update:dateYear", dateYear.value);
|
||||
await props.fetchDataSummaryCalendar();
|
||||
};
|
||||
|
||||
/**
|
||||
* ฟังก์ชันปุ่มเพิ่มวันหยุดแบบเลือกวันได้
|
||||
*/
|
||||
const addCalendar = () => {
|
||||
dateAdd.value = [new Date(), new Date()];
|
||||
name.value = "";
|
||||
category.value = "all";
|
||||
isSpecial.value = true;
|
||||
modalAdd.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* ฟังก์ชัน copy วันหยุดจากปีนิงไปอีกปี
|
||||
*/
|
||||
const copyCalendar = () => {
|
||||
modalCopy.value = true;
|
||||
dateYearStart.value = new Date().getFullYear();
|
||||
dateYearEnd.value = new Date().getFullYear() + 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* ฟังก์ชันปุ่มบันทึกเพิ่มวันหยุด
|
||||
*/
|
||||
const onSubmit = async () => {
|
||||
await formDate.value.validate().then(async (result: boolean) => {
|
||||
if (result) {
|
||||
const dataAdd = ref<DataDateAddObject[]>([]);
|
||||
let i = 0;
|
||||
const dateStart = ref<Date>(dateAdd.value[0]);
|
||||
do {
|
||||
i = i + 1;
|
||||
dataAdd.value.push({
|
||||
year: new Date(dateStart.value).getFullYear(),
|
||||
holidayDate: dateToISO(new Date(dateStart.value)),
|
||||
name: name.value,
|
||||
isSpecial: true,
|
||||
});
|
||||
dateStart.value = new Date(
|
||||
new Date(dateStart.value).setDate(
|
||||
new Date(dateStart.value).getDate() + 1
|
||||
)
|
||||
);
|
||||
} while (new Date(dateStart.value) <= new Date(dateAdd.value[1]));
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.listHolidayHistoryAdd(category.value), dataAdd.value)
|
||||
.then(() => {
|
||||
modalAdd.value = false;
|
||||
success($q, "เพิ่มวันหยุดสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(() => {
|
||||
refreshData.value = !refreshData.value;
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
});
|
||||
await props.fetchDataSummaryCalendar();
|
||||
};
|
||||
|
||||
/**
|
||||
* ฟังก์ชันคัดลอกวันหยุด
|
||||
*/
|
||||
const onSubmitCopy = async () => {
|
||||
if (dateYearStart.value >= dateYearEnd.value) {
|
||||
dialogMessage(
|
||||
$q,
|
||||
"ไม่สามารถคัดลอกวันหยุดได้",
|
||||
"ปีที่เริ่มต้นคัดลอกต้องมากกว่าปีที่จะลงวันคัดลอก",
|
||||
"warning",
|
||||
undefined,
|
||||
"orange",
|
||||
undefined,
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
return;
|
||||
}
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.listHolidayCopy, {
|
||||
fromYear: dateYearStart.value,
|
||||
toYear: dateYearEnd.value,
|
||||
})
|
||||
.then(() => {
|
||||
modalCopy.value = false;
|
||||
success($q, "คัดลอกวันหยุดสำเร็จ");
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(async () => {
|
||||
refreshData.value = !refreshData.value;
|
||||
await props.fetchDataSummaryCalendar();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* แปลง ปีและเดือนเป็นภาษาไทย
|
||||
* @param val datepicker แบบเลือกปีและเดือน
|
||||
*/
|
||||
const monthYearThai = (val: DataDateMonthObject) => {
|
||||
if (val == null) return "";
|
||||
else return monthYear2Thai(val.month, val.year);
|
||||
};
|
||||
|
||||
/**
|
||||
* แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง
|
||||
* @param val ช่วงวันที่
|
||||
*/
|
||||
const dateThaiRange = (val: [Date, Date] | []) => {
|
||||
if (val.length === 0) {
|
||||
} else if (date2Thai(val[0]) === date2Thai(val[1])) {
|
||||
return `${date2Thai(val[0])}`;
|
||||
} else {
|
||||
return `${date2Thai(val[0])} - ${date2Thai(val[1])} `;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.my-menu-link {
|
||||
color: black;
|
||||
background: #d0d0d0;
|
||||
}
|
||||
|
||||
.my-list-link {
|
||||
color: black;
|
||||
border-radius: 5px;
|
||||
background: #f4f4f4;
|
||||
}
|
||||
|
||||
.my-list {
|
||||
padding: 10px 10px;
|
||||
}
|
||||
|
||||
.my-card {
|
||||
width: 100%;
|
||||
max-width: 160px;
|
||||
}
|
||||
|
||||
.sub-card {
|
||||
height: 100%;
|
||||
max-height: 265px;
|
||||
}
|
||||
|
||||
.cardNum {
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.fc-direction-ltr .fc-daygrid-event.fc-event-end,
|
||||
.fc-direction-rtl .fc-daygrid-event.fc-event-start {
|
||||
padding-left: 5px;
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue