hrms-mgt/src/modules/04_registry/components/Train.vue
setthawutttty aa0e1fb822 no message
2024-02-14 12:08:40 +07:00

1523 lines
51 KiB
Vue

<!-- card การฝกอบรม/งาน -->
<template>
<q-card flat bordered class="col-12 q-px-lg q-py-md">
<q-form ref="myForm">
<ProfileTable
:rows="rows"
:columns="columns"
:filter="filter"
:visible-columns="visibleColumns"
v-model:inputfilter="filter"
v-model:inputvisible="visibleColumns"
:add="clickAdd"
name="การฝึกอบรม/ดูงาน"
icon="mdi-briefcase"
:statusEdit="statusEdit"
>
<template #columns="props">
<q-tr :props="props">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
@click="selectData(props)"
class="cursor-pointer"
>
<div v-if="col.name == 'startDate'" class="table_ellipsis">
{{
props.row.isDate == "true"
? date2Thai(props.row.startDate2)
: col.value + 543
}}
</div>
<div v-else-if="col.name == 'endDate'" class="table_ellipsis">
{{
props.row.isDate == "true"
? date2Thai(props.row.endDate2)
: col.value + 543
}}
</div>
<div v-else-if="col.name == 'dateOrder'" class="table_ellipsis">
{{ date2Thai(col.value) }}
</div>
<div v-else-if="col.name == 'yearly'" class="table_ellipsis">
{{ col.value ? col.value + 543 : "" }}
</div>
<div v-else class="table_ellipsis">
{{ col.value }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="info"
flat
dense
round
size="14px"
icon="mdi-history"
@click="clickHistory(props.row)"
>
<q-tooltip>ประวัติแก้ไขการฝึกอบรม/ดูงาน</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</ProfileTable>
</q-form>
</q-card>
<!-- popup Edit window-->
<q-dialog v-model="modal" persistent>
<q-card style="width: 600px">
<q-form ref="myForm">
<DialogHeader tittle="การฝึกอบรม/ดูงาน" :close="clickClose" />
<q-separator />
<q-card-section class="q-p-sm">
<div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
:class="getClass(edit)"
hide-bottom-space
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="name"
:rules="[
(val) =>
!!val || `${'กรุณากรอกชื่อโครงการ/หลักสูตรการฝึกอบรม'}`,
]"
:label="`${'ชื่อโครงการ/หลักสูตรการฝึกอบรม'}`"
@update:modelValue="clickEditRow"
/>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="topic"
:label="`${'หัวข้อการฝึกอบรม/ดูงาน'}`"
@update:modelValue="clickEditRow"
/>
</div>
<div class="col-12">
<q-card flat bordered class="q-px-sm q-pb-sm borderCard">
<div class="row col-12 q-gutter-md q-py-sm text-grey-7">
<q-radio
v-model="isDate"
checked-icon="task_alt"
unchecked-icon="panorama_fish_eye"
val="false"
label="ปี"
dense
:disable="!edit"
/>
<q-radio
v-model="isDate"
checked-icon="task_alt"
unchecked-icon="panorama_fish_eye"
val="true"
label="วัน/เดือน/ปี"
dense
:disable="!edit"
/>
</div>
<div class="col-12 row q-col-gutter-sm">
<div class="col-xs-6 col-sm-6 col-md-6">
<div v-if="isDate === 'false'">
<q-input
v-if="edit"
outlined
v-model="inputStartDate"
:label="`${'ปี เริ่มต้นการฝึกอบรม/ดูงาน'}`"
mask="####"
dense
hide-bottom-space
:error="dayChecked"
error-message="กรุณากรอก ปีเริ่มต้นการฝึกอบรม/ดูงาน"
/>
<datepicker
v-else
menu-class-name="modalfix"
:readonly="!edit"
v-model="startDate"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
@update:modelValue="clickEditRow"
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)"
:outlined="edit"
dense
lazy-rules
:borderless="!edit"
:model-value="Number(startDate) + 543"
:rules="[
(val) =>
!!val ||
`${'กรุณากรอกปี เริ่มต้นการฝึกอบรม/ดูงาน'}`,
]"
hide-bottom-space
:label="`${'ปี เริ่มต้นการฝึกอบรม/ดูงาน'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<div v-else>
<q-input
v-if="edit"
outlined
v-model="inputStartDate2"
label="วัน/เดือน/ปี เริ่มต้นการฝึกอบรม/ดูงาน"
mask="##/##/####"
dense
hide-bottom-space
:error="dayChecked2"
error-message="กรุณากรอก วัน/เดือน/ปี เริ่มต้นการฝึกอบรม/ดูงาน"
/>
<datepicker
v-else
menu-class-name="modalfix"
:readonly="!edit"
v-model="startDate2"
:locale="'th'"
autoApply
:enableTimePicker="false"
@update:modelValue="clickEditRow"
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)"
:outlined="edit"
dense
lazy-rules
:borderless="!edit"
:model-value="date2Thai(startDate2 as Date)"
:rules="[
(val) =>
!!val ||
`${'กรุณากรอก วัน/เดือน/ปี เริ่มต้นการฝึกอบรม/ดูงาน'}`,
]"
hide-bottom-space
:label="`${'วัน/เดือน/ปี เริ่มต้นการฝึกอบรม/ดูงาน'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div v-if="isDate === 'false'">
<q-input
v-if="edit"
outlined
v-model="inputEndDate"
:label="`${'ปี สิ้นสุดการฝึกอบรม/ดูงาน'}`"
mask="####"
dense
hide-bottom-space
:error="dayEndChecked"
error-message="กรุณากรอก ปีสิ้นสุดการฝึกอบรม/ดูงาน"
/>
<datepicker
v-else
menu-class-name="modalfix"
v-model="endDate"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
:min-date="minDate"
:readonly="!edit"
@update:modelValue="clickEditRow"
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)"
:outlined="edit"
dense
lazy-rules
:borderless="!edit"
:model-value="Number(endDate) + 543"
:rules="[
(val) =>
!!val ||
`${'กรุณากรอก ปี สิ้นสุดการฝึกอบรม/ดูงาน'}`,
]"
hide-bottom-space
:label="`${'ปี สิ้นสุดการฝึกอบรม/ดูงาน'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<div v-else>
<q-input
v-if="edit"
outlined
v-model="inputEndDate2"
label="วัน/เดือน/ปี สิ้นสุดการฝึกอบรม/ดูงาน"
mask="##/##/####"
dense
hide-bottom-space
:error="dayEndChecked2"
error-message="กรุณากรอก วัน/เดือน/ปี สิ้นสุดการฝึกอบรม/ดูงาน"
/>
<datepicker
v-else
menu-class-name="modalfix"
:readonly="!edit"
v-model="endDate2"
:locale="'th'"
autoApply
:enableTimePicker="false"
@update:modelValue="clickEditRow"
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)"
:outlined="edit"
dense
lazy-rules
:borderless="!edit"
:model-value="date2Thai(endDate2 as Date)"
:rules="[
(val) =>
!!val ||
`${'กรุณากรอก วัน/เดือน/ปี สิ้นสุดการฝึกอบรม/ดูงาน'}`,
]"
hide-bottom-space
:label="`${'วัน/เดือน/ปี สิ้นสุดการฝึกอบรม/ดูงาน'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
</div>
</div>
</q-card>
</div>
<div class="col-xs-6 col-sm-6 col-md-6"></div>
<div class="col-xs-6 col-sm-6 col-md-6"></div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
v-if="edit"
outlined
v-model="yearlyInput"
label="ปีงบประมาณ"
mask="####"
dense
/>
<datepicker
v-else
menu-class-name="modalfix"
v-model="yearly"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
:readonly="!edit"
@update:modelValue="clickEditRow"
>
<template #year="{ year }">{{ year }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value)
}}</template>
<template #trigger>
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:borderless="!edit"
:model-value="yearly == 0 ? null : Number(yearly + 543)"
:label="`${'ปีงบประมาณ'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
<template v-if="yearly && edit" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="yearly = 0"
class="cursor-pointer"
/>
</template>
</q-input>
</template>
</datepicker>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
:class="getClass(edit)"
hide-bottom-space
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="place"
:rules="[
(val) => !!val || `${'กรุณากรอกสถานที่ฝึกอบรม/ดูงาน'}`,
]"
:label="`${'สถานที่ฝึกอบรม/ดูงาน'}`"
@update:modelValue="clickEditRow"
/>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
:class="getClass(edit)"
hide-bottom-space
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="duration"
:label="`${'รวมระยะเวลาในการฝึกอบรม/ดูงาน'}`"
@update:modelValue="clickEditRow"
/>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
:class="getClass(edit)"
hide-bottom-space
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="department"
:label="`${'หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน'}`"
@update:modelValue="clickEditRow"
/>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
:class="getClass(edit)"
hide-bottom-space
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="numberOrder"
:label="`${'เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ'}`"
@update:modelValue="clickEditRow"
/>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<q-input
v-if="edit"
outlined
v-model="dateOrderInput"
label="คำสั่งลง วัน/เดือน/ปี /หนังสืออนุมัติลงวันที่"
mask="##/##/####"
dense
/>
<datepicker
v-else
menu-class-name="modalfix"
v-model="dateOrder"
:locale="'th'"
autoApply
:enableTimePicker="false"
:min-date="minDate"
:readonly="!edit"
@update:modelValue="clickEditRow"
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
lazy-rules
:borderless="!edit"
:model-value="date2Thai(dateOrder as Date)"
:label="`${'คำสั่งลง วัน/เดือน/ปี /หนังสืออนุมัติลงวันที่'}`"
>
<!-- :rules="[
(val) =>
!!val ||
`${'กรุณาเลือกคำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'}`,
]" -->
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
<template v-if="dateOrder && edit" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="dateOrder = null"
class="cursor-pointer"
/>
</template>
</q-input>
</template>
</datepicker>
</div>
</div>
</q-card-section>
<q-separator />
<DialogFooter
:cancel="clickCancel"
:edit="clickEdit"
:save="clickSave"
:validate="validateData"
:clickNext="clickNext"
:clickPrevious="clickPrevious"
:clickDelete="clickDelete"
v-model:editvisible="edit"
v-model:next="next"
v-model:previous="previous"
v-model:modalEdit="modalEdit"
/>
</q-form>
</q-card>
</q-dialog>
<HistoryTable
:rows="rowsHistory"
:columns="columnsHistory"
:filter="filterHistory"
:visible-columns="visibleColumnsHistory"
v-model:modal="modalHistory"
v-model:inputfilter="filterHistory"
v-model:inputvisible="visibleColumnsHistory"
v-model:tittle="tittleHistory"
>
<template #columns="props">
<q-tr :props="props">
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div
v-if="
col.name == 'startDate' ||
col.name == 'endDate' ||
col.name == 'createdAt' ||
col.name == 'dateOrder'
"
class="table_ellipsis"
>
{{ date2Thai(col.value) }}
</div>
<div v-else-if="col.name == 'yearly'" class="table_ellipsis">
{{ col.value + 543 }}
</div>
<div v-else class="table_ellipsis">
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</HistoryTable>
</template>
<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { useProfileDataStore } from "@/modules/04_registry/store";
import ProfileTable from "@/modules/04_registry/components/Table.vue";
import DialogHeader from "@/modules/04_registry/components/DialogHeader.vue";
import DialogFooter from "@/modules/04_registry/components/DialogFooter.vue";
import { useQuasar } from "quasar";
import type {
RequestItemsObject,
DataProps,
} from "@/modules/04_registry/interface/request/Train";
import type { ResponseObject } from "@/modules/04_registry/interface/response/Train";
import HistoryTable from "@/components/TableHistory.vue";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
const props = defineProps({
statusEdit: {
type: Boolean,
required: true,
},
});
const inputStartDate = ref<string>("");
const inputEndDate = ref<string>("");
const inputStartDate2 = ref<string>("");
const inputEndDate2 = ref<string>("");
const yearlyInput = ref<string>("");
const dateOrderInput = ref<string>("");
const dayChecked = ref<boolean>(false);
const dayEndChecked = ref<boolean>(false);
const dayChecked2 = ref<boolean>(false);
const dayEndChecked2 = ref<boolean>(false);
const $q = useQuasar();
const store = useProfileDataStore();
const { profileData, changeProfileColumns } = store;
const isDate = ref<string | null>("true");
const mixin = useCounterMixin();
const {
date2Thai,
success,
dateToISO,
messageError,
showLoader,
hideLoader,
convertDate,
convertDateDisplay,
} = mixin;
const route = useRoute();
const id = ref<string>("");
const name = ref<string>();
const topic = ref<string>();
const yearly = ref<number>(new Date().getFullYear());
const place = ref<string>();
const duration = ref<string>();
const department = ref<string>();
const numberOrder = ref<string>();
const dateOrder = ref<Date | null | string>(new Date());
const startDate = ref<Date | string | number>(new Date().getFullYear());
const startDate2 = ref<Date | string | null>(new Date());
const endDate = ref<Date | string | number>(new Date().getFullYear());
const endDate2 = ref<Date | string | null>(new Date());
const minDate = ref<Date>();
const myForm = ref<any>(); //form data input
const edit = ref<boolean>(false); //เช็คการกดปุ่มแก้ไขใน dialog
const modal = ref<boolean>(false); //modal add detail
const modalEdit = ref<boolean>(false); //modal ที่แสดงใช้สำหรับแก้ไขหรือไม่
const rawItem = ref<RequestItemsObject>(); //ข้อมูลเดิมที่เลือกใน row นั้น
const rowIndex = ref<number>(0); //indexข้อมูลเดิมที่เลือกใน row นั้น
const previous = ref<boolean>(); //แสดงปุ่มดูข้อมูลก่อนหน้า
const next = ref<boolean>(); //แสดงปุ่มดูข้อมูลต่อไป
const editRow = ref<boolean>(false); //เช็คมีการแก้ไขข้อมูล
const rowsHistory = ref<RequestItemsObject[]>([]); //select data history
const tittleHistory = ref<string>("ประวัติแก้ไขการฝึกอบรม/ดูงาน"); //
const filterHistory = ref<string>(""); //search data table history
const modalHistory = ref<boolean>(false); //modal ประวัติการแก้ไขข้อมูล
const checkValidate = ref<boolean>(false); //validate data ผ่านหรือไม่
const profileId = ref<string>(
route.params.id ? route.params.id.toString() : ""
);
const rows = ref<RequestItemsObject[]>([]);
const filter = ref<string>(""); //search data table
const visibleColumns = ref<String[]>([]);
profileData.train.columns.length == 0
? (visibleColumns.value = [
"name",
"topic",
"yearly",
"place",
"duration",
"department",
"numberOrder",
"dateOrder",
"startDate",
"endDate",
])
: (visibleColumns.value = profileData.train.columns);
const columns = ref<QTableProps["columns"]>([
{
name: "name",
align: "left",
label: "ชื่อโครงการ/หลักสูตรการฝึกอบรม",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "topic",
align: "left",
label: "หัวข้อการฝึกอบรม/ดูงาน",
sortable: true,
field: "topic",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "startDate",
align: "left",
label: "วันเริ่มต้นการฝึกอบรม/ดูงาน",
sortable: true,
field: "startDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "endDate",
align: "left",
label: "วันสิ้นสุดการฝึกอบรม/ดูงาน",
sortable: true,
field: "endDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "yearly",
align: "left",
label: "ปีที่อบรม (พ.ศ.)",
sortable: true,
field: "yearly",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "place",
align: "left",
label: "สถานที่ฝึกอบรม/ดูงาน",
sortable: true,
field: "place",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "duration",
align: "left",
label: "รวมระยะเวลาในการฝึกอบรม/ดูงาน",
sortable: true,
field: "duration",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "department",
align: "left",
label: "หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน",
sortable: true,
field: "department",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "numberOrder",
align: "left",
label: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ",
sortable: true,
field: "numberOrder",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "dateOrder",
align: "left",
label: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่",
sortable: true,
field: "dateOrder",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
const columnsHistory = ref<QTableProps["columns"]>([
{
name: "name",
align: "left",
label: "ชื่อโครงการ/หลักสูตรการฝึกอบรม",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "topic",
align: "left",
label: "หัวข้อการฝึกอบรม/ดูงาน",
sortable: true,
field: "topic",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "startDate",
align: "left",
label: "วันเริ่มต้นการฝึกอบรม/ดูงาน",
sortable: true,
field: "startDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "endDate",
align: "left",
label: "วันสิ้นสุดการฝึกอบรม/ดูงาน",
sortable: true,
field: "endDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "yearly",
align: "left",
label: "ปีที่อบรม (พ.ศ.)",
sortable: true,
field: "yearly",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "place",
align: "left",
label: "สถานที่ฝึกอบรม/ดูงาน",
sortable: true,
field: "place",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "duration",
align: "left",
label: "รวมระยะเวลาในการฝึกอบรม/ดูงาน",
sortable: true,
field: "duration",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "department",
align: "left",
label: "หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน",
sortable: true,
field: "department",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "numberOrder",
align: "left",
label: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ",
sortable: true,
field: "numberOrder",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "dateOrder",
align: "left",
label: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่",
sortable: true,
field: "dateOrder",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "createdFullName",
align: "left",
label: "ผู้ดำเนินการ",
sortable: true,
field: "createdFullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "createdAt",
align: "left",
label: "วันที่แก้ไข",
sortable: true,
field: "createdAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
const visibleColumnsHistory = ref<String[]>([
"name",
"topic",
"yearly",
"place",
"duration",
"department",
"numberOrder",
"dateOrder",
"startDate",
"endDate",
"createdFullName",
"createdAt",
]);
watch(startDate, (count, prevCount) => {
minDate.value = new Date(startDate.value);
});
watch(visibleColumns, async (count: String[], prevCount: String[]) => {
await changeProfileColumns("train", count);
});
onMounted(async () => {
await fetchData();
});
const fetchData = async () => {
if (profileId.value) {
showLoader();
await http
.get(config.API.profileTrainId(profileId.value))
.then((res) => {
let data = res.data.result;
rows.value = [];
data.map((e: ResponseObject) => {
rows.value.push({
id: e.id,
name: e.name,
topic: e.topic,
yearly: e.yearly,
place: e.place,
duration: e.duration,
department: e.department,
numberOrder: e.numberOrder,
dateOrder: e.dateOrder,
isDate: e.isDate == null ? null : e.isDate.toString(),
startDate: new Date(e.startDate).getFullYear(),
endDate: new Date(e.endDate).getFullYear(),
startDate2: new Date(e.startDate),
endDate2: new Date(e.endDate),
createdFullName: e.createdFullName,
createdAt: new Date(e.createdAt),
});
});
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
// hideLoader();
store.isLoad++;
});
}
};
/**
* กดดูข้อมูลก่อนหน้า
*/
const clickPrevious = async () => {
edit.value = false;
rowIndex.value -= 1;
await getData();
await checkRowPage();
};
/**
* กดดูข้อมูลต่อไป
*/
const clickNext = async () => {
edit.value = false;
rowIndex.value += 1;
await getData();
await checkRowPage();
};
/**
* กดดูข้อมูลต่อไป
*/
const getData = () => {
const row = rows.value[rowIndex.value];
name.value = row.name;
topic.value = row.topic;
yearly.value = row.yearly;
place.value = row.place;
duration.value = row.duration;
department.value = row.department;
numberOrder.value = row.numberOrder;
dateOrder.value = row.dateOrder;
isDate.value = row.isDate;
startDate.value = row.startDate;
endDate.value = row.endDate;
startDate2.value = row.startDate2;
endDate2.value = row.endDate2;
id.value = row.id;
inputStartDate.value = (Number(row.startDate) + 543).toLocaleString();
inputEndDate.value = (Number(row.endDate) + 543).toLocaleString();
yearlyInput.value = (Number(row.yearly) + 543).toLocaleString();
inputStartDate2.value = convertDateDisplay(row.startDate2);
inputEndDate2.value = convertDateDisplay(row.endDate2);
dateOrderInput.value = row.dateOrder ? convertDateDisplay(row.dateOrder) : "";
};
/**
* เช็คปุ่มดูข้อมูล ย้อน กับ ต่อไป ว่าต้องแสดงไหม
*/
const checkRowPage = () => {
editRow.value = false;
next.value = true;
previous.value = true;
if (rowIndex.value + 1 >= rows.value.length) {
next.value = false;
}
if (rowIndex.value - 1 < 0) {
previous.value = false;
}
};
/**
* กดปุ่มแก้ไขใน dialog
*/
const clickEdit = () => {
editRow.value = false;
next.value = false;
previous.value = false;
};
/**
* กดปุ่มเพิ่มด้านบน table
*/
const clickAdd = async () => {
editRow.value = false;
await addData();
};
/**
* กดบันทึกใน dialog
*/
const clickSave = async () => {
myForm.value.validate().then(async (result: boolean) => {
if (result) {
if (isDate.value == "false") {
dayChecked2.value = false;
dayEndChecked2.value = false;
if (inputStartDate.value == "") {
dayChecked.value = true;
} else if (inputEndDate.value === "") {
dayEndChecked.value = true;
} else {
if (modalEdit.value) {
await editData();
} else {
await saveData();
}
}
} else {
dayChecked.value = false;
dayEndChecked.value = false;
if (inputStartDate2.value === "") {
dayChecked2.value = true;
} else if (inputEndDate2.value === "") {
dayEndChecked2.value = true;
} else {
if (modalEdit.value) {
await editData();
} else {
await saveData();
}
}
}
}
});
};
/**
* บันทึกเพิ่มข้อมูล
*/
const saveData = async () => {
if (profileId.value) {
showLoader();
await http
.post(config.API.profileTrainId(profileId.value), {
id: id.value,
name: name.value,
topic: topic.value,
yearly: yearly.value,
place: place.value,
duration: duration.value,
department: department.value,
numberOrder: numberOrder.value,
dateOrder: dateOrder.value,
isDate: isDate.value == "true" ? true : false,
startDate:
isDate.value == "true"
? dateToISO(startDate2.value as Date)
: new Date(`${startDate.value}-01-01`),
endDate:
isDate.value == "true"
? dateToISO(endDate2.value as Date)
: new Date(`${endDate.value}-01-01`),
})
.then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ");
modal.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchData();
});
}
};
/**
* บันทึกแก้ไขข้อมูล
*/
const editData = async () => {
showLoader();
await http
.put(config.API.profileTrainId(id.value), {
id: id.value,
name: name.value,
topic: topic.value,
yearly: yearly.value,
place: place.value,
duration: duration.value,
department: department.value,
numberOrder: numberOrder.value,
dateOrder: dateOrder.value,
isDate: isDate.value == "true" ? true : false,
startDate:
isDate.value == "true"
? dateToISO(startDate2.value as Date)
: new Date(`${startDate.value}-01-01`),
endDate:
isDate.value == "true"
? dateToISO(endDate2.value as Date)
: new Date(`${endDate.value}-01-01`),
})
.then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ");
modal.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchData();
});
};
/**
* ลบลบข้อมูล
*/
const clickDelete = async () => {
$q.dialog({
title: `ลบข้อมูล`,
message: `ต้องการทำการลบข้อมูลนี้ใช่หรือไม่?`,
cancel: "ยกเลิก",
ok: "ยืนยัน",
persistent: true,
})
.onOk(async () => {
showLoader();
await http
.delete(config.API.profileTrainId(id.value))
.then((res) => {
success($q, "ลบข้อมูลสำเร็จ");
modal.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchData();
});
})
.onCancel(async () => {
await fetchData();
});
};
/**
* กดปิด dialog
*/
const clickClose = async () => {
if (editRow.value == true) {
$q.dialog({
title: `ข้อมูลมีการแก้ไข`,
message: `ยืนยันที่จะปิดโดยไม่บันทึกใช่หรือไม่?`,
cancel: "ยกเลิก",
ok: "ยืนยัน",
persistent: true,
}).onOk(async () => {
modal.value = false;
next.value = false;
previous.value = false;
});
} else {
modal.value = false;
next.value = false;
previous.value = false;
}
};
/**
* กดเลือกข้อมูลที่จะแก้ไข
* @param props ค่า props ใน row ที่เลือก
*/
const selectData = async (props: DataProps) => {
modalEdit.value = true;
modal.value = true;
edit.value = false;
rawItem.value = props.row;
rowIndex.value = props.rowIndex;
name.value = props.row.name;
topic.value = props.row.topic;
yearly.value = props.row.yearly;
console.log(typeof yearly.value);
place.value = props.row.place;
duration.value = props.row.duration;
department.value = props.row.department;
numberOrder.value = props.row.numberOrder;
dateOrder.value = props.row.dateOrder;
isDate.value = props.row.isDate;
startDate.value = props.row.startDate;
endDate.value = props.row.endDate;
startDate2.value = props.row.startDate2;
endDate2.value = props.row.endDate2;
inputStartDate.value = (Number(props.row.startDate) + 543).toLocaleString();
inputEndDate.value = (Number(props.row.endDate) + 543).toLocaleString();
yearlyInput.value =
props.row.yearly !== 0
? (Number(props.row.yearly) + 543).toLocaleString()
: "";
inputStartDate2.value = convertDateDisplay(props.row.startDate2);
inputEndDate2.value = convertDateDisplay(props.row.endDate2);
dateOrderInput.value = props.row.dateOrder
? convertDateDisplay(props.row.dateOrder)
: "";
id.value = props.row.id;
await checkRowPage();
};
/**
* กดปุ่มเพิ่มบน table
*/
const addData = () => {
modalEdit.value = false;
modal.value = true;
edit.value = true;
name.value = "";
topic.value = "";
yearly.value = 0;
place.value = "";
duration.value = "";
department.value = "";
numberOrder.value = "";
dateOrder.value = null;
isDate.value = "true";
startDate.value = new Date().getFullYear();
endDate.value = new Date().getFullYear();
startDate2.value = new Date();
endDate2.value = new Date();
inputStartDate2.value = "";
inputEndDate2.value = "";
inputStartDate.value = "";
inputEndDate.value = "";
yearlyInput.value = "";
dateOrderInput.value = "";
dayChecked.value = false;
dayEndChecked.value = false;
};
/**
* ฟังก์ชันปุ่มยกเลิกการแก้ไขข้อมูล
*/
const clickCancel = async () => {
if (editRow.value == true) {
$q.dialog({
title: `ข้อมูลมีการแก้ไข`,
message: `ยืนยันยกเลิกการแก้ไขใช่หรือไม่?`,
cancel: "ยกเลิก",
ok: "ยืนยัน",
persistent: true,
}).onOk(async () => {
edit.value = false;
await checkRowPage();
await getData();
});
} else {
edit.value = false;
await checkRowPage();
}
};
/**
* เช็คว่ามีการแก้ไขข้อมูล
*/
const clickEditRow = () => {
editRow.value = true;
};
/**
* ฟังชั้นดูข้อมูลประวัติแก้ไขข้อมูลที่เลือก
* @param row ข้อมูล row ที่ดูประวัติการแก้ไข
*/
const clickHistory = async (row: RequestItemsObject) => {
modalHistory.value = true;
filterHistory.value = "";
showLoader();
await http
.get(config.API.profileTrainHisId(row.id))
.then((res) => {
let data = res.data.result;
rowsHistory.value = [];
data.map((e: ResponseObject) => {
rowsHistory.value.push({
id: e.id,
name: e.name,
topic: e.topic,
yearly: e.yearly,
place: e.place,
duration: e.duration,
department: e.department,
numberOrder: e.numberOrder,
dateOrder: e.dateOrder,
isDate: e.isDate,
startDate: new Date(e.startDate).getFullYear(),
endDate: new Date(e.endDate).getFullYear(),
startDate2: new Date(e.startDate2),
endDate2: new Date(e.endDate2),
createdFullName: e.createdFullName,
createdAt: new Date(e.createdAt),
});
});
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
/**
* validate input ใน dialog
*/
const validateData = async () => {
checkValidate.value = true;
await myForm.value.validate().then((result: boolean) => {
if (result == false) {
checkValidate.value = false;
}
});
};
/**
* class จัดรูปแบบแสดงระหว่างข้อมูลที่แก้ไขหรือแสดงเฉยๆ
* @param val ข้อมูล input สำหรับแก้ไขหรือไม่
*/
const getClass = (val: boolean) => {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
};
watch(
() => inputStartDate2.value,
(value: string) => {
if (value.length === 10) {
const dateVal = convertDate(value);
if (dateVal.isValid) {
dayChecked2.value = false;
startDate2.value = dateVal.value;
} else {
dayChecked.value = true;
inputStartDate2.value = "";
}
}
}
);
watch(
() => inputEndDate2.value,
(value: string) => {
if (value.length === 10) {
const dateVal = convertDate(value);
if (dateVal.isValid) {
dayEndChecked2.value = false;
endDate2.value = dateVal.value;
} else {
dayEndChecked.value = true;
inputEndDate2.value = "";
}
}
}
);
watch(
() => dateOrderInput.value,
(value: string) => {
if (value.length === 10) {
const dateVal = convertDate(value);
if (dateVal.isValid) {
dateOrder.value = dateVal.value;
} else {
dateOrderInput.value = "";
}
}
}
);
watch(
() => inputStartDate.value,
(value: string) => {
if (value.length === 4) {
const dateVal = Number(value) - 543;
dayChecked.value = false;
startDate.value = dateVal;
}
}
);
watch(
() => inputEndDate.value,
(value: string) => {
if (value.length === 4) {
const dateVal = Number(value) - 543;
dayEndChecked.value = false;
endDate.value = dateVal;
}
}
);
watch(
() => yearlyInput.value,
(value: string) => {
if (value.length === 4) {
const dateVal = Number(value) - 543;
yearly.value = dateVal;
}
}
);
</script>
<style lang="scss">
.modalfix {
position: fixed !important;
}
</style>