hrms-mgt/src/modules/04_registry/components/Education.vue
setthawutttty 30b526a875 no message
2024-03-04 10:57:19 +07:00

1849 lines
60 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="school"
: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"
? props.row.startDate2
? date2Thai(props.row.startDate2)
: "-"
: col.value + 543
}}
</div>
<div v-else-if="col.name == 'endDate'" class="table_ellipsis">
{{
props.row.isDate == "true"
? props.row.endDate2
? date2Thai(props.row.endDate2)
: "-"
: col.value + 543
}}
</div>
<div v-else-if="col.name == 'finishDate'" class="table_ellipsis">
{{ col.value ? date2Thai(col.value) : "-" }}
</div>
<div v-else-if="col.name == 'isEducation'" class="table_ellipsis">
{{ col.value ? "ใช่" : "ไม่ใช่" }}
</div>
<div v-else class="table_ellipsis">
{{ col.value ? 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">
<selector
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="levelId"
:rules="[(val:string) => !!val || `${'กรุณาเลือกระดับการศึกษา'}`]"
hide-bottom-space
:label="`${'ระดับการศึกษา'}`"
@update:modelValue="clickEditRow"
emit-value
map-options
option-label="name"
:options="Ops.levelOptions"
option-value="id"
use-input
input-debounce="0"
@filter="(inputValue:any,
doneFn:Function) => filterSelector(inputValue, doneFn,'levelOptions'
) "
/>
</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="institute"
:rules="[(val) => !!val || `${'กรุณากรอกสถานศึกษา'}`]"
hide-bottom-space
: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">
<q-input
v-if="edit"
outlined
v-model="finishDateInput"
label="วัน/เดือน/ปี / ที่สำเร็จการศึกษา"
mask="##/##/####"
dense
/>
<datepicker
v-else
menu-class-name="modalfix"
:readonly="!edit"
v-model="finishDate"
: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="finishDate ? date2Thai(finishDate as Date) : null"
hide-bottom-space
: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="finishDate && edit" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="finishDate = null"
class="cursor-pointer"
/>
</template>
</q-input>
</template>
</datepicker>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<selector
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="isEducation"
hide-bottom-space
:label="`${'เป็นวุฒิการศึกษาในตำแหน่ง'}`"
@update:modelValue="clickEditRow"
emit-value
map-options
option-label="name"
:options="Ops.positionPathOptions"
option-value="id"
use-input
input-debounce="0"
@filter="(inputValue:any,
doneFn:Function) => filterSelector(inputValue, doneFn,'positionPathOptions'
) "
>
<template v-if="isEducation !== null && edit" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="isEducation = null"
class="cursor-pointer"
/>
</template>
</selector>
</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="degree"
:rules="[(val) => !!val || `${'กรุณากรอกวุฒิการศึกษา'}`]"
hide-bottom-space
: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="field"
hide-bottom-space
:label="`${'สาขาวิชา/ทาง'}`"
@update:modelValue="clickEditRow"
/>
<!-- :rules="[(val) => !!val || `${'กรุณากรอกสาขาวิชา/ทาง'}`]" -->
</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="fundName"
hide-bottom-space
: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="gpa"
hide-bottom-space
:label="`${'เกรดเฉลี่ย'}`"
@update:modelValue="clickEditRow"
/>
<!-- :rules="[(val) => !!val || `${'กรุณากรอกเกรดเฉลี่ย'}`]" -->
</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="country"
hide-bottom-space
:label="`${'ประเทศ'}`"
@update:modelValue="clickEditRow"
/>
<!-- :rules="[(val) => !!val || `${'กรุณากรอกประเทศ'}`]" -->
</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="other"
hide-bottom-space
: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="duration"
hide-bottom-space
: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="durationYear"
hide-bottom-space
:label="`${'ระยะเวลาหลักสูตร'}`"
@update:modelValue="clickEditRow"
type="number"
/>
<!-- :rules="[(val) => !!val || `${'กรุณากรอกระยะเวลาหลักสูตร'}`]" -->
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
:readonly="!edit"
:borderless="!edit"
v-model="note"
label="หมายเหตุ"
type="textarea"
/>
</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'" 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 == 'finishDate' || col.name == 'createdAt'"
class="table_ellipsis"
>
{{ col.value ? date2Thai(col.value) : "-" }}
</div>
<div v-else-if="col.name == 'isEducation'" class="table_ellipsis">
{{ col.value ? "ใช่" : "ไม่ใช่" }}
</div>
<div v-else class="table_ellipsis">
{{ col.value ? 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 { useProfileDataStore } from "@/modules/04_registry/store";
import { useCounterMixin } from "@/stores/mixin";
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/Education";
import type { ResponseObject } from "@/modules/04_registry/interface/response/Education";
import type { DataOption } from "@/modules/04_registry/interface/index/Main";
import HistoryTable from "@/components/TableHistory.vue";
import http from "@/plugins/http";
import config from "@/app.config";
import type { EduOps } from "@/modules/04_registry/interface/index/Main";
import type { QTableProps } from "quasar";
const inputStartDate = ref<string>("");
const inputEndDate = ref<string>("");
const inputStartDate2 = ref<string>("");
const inputEndDate2 = ref<string>("");
const finishDateInput = ref<string>("");
const dayChecked = ref<boolean>(false);
const dayEndChecked = ref<boolean>(false);
const dayChecked2 = ref<boolean>(false);
const dayEndChecked2 = ref<boolean>(false);
const props = defineProps({
statusEdit: {
type: Boolean,
required: true,
},
});
const $q = useQuasar();
const store = useProfileDataStore();
const { profileData, changeProfileColumns } = store;
const mixin = useCounterMixin();
const {
success,
dateToISO,
date2Thai,
messageError,
showLoader,
hideLoader,
convertDate,
convertDateDisplay,
} = mixin;
const route = useRoute();
const id = ref<string>("");
const levelId = ref<string>();
const Ops = ref<EduOps>({
levelOptions: [],
positionPathOptions: [],
});
const OpsFilter = ref<EduOps>({
levelOptions: [],
positionPathOptions: [],
});
const isEducation = ref<boolean | null>();
const institute = ref<string>();
const degree = ref<string>();
const field = ref<string>();
const gpa = ref<string>();
const country = ref<string>();
const duration = ref<string>();
const durationYear = ref<number>(0);
const other = ref<string>();
const fundName = ref<string>();
const isDate = ref<string | null>("true");
const finishDate = ref<Date | null | string>(null);
const startDate = ref<Date | string | number | null>(new Date().getFullYear());
const startDate2 = ref<Date | string | null>(null);
const endDate = ref<number | string | Date | null>(new Date().getFullYear());
const endDate2 = ref<Date | string | null>(null);
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 note = ref<string>()
const rows = ref<RequestItemsObject[]>([]);
const filter = ref<string>(""); //search data table
const visibleColumns = ref<String[]>([]);
profileData.education.columns.length == 0
? (visibleColumns.value = [
"level",
"institute",
"degree",
"field",
"gpa",
"country",
"duration",
"durationYear",
"other",
"fundName",
"isEducation",
"finishDate",
"startDate",
"endDate",
"note",
])
: (visibleColumns.value = profileData.education.columns);
const columns = ref<QTableProps["columns"]>([
{
name: "level",
align: "left",
label: "ระดับศึกษา",
sortable: true,
field: "level",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "institute",
align: "left",
label: "สถานศึกษา",
sortable: true,
field: "institute",
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: "finishDate",
align: "left",
label: "วันที่สำเร็จการศึกษา",
sortable: true,
field: "finishDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "isEducation",
align: "left",
label: "เป็นวุฒิการศึกษาในตำแหน่ง",
sortable: true,
field: "isEducation",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "degree",
align: "left",
label: "วุฒิการศึกษา",
sortable: true,
field: "degree",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "field",
align: "left",
label: "สาขาวิชา/ทาง",
sortable: true,
field: "field",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "fundName",
align: "left",
label: "ทุน",
sortable: true,
field: "fundName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "gpa",
align: "left",
label: "เกรดเฉลี่ย",
sortable: true,
field: "gpa",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "country",
align: "left",
label: "ประเทศ",
sortable: true,
field: "country",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "other",
align: "left",
label: "ข้อมูลการติดต่อ",
sortable: true,
field: "other",
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: "durationYear",
align: "left",
label: "ระยะเวลาหลักสูตร",
sortable: true,
field: "durationYear",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "note",
align: "left",
label: "หมายเหตุ",
sortable: true,
field: "note",
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: "level",
align: "left",
label: "ระดับศึกษา",
sortable: true,
field: "level",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "institute",
align: "left",
label: "สถานศึกษา",
sortable: true,
field: "institute",
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: "finishDate",
align: "left",
label: "วันที่สำเร็จการศึกษา",
sortable: true,
field: "finishDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "isEducation",
align: "left",
label: "เป็นวุฒิการศึกษาในตำแหน่ง",
sortable: true,
field: "isEducation",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "degree",
align: "left",
label: "วุฒิการศึกษา",
sortable: true,
field: "degree",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "field",
align: "left",
label: "สาขาวิชา/ทาง",
sortable: true,
field: "field",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "fundName",
align: "left",
label: "ทุน",
sortable: true,
field: "fundName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "gpa",
align: "left",
label: "เกรดเฉลี่ย",
sortable: true,
field: "gpa",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "country",
align: "left",
label: "ประเทศ",
sortable: true,
field: "country",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "other",
align: "left",
label: "ข้อมูลการติดต่อ",
sortable: true,
field: "other",
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: "durationYear",
align: "left",
label: "ระยะเวลาหลักสูตร",
sortable: true,
field: "durationYear",
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[]>([
"level",
"institute",
"degree",
"field",
"gpa",
"country",
"duration",
"durationYear",
"other",
"isEducation",
"fundName",
"finishDate",
"startDate",
"endDate",
"createdFullName",
"createdAt",
]);
watch(startDate, (count, prevCount) => {
minDate.value = new Date(`${startDate.value}-01-01`);
});
watch(visibleColumns, async (count: String[], prevCount: String[]) => {
await changeProfileColumns("education", count);
});
onMounted(async () => {
await fetchLevel();
await fetchPositionPath();
await fetchData();
});
const fetchLevel = async () => {
showLoader();
await http
.get(config.API.educationLevel)
.then((res) => {
const data = res.data.result;
let option: DataOption[] = [];
data.map((r: DataOption) => {
option.push({ id: r.id.toString(), name: r.name.toString() });
});
Ops.value.levelOptions = option;
OpsFilter.value.levelOptions = option;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
store.isLoad++;
});
};
const fetchPositionPath = async () => {
showLoader();
await http
.get(config.API.positionPath)
.then((res) => {
const data = res.data.result;
let option: any = [];
// data.map((r: DataOption) => {
option.push({ id: true, name: "ใช่" });
option.push({ id: false, name: "ไม่ใช่" });
// });
Ops.value.positionPathOptions = option;
OpsFilter.value.positionPathOptions = option;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
store.isLoad++;
// hideLoader();
});
};
const filterSelector = (val: any, update: Function, refData: string) => {
switch (refData) {
case "levelOptions":
update(() => {
Ops.value.levelOptions = OpsFilter.value.levelOptions.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "positionPathOptions":
update(() => {
Ops.value.positionPathOptions =
OpsFilter.value.positionPathOptions.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
default:
break;
}
};
const fetchData = async () => {
if (profileId.value) {
showLoader();
await http
.get(config.API.profileEduId(profileId.value))
.then((res) => {
let data = res.data.result;
rows.value = [];
data.map((e: ResponseObject) => {
rows.value.push({
id: e.id,
level: e.educationLevel,
levelId: e.educationLevelId,
positionPath: e.positionPath,
isEducation: e.isEducation,
institute: e.institute,
degree: e.degree,
field: e.field,
gpa: e.gpa,
country: e.country,
duration: e.duration,
durationYear: e.durationYear,
other: e.other,
fundName: e.fundName,
isDate: e.isDate == null ? null : e.isDate.toString(),
finishDate: e.finishDate ? new Date(e.finishDate) : null,
startDate: e.startDate ? new Date(e.startDate).getFullYear() : null,
endDate: e.endDate ? new Date(e.endDate).getFullYear() : null,
startDate2: e.startDate ? new Date(e.startDate) : null,
endDate2: e.endDate ? new Date(e.endDate) : null,
createdFullName: e.createdFullName,
createdAt: new Date(e.createdAt),
note: e.note,
});
});
console.log(data);
console.log(rows.value);
})
.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];
levelId.value = row.levelId;
isEducation.value = row.isEducation;
institute.value = row.institute;
degree.value = row.degree;
field.value = row.field;
gpa.value = row.gpa;
country.value = row.country;
duration.value = row.duration;
durationYear.value = row.durationYear;
other.value = row.other;
fundName.value = row.fundName;
finishDate.value = row.finishDate ? row.finishDate : null;
isDate.value = row.isDate;
startDate.value = row.startDate;
endDate.value = row.endDate;
startDate2.value = row.startDate2;
note.value = row.note;
inputStartDate.value = row.startDate
? (Number(row.startDate) + 543).toLocaleString()
: "";
inputEndDate.value = row.endDate
? (Number(row.endDate) + 543).toLocaleString()
: "";
inputStartDate2.value = row.startDate2
? convertDateDisplay(row.startDate2 as Date)
: "";
inputEndDate2.value = row.endDate2
? convertDateDisplay(row.endDate2 as Date)
: "";
finishDateInput.value = row.finishDate
? convertDateDisplay(row.finishDate)
: "-";
endDate2.value = row.endDate2;
id.value = row.id;
};
/**
* เช็คปุ่มดูข้อมูล ย้อน กับ ต่อไป ว่าต้องแสดงไหม
*/
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 () => {
// const filter = OpsFilter.value.levelOptions.filter(
// (r: any) => r.id == levelId.value
// );
// const filterPositionPath = OpsFilter.value.positionPathOptions.filter(
// (r: any) => r.id == isEducation.value
// );
if (profileId.value) {
showLoader();
await http
.post(config.API.profileEduId(profileId.value), {
id: id.value,
// educationLevel: filter[0].name,
educationLevelId: levelId.value,
isEducation: isEducation.value,
institute: institute.value,
degree: degree.value,
field: field.value,
gpa: gpa.value,
country: country.value,
duration: duration.value,
durationYear: durationYear.value,
other: other.value,
fundName: fundName.value,
isDate: isDate.value == "true" ? true : false,
finishDate: finishDate.value
? dateToISO(finishDate.value as Date)
: null,
startDate:
isDate.value == "true"
? startDate2.value
? dateToISO(startDate2.value as Date)
: null
: new Date(`${startDate.value}-01-01`),
endDate:
isDate.value == "true"
? endDate2.value
? dateToISO(endDate2.value as Date)
: null
: new Date(`${endDate.value}-01-01`),
note:note.value
})
.then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ");
modal.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchData();
});
}
};
/**
* บันทึกแก้ไขข้อมูล
*/
const editData = async () => {
// const filter = OpsFilter.value.levelOptions.filter(
// (r: any) => r.id == levelId.value
// );
// const filterPositionPath = OpsFilter.value.positionPathOptions.filter(
// (r: any) => r.id == isEducation.value
// );
showLoader();
await http
.put(config.API.profileEduId(id.value), {
id: id.value,
// educationLevel: filter[0].name,
educationLevelId: levelId.value,
isEducation: isEducation.value,
institute: institute.value,
degree: degree.value,
field: field.value,
gpa: gpa.value,
country: country.value,
duration: duration.value,
durationYear: durationYear.value,
other: other.value,
fundName: fundName.value,
isDate: isDate.value == "true" ? true : false,
finishDate: finishDate.value ? dateToISO(finishDate.value as Date) : null,
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`),
note:note.value
})
.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.profileEduId(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) => {
console.log(_props);
modalEdit.value = true;
modal.value = true;
edit.value = false;
rawItem.value = _props.row;
rowIndex.value = _props.rowIndex;
levelId.value = _props.row.levelId;
isEducation.value = _props.row.isEducation;
institute.value = _props.row.institute;
degree.value = _props.row.degree;
field.value = _props.row.field;
gpa.value = _props.row.gpa;
country.value = _props.row.country;
duration.value = _props.row.duration;
durationYear.value = _props.row.durationYear;
other.value = _props.row.other;
fundName.value = _props.row.fundName;
finishDate.value = _props.row.finishDate ? _props.row.finishDate : null;
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;
id.value = _props.row.id;
note.value = _props.row.note;
inputStartDate.value = _props.row.startDate
? (Number(_props.row.startDate) + 543).toLocaleString()
: "";
inputEndDate.value = _props.row.endDate
? (Number(_props.row.endDate) + 543).toLocaleString()
: "";
inputStartDate2.value = _props.row.startDate2
? convertDateDisplay(_props.row.startDate2 as Date)
: "";
inputEndDate2.value = _props.row.endDate2
? convertDateDisplay(_props.row.endDate2 as Date)
: "";
finishDateInput.value = _props.row.finishDate
? convertDateDisplay(_props.row.finishDate)
: "-";
await checkRowPage();
};
/**
* กดปุ่มเพิ่มบน table
*/
const addData = () => {
modalEdit.value = false;
modal.value = true;
edit.value = true;
levelId.value = "";
isEducation.value = null;
institute.value = "";
degree.value = "";
field.value = "";
gpa.value = "";
country.value = "";
duration.value = "";
durationYear.value = 0;
other.value = "";
fundName.value = "";
isDate.value = "true";
finishDate.value = null;
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 = "";
finishDateInput.value = "";
note.value = "";
dayChecked2.value = false;
dayEndChecked2.value = false;
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.profileEduHisId(row.id))
.then((res) => {
let data = res.data.result;
rowsHistory.value = [];
data.map((e: ResponseObject) => {
rowsHistory.value.push({
id: e.id,
level: e.educationLevel,
levelId: e.educationLevelId,
positionPath: e.positionPath,
isEducation: e.isEducation,
institute: e.institute,
degree: e.degree,
field: e.field,
gpa: e.gpa,
country: e.country,
duration: e.duration,
durationYear: e.durationYear,
other: e.other,
fundName: e.fundName,
note: e.note,
isDate: e.isDate,
finishDate: e.finishDate ? new Date(e.finishDate) : null,
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 {
dayChecked2.value = true;
inputStartDate2.value = "";
}
} else {
startDate2.value = null;
}
}
);
watch(
() => inputEndDate2.value,
(value: string) => {
if (value.length === 10) {
const dateVal = convertDate(value);
if (dateVal.isValid) {
dayEndChecked2.value = false;
endDate2.value = dateVal.value;
} else {
dayEndChecked2.value = true;
inputEndDate2.value = "";
}
} else {
endDate2.value = null;
}
}
);
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(
() => finishDateInput.value,
(value: string) => {
if (value.length === 10) {
const dateVal = convertDate(value);
if (dateVal.isValid) {
finishDate.value = dateVal.value;
} else {
finishDateInput.value = "";
}
}
}
);
</script>
<style lang="scss">
.modalfix {
position: fixed !important;
}
.borderCard {
border: 1px solid #d0d0d0;
}
</style>