ปรับปฎิทิน
This commit is contained in:
parent
bc6c78c0a6
commit
8500d25a5a
5 changed files with 374 additions and 343 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, watch } from "vue";
|
||||
import config from "@/app.config";
|
||||
import http from "@/plugins/http";
|
||||
import { ref, watch, type PropType } from "vue";
|
||||
// import config from "@/app.config";
|
||||
// import http from "@/plugins/http";
|
||||
import { useQuasar } from "quasar";
|
||||
import FullCalendar from "@fullcalendar/vue3";
|
||||
import dayGridPlugin from "@fullcalendar/daygrid";
|
||||
|
|
@ -12,16 +12,21 @@ import allLocales from "@fullcalendar/core/locales-all";
|
|||
import listPlugin from "@fullcalendar/list";
|
||||
|
||||
import type { DataDateMonthObject } from "@/modules/09_leave/interface/response/leave";
|
||||
import type { CaledarDisciplinary } from "@/modules/11_discipline/interface/response/Main";
|
||||
import type { ExtendHistoryObject } from "@/modules/11_discipline/interface/response/Main";
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง
|
||||
const { monthYear2Thai, showLoader, hideLoader, messageError } = mixin;
|
||||
const { monthYear2Thai, showLoader, hideLoader, messageError, dateToISO } =
|
||||
mixin;
|
||||
|
||||
const $q = useQuasar();
|
||||
|
||||
const props = defineProps({
|
||||
lists: {
|
||||
type: Array as PropType<ExtendHistoryObject[]>,
|
||||
default: [],
|
||||
},
|
||||
modal: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
|
|
@ -32,7 +37,6 @@ const props = defineProps({
|
|||
},
|
||||
});
|
||||
|
||||
/** Option ของปฏิทิน */
|
||||
const fullCalendar = ref<any>(); //ref calendar
|
||||
const calendarOptions = ref<CalendarOptions>({
|
||||
plugins: [
|
||||
|
|
@ -57,8 +61,8 @@ const calendarOptions = ref<CalendarOptions>({
|
|||
expandRows: true,
|
||||
nowIndicator: true,
|
||||
height: "100%",
|
||||
eventColor: "#50a5fc",
|
||||
eventTextColor: "#fff",
|
||||
eventColor: "#E3FDDA",
|
||||
eventTextColor: "#000000",
|
||||
eventBorderColor: "#50a5fc",
|
||||
displayEventTime: false,
|
||||
editable: true,
|
||||
|
|
@ -73,54 +77,86 @@ const dateMonth = ref<DataDateMonthObject>({
|
|||
|
||||
/** function เรียกข่อมูล calendar*/
|
||||
function getRandomColor() {
|
||||
const letters = "0123456789ABCDEF";
|
||||
let color = "#";
|
||||
for (let i = 0; i < 6; i++) {
|
||||
color += letters[Math.floor(Math.random() * 16)];
|
||||
}
|
||||
return color;
|
||||
return (
|
||||
"hsl(" +
|
||||
360 * Math.random() +
|
||||
"," +
|
||||
(25 + 70 * Math.random()) +
|
||||
"%," +
|
||||
(85 + 10 * Math.random()) +
|
||||
"%)"
|
||||
);
|
||||
}
|
||||
|
||||
async function fetchCalendar() {
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.disciplinaryCalendar(), {
|
||||
year: dateMonth.value.year,
|
||||
month: dateMonth.value.month,
|
||||
})
|
||||
.then((res) => {
|
||||
const data = res.data.result;
|
||||
const defaultColor = "#02A998";
|
||||
const gradientColors = generateGradientColors(data.length);
|
||||
const defaultColor = "#E3FDDA";
|
||||
const gradientColors = generateGradientColors(props.lists.length);
|
||||
|
||||
const events = data.map((e: CaledarDisciplinary, index: number) => ({
|
||||
id: e.id,
|
||||
title: e.title,
|
||||
start: e.disciplinaryDateStart,
|
||||
end: e.disciplinaryDateEnd,
|
||||
allDay: true,
|
||||
color:
|
||||
data.length > 1 && index > 0 ? gradientColors[index] : defaultColor,
|
||||
}));
|
||||
const events = await props.lists.map(
|
||||
(e: ExtendHistoryObject, index: number) => ({
|
||||
id: index.toString(),
|
||||
title: e.name,
|
||||
start: e.dateStart,
|
||||
end: e.dateEnd,
|
||||
allDay: false,
|
||||
color:
|
||||
props.lists.length > 1 && index > 0
|
||||
? gradientColors[index]
|
||||
: defaultColor,
|
||||
})
|
||||
);
|
||||
calendarOptions.value.events = events;
|
||||
|
||||
calendarOptions.value.events = events;
|
||||
console.log("events===>",events)
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
setTimeout(() => {
|
||||
if (fullCalendar !== undefined) {
|
||||
const calen = fullCalendar.value.getApi();
|
||||
const date = new Date(dateMonth.value.year, dateMonth.value.month);
|
||||
calen.gotoDate(date);
|
||||
}
|
||||
hideLoader();
|
||||
}, 1000);
|
||||
});
|
||||
setTimeout(() => {
|
||||
if (fullCalendar !== undefined) {
|
||||
const calen = fullCalendar.value.getApi();
|
||||
const date = new Date(dateMonth.value.year, dateMonth.value.month);
|
||||
calen.gotoDate(date);
|
||||
}
|
||||
hideLoader();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// async function fetchCalendar() {
|
||||
// showLoader();
|
||||
// await http
|
||||
// .post(config.API.investigateCalendar(), {
|
||||
// year: dateMonth.value.year,
|
||||
// month: dateMonth.value.month,
|
||||
// })
|
||||
// .then((res) => {
|
||||
// const data = res.data.result;
|
||||
// const defaultColor = "#02A998";
|
||||
// const gradientColors = generateGradientColors(data.length);
|
||||
|
||||
// const events = data.map((e: CaledarInvestigatefacts, index: number) => ({
|
||||
// id: e.id,
|
||||
// title: e.title,
|
||||
// start: e.investigationDateStart,
|
||||
// end: e.investigationDateEnd,
|
||||
// allDay: true,
|
||||
// color:
|
||||
// data.length > 1 && index > 0 ? gradientColors[index] : defaultColor,
|
||||
// }));
|
||||
|
||||
// calendarOptions.value.events = events;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// messageError($q, err);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// setTimeout(() => {
|
||||
// if (fullCalendar !== undefined) {
|
||||
// const calen = fullCalendar.value.getApi();
|
||||
// const date = new Date(dateMonth.value.year, dateMonth.value.month);
|
||||
// calen.gotoDate(date);
|
||||
// }
|
||||
// hideLoader();
|
||||
// }, 1000);
|
||||
// });
|
||||
// }
|
||||
|
||||
function generateGradientColors(length: number) {
|
||||
const colors = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
|
@ -129,25 +165,24 @@ function generateGradientColors(length: number) {
|
|||
return colors;
|
||||
}
|
||||
|
||||
/** function เปลี่ยนปฎิทิน*/
|
||||
function changCalendar() {
|
||||
fetchCalendar();
|
||||
}
|
||||
|
||||
const monthYearThai = (val: DataDateMonthObject) => {
|
||||
/**
|
||||
* function convert เดือนปี
|
||||
* @param val เดือนปี
|
||||
*/
|
||||
function monthYearThai(val: DataDateMonthObject) {
|
||||
if (val == null) return "";
|
||||
else return monthYear2Thai(val.month, val.year);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชั่นเปิด model
|
||||
* @param text
|
||||
* function openModalDetail
|
||||
* @param text เรื่อง
|
||||
*/
|
||||
const view = async (text: string) => {
|
||||
async function view(text: string) {
|
||||
title.value = text;
|
||||
modalCancel.value = true;
|
||||
modeCancel.value = false;
|
||||
};
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modal,
|
||||
|
|
@ -161,28 +196,17 @@ watch(
|
|||
*/
|
||||
const modalCancel = ref(false);
|
||||
const title = ref("");
|
||||
const location = ref("บ้าน");
|
||||
const subject = ref("ลาป่วย");
|
||||
const dateStart = ref("20 ส.ค. 2566");
|
||||
const dateEnd = ref("21 ส.ค. 2566");
|
||||
const numDate = ref("20");
|
||||
const place = ref("บ้าน");
|
||||
const phone = ref("000-00000000");
|
||||
const reason = ref("ยกเลิกการลา");
|
||||
const model = ref(null);
|
||||
const modeCancel = ref(true);
|
||||
|
||||
function gotoPrevMonth() {
|
||||
const calen = fullCalendar.value.getApi();
|
||||
calen.prev();
|
||||
console.log("b", calen.getDate());
|
||||
updateDateMonth(calen.getDate());
|
||||
}
|
||||
|
||||
function gotoNextMonth() {
|
||||
const calen = fullCalendar.value.getApi();
|
||||
calen.next();
|
||||
console.log("n", calen.getDate());
|
||||
updateDateMonth(calen.getDate());
|
||||
}
|
||||
|
||||
|
|
@ -192,13 +216,14 @@ function updateDateMonth(date: Date) {
|
|||
fetchCalendar();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-dialog v-model="props.modal">
|
||||
<q-card style="min-width: 60vw">
|
||||
<q-toolbar>
|
||||
<q-toolbar-title class="text-subtitle2 text-bold"
|
||||
>ปฎิทิน</q-toolbar-title
|
||||
>
|
||||
<q-toolbar-title class="text-subtitle2 text-bold">
|
||||
ปฎิทินแสดงวันที่สืบสวน
|
||||
</q-toolbar-title>
|
||||
<q-btn
|
||||
icon="close"
|
||||
unelevated
|
||||
|
|
@ -210,12 +235,13 @@ function updateDateMonth(date: Date) {
|
|||
</q-toolbar>
|
||||
|
||||
<q-separator />
|
||||
|
||||
<q-card-section class="q-pa-md bg-grey-1 scroll">
|
||||
<div class="q-ma-sm">
|
||||
<div class="row q-gutter-sm">
|
||||
<div class="col-12">
|
||||
<div class="row q-gutter-sm q-pb-sm main-content">
|
||||
<div class="demo-app-main">
|
||||
<div class="demo-app-main q-mb-xl">
|
||||
<!-- <div class="row col-12 q-mb-sm">
|
||||
<div class="col-xs-12 col-sm-3 col-md-2">
|
||||
<datepicker
|
||||
|
|
@ -306,17 +332,6 @@ function updateDateMonth(date: Date) {
|
|||
</div>
|
||||
</template>
|
||||
</FullCalendar>
|
||||
<div class="row q-col-gutter-lg justify-end q-pb-lg">
|
||||
<div class="items-center row">
|
||||
<q-icon
|
||||
size="10px"
|
||||
color="light-blue-14"
|
||||
name="mdi-circle"
|
||||
class="q-mr-sm"
|
||||
/>
|
||||
<span class="text-caption text-grey-8">สอบสวน</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -325,88 +340,10 @@ function updateDateMonth(date: Date) {
|
|||
</q-card-section>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<!-- modal ขอยกเลิก/ดูรายละเอียด -->
|
||||
<q-dialog v-model="modalCancel" persistent>
|
||||
<q-card :style="modeCancel == true ? 'min-width: 50%;' : 'min-width:30%'">
|
||||
<q-card-section class="row items-center q-pa-sm">
|
||||
<div v-if="modeCancel == false" class="text-bold q-pl-sm">
|
||||
รายละเอียดของ{{ title }}
|
||||
</div>
|
||||
<div v-else class="text-bold q-pl-sm">ขอยกเลิก{{ title }}</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 flat :class="modeCancel == true ? 'col-xs-6 col-sm-6' : 'col-12'">
|
||||
<div class="col-12 q-col-gutter-sm row items-center">
|
||||
<div class="col-6 text-grey-7">เขียนที่</div>
|
||||
<div class="col-6 text-black">{{ location }}</div>
|
||||
<div class="col-6 text-grey-7">เรื่องและเหตุผลการลา</div>
|
||||
<div class="col-6 text-black">{{ subject }}</div>
|
||||
<div class="col-6 text-grey-7">วัน เดือน ปีเริ่มต้น</div>
|
||||
<div class="col-6 text-black">{{ dateStart }}</div>
|
||||
<div class="col-6 text-grey-7">วัน เดือน ปีสิ้นสุด</div>
|
||||
<div class="col-6 text-black">{{ dateEnd }}</div>
|
||||
<div class="col-6 text-grey-7">จำนวนวันที่ลา</div>
|
||||
<div class="col-6 text-black">{{ numDate }}</div>
|
||||
<div class="col-6 text-grey-7">สถานที่ติดต่อขณะลา</div>
|
||||
<div class="col-6 text-black">{{ place }}</div>
|
||||
<div class="col-6 text-grey-7">หมายเลขโทรศัพท์</div>
|
||||
<div class="col-6 text-black">{{ phone }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div flat class="col-xs-6 col-sm-6" v-if="modeCancel == true">
|
||||
<q-input
|
||||
v-model="reason"
|
||||
type="textarea"
|
||||
label="กรอกเหตุผล"
|
||||
outlined
|
||||
dense
|
||||
/>
|
||||
<q-file
|
||||
outlined
|
||||
v-model="model"
|
||||
label="เลือกไฟล์เอกสารหลักฐาน"
|
||||
class="q-mt-md"
|
||||
use-chips
|
||||
dense
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="attach_file" />
|
||||
</template>
|
||||
</q-file>
|
||||
</div>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
<q-card-section
|
||||
class="row items-center q-pa-sm"
|
||||
v-if="modeCancel == true"
|
||||
>
|
||||
<q-space />
|
||||
<q-btn
|
||||
label="ยืนยัน"
|
||||
unelevated
|
||||
color="secondary"
|
||||
dense
|
||||
class="q-px-md"
|
||||
v-close-popup
|
||||
/>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
<style scope lang="scss">
|
||||
.main-content {
|
||||
height: 65vh;
|
||||
height: 80vh;
|
||||
}
|
||||
|
||||
.color-main {
|
||||
|
|
@ -419,6 +356,7 @@ function updateDateMonth(date: Date) {
|
|||
|
||||
.demo-app-main {
|
||||
flex-grow: 1;
|
||||
|
||||
/* padding: 3em; */
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue