623 lines
18 KiB
Vue
623 lines
18 KiB
Vue
<!-- tab ประวัติการทำงาน/ฝึกงาน -->
|
|
<template>
|
|
<q-card flat bordered class="col-12 q-px-lg q-py-md">
|
|
<q-form ref="myForm">
|
|
<Table
|
|
:rows="rows"
|
|
:columns="columns"
|
|
:filter="filter"
|
|
:visible-columns="visibleColumns"
|
|
v-model:inputfilter="filter"
|
|
v-model:inputvisible="visibleColumns"
|
|
v-model:editvisible="edit"
|
|
:add="clickAdd"
|
|
:edit="clickEdit"
|
|
:cancel="clickCancel"
|
|
:addData="false"
|
|
:editData="status == 'register' || status == 'rejectRegister'"
|
|
name="ประวัติการทำงาน/ฝึกงาน"
|
|
icon="mdi-briefcase"
|
|
>
|
|
<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 == 'salary'" class="">
|
|
{{ col.value.toLocaleString('en-US') }}
|
|
</div>
|
|
<div v-else-if="col.name == 'duration'" class="">
|
|
{{ dateThaiRange(col.value) }}
|
|
</div>
|
|
<div v-else class="">
|
|
{{ col.value }}
|
|
</div>
|
|
</q-td>
|
|
<q-td auto-width v-if="edit === true">
|
|
<q-btn
|
|
color="red"
|
|
flat
|
|
dense
|
|
round
|
|
size="14px"
|
|
icon="mdi-trash-can-outline"
|
|
@click="checkDelete(props.row)"
|
|
/>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
</Table>
|
|
</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="checkClose" />
|
|
<q-separator />
|
|
<q-card-section class="q-p-sm">
|
|
<div class="row col-12 items-center 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="location"
|
|
: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="position"
|
|
: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="salary"
|
|
:rules="[(val) => !!val || `${'กรุณากรอกเงินเดือนสุดท้ายก่อนออก'}`]"
|
|
:label="`${'เงินเดือนสุดท้ายก่อนออก'}`"
|
|
@update:modelValue="clickEditRow"
|
|
type="number"
|
|
/>
|
|
</div>
|
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
|
<datepicker
|
|
:readonly="!edit"
|
|
v-model="duration"
|
|
: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)"
|
|
class="datepicker"
|
|
hide-bottom-space
|
|
:outlined="edit"
|
|
dense
|
|
lazy-rules
|
|
:borderless="!edit"
|
|
:model-value="dateThaiRange(duration)"
|
|
>
|
|
<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 class="col-xs-12 col-sm-12 col-md-12">
|
|
<q-input
|
|
:class="getClass(edit)"
|
|
hide-bottom-space
|
|
:outlined="edit"
|
|
dense
|
|
lazy-rules
|
|
:readonly="!edit"
|
|
:borderless="!edit"
|
|
v-model="reason"
|
|
:rules="[(val) => !!val || `${'กรุณากรอกเหตุผลที่ออก'}`]"
|
|
:label="`${'เหตุผลที่ออก'}`"
|
|
@update:modelValue="clickEditRow"
|
|
type="textarea"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</q-card-section>
|
|
<q-separator />
|
|
<DialogFooter
|
|
:cancel="clickCancel"
|
|
:edit="clickEdit"
|
|
:save="clickSave"
|
|
:validate="validateData"
|
|
:clickNext="clickNext"
|
|
:clickPrevious="clickPrevious"
|
|
:editData="status == 'register' || status == 'rejectRegister'"
|
|
v-model:editvisible="edit"
|
|
v-model:next="next"
|
|
v-model:previous="previous"
|
|
v-model:modalEdit="modalEdit"
|
|
/>
|
|
</q-form>
|
|
</q-card>
|
|
</q-dialog>
|
|
<q-dialog :model-value="modalConsend" persistent>
|
|
<q-card style="min-width: 800px">
|
|
<Conference :ok="consendOk" :close="consenClose" />
|
|
</q-card>
|
|
</q-dialog>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { onMounted, ref, watch } from 'vue'
|
|
import { useQuasar } from 'quasar'
|
|
import { useCounterMixin } from '@/stores/mixin'
|
|
import http from '@/plugins/http'
|
|
import config from '@/app.config'
|
|
import { useExamDataStore } from '@/modules/01_exam/store'
|
|
import type {
|
|
RequestItemsObject,
|
|
Columns,
|
|
DataProps
|
|
} from '@/modules/01_exam/interface/request/Career'
|
|
import type { ResponseObject } from '@/modules/01_exam/interface/response/Career'
|
|
import Table from '@/components/Table.vue'
|
|
import DialogHeader from '@/components/DialogHeader.vue'
|
|
import DialogFooter from '@/components/DialogFooter.vue'
|
|
import Conference from '@/modules/01_exam/components/Conference.vue'
|
|
|
|
const props = defineProps({
|
|
loader: {
|
|
//หน้า main มีการอัพเดทค่าให้ refresh data
|
|
type: Boolean,
|
|
required: true
|
|
},
|
|
status: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
statusEdit: {
|
|
type: Boolean,
|
|
required: true
|
|
}
|
|
})
|
|
|
|
const $q = useQuasar()
|
|
const mixin = useCounterMixin() //เรียกฟังก์ชันกลาง
|
|
const { dateThaiRange, modalDelete, modalConfirm, dateToISO, success } = mixin
|
|
const store = useExamDataStore()
|
|
const { examData, changeExamColumns } = store
|
|
const loader = ref<boolean>(false)
|
|
const id = ref<string>('')
|
|
const location = ref<string>()
|
|
const position = ref<string>()
|
|
const salary = ref<number | null>()
|
|
const duration = ref<[Date, Date]>([new Date(), new Date()])
|
|
const reason = ref<string>()
|
|
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 statusCode = ref<number>()
|
|
const checkValidate = ref<boolean>(false) //validate data ผ่านหรือไม่
|
|
const modalConsend = ref<boolean>(false)
|
|
const candidateId = ref<string>('2223ba53-2fb2-470b-8dc1-27e5471b0331')
|
|
const rows = ref<RequestItemsObject[]>([])
|
|
const filter = ref<string>('') //search data table
|
|
|
|
const emit = defineEmits(['update:loader', 'update:statusEdit'])
|
|
|
|
const visibleColumns = ref<String[]>([])
|
|
|
|
examData.career.columns.length == 0
|
|
? (visibleColumns.value = ['location', 'position', 'salary', 'duration', 'reason'])
|
|
: (visibleColumns.value = examData.career.columns)
|
|
|
|
const columns = ref<Columns>([
|
|
{
|
|
name: 'location',
|
|
align: 'left',
|
|
label: 'สถานที่ทำงาน/ฝึกงาน',
|
|
sortable: true,
|
|
field: 'location',
|
|
headerStyle: 'font-size: 14px',
|
|
style: 'font-size: 14px'
|
|
},
|
|
{
|
|
name: 'position',
|
|
align: 'left',
|
|
label: 'ตำแหน่ง/ลักษณะงาน',
|
|
sortable: true,
|
|
field: 'position',
|
|
headerStyle: 'font-size: 14px',
|
|
style: 'font-size: 14px'
|
|
},
|
|
{
|
|
name: 'salary',
|
|
align: 'left',
|
|
label: 'เงินเดือนสุดท้ายก่อนออก',
|
|
sortable: true,
|
|
field: 'salary',
|
|
headerStyle: 'font-size: 14px',
|
|
style: 'font-size: 14px'
|
|
},
|
|
{
|
|
name: 'duration',
|
|
align: 'left',
|
|
label: 'ระยะเวลา',
|
|
sortable: true,
|
|
field: 'duration',
|
|
headerStyle: 'font-size: 14px',
|
|
style: 'font-size: 14px'
|
|
},
|
|
{
|
|
name: 'reason',
|
|
align: 'left',
|
|
label: 'เหตุผลที่ออก',
|
|
sortable: true,
|
|
field: 'reason',
|
|
headerStyle: 'font-size: 14px',
|
|
style: 'font-size: 14px'
|
|
}
|
|
])
|
|
|
|
watch(loader, (count: boolean, prevCount: boolean) => {
|
|
emit('update:loader', count)
|
|
})
|
|
|
|
watch(visibleColumns, async (count: String[], prevCount: String[]) => {
|
|
await changeExamColumns('career', count)
|
|
})
|
|
|
|
watch(edit, (count: boolean, prevCount: boolean) => {
|
|
emit('update:statusEdit', count)
|
|
})
|
|
|
|
onMounted(async () => {
|
|
await fetchData()
|
|
})
|
|
|
|
const fetchData = async () => {
|
|
loader.value = true
|
|
await http
|
|
.get(config.API.candidateCareer(candidateId.value))
|
|
.then((res) => {
|
|
const data = res.data.result
|
|
rows.value = []
|
|
data.map((r: ResponseObject) => {
|
|
rows.value.push({
|
|
...r,
|
|
location: r.name,
|
|
duration: [r.durationStart, r.durationEnd]
|
|
})
|
|
})
|
|
})
|
|
.catch(() => {})
|
|
.finally(() => {
|
|
loader.value = false
|
|
})
|
|
}
|
|
|
|
/**
|
|
* กดดูข้อมูลก่อนหน้า
|
|
*/
|
|
const clickPrevious = () => {
|
|
rowIndex.value -= 1
|
|
const row = rows.value[rowIndex.value]
|
|
location.value = row.location
|
|
position.value = row.position
|
|
salary.value = row.salary
|
|
duration.value = row.duration
|
|
reason.value = row.reason
|
|
id.value = row.id
|
|
checkRowPage()
|
|
}
|
|
|
|
/**
|
|
* กดดูข้อมูลต่อไป
|
|
*/
|
|
const clickNext = () => {
|
|
rowIndex.value += 1
|
|
const row = rows.value[rowIndex.value]
|
|
location.value = row.location
|
|
position.value = row.position
|
|
salary.value = row.salary
|
|
duration.value = row.duration
|
|
reason.value = row.reason
|
|
id.value = row.id
|
|
checkRowPage()
|
|
}
|
|
|
|
/**
|
|
* เช็คปุ่มดูข้อมูล ย้อน กับ ต่อไป ว่าต้องแสดงไหม
|
|
*/
|
|
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 = () => {
|
|
edit.value = true
|
|
next.value = false
|
|
previous.value = false
|
|
}
|
|
|
|
/**
|
|
* กดปุ่มเพิ่มด้านบน table
|
|
*/
|
|
const clickAdd = () => {
|
|
addRow()
|
|
}
|
|
|
|
const checkDelete = (row: RequestItemsObject) => {
|
|
rawItem.value = row
|
|
modalDelete($q, 'ยืนยันการลบข้อมูล', 'หากต้องการลบกดให้กดตกลง', clickDeleteRow)
|
|
}
|
|
|
|
/**
|
|
* ลบข้อมูลใน table
|
|
*/
|
|
const clickDeleteRow = async () => {
|
|
if (rawItem.value != null) {
|
|
loader.value = true
|
|
await http
|
|
.delete(config.API.candidateCareer(rawItem.value.id))
|
|
.then(() => {
|
|
success($q, 'ลบข้อมูลสำเร็จ')
|
|
})
|
|
.catch(() => {
|
|
// modalError.value = true
|
|
// modalErrorTittle.value = 'ไม่สามารถบันทึกข้อมูลร่างได้'
|
|
// modalErrorDetail.value = e.response.data.message
|
|
// statusCode.value = e.response.data.status
|
|
})
|
|
.finally(async () => {
|
|
loader.value = false
|
|
await fetchData()
|
|
edit.value = false
|
|
})
|
|
} else {
|
|
await fetchData()
|
|
edit.value = false
|
|
}
|
|
}
|
|
|
|
/**
|
|
* กดบันทึกใน dialog
|
|
*/
|
|
const clickSave = async () => {
|
|
myForm.value.validate().then(async (result: boolean) => {
|
|
if (result) {
|
|
if (store.consend == true) {
|
|
if (modalEdit.value) {
|
|
await editData()
|
|
} else {
|
|
await saveData()
|
|
}
|
|
} else {
|
|
modalConsend.value = true
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* บันทึกเพิ่มข้อมูล
|
|
*/
|
|
const saveData = async () => {
|
|
loader.value = true
|
|
await http
|
|
.post(config.API.candidateCareer(candidateId.value), {
|
|
name: location.value,
|
|
position: position.value,
|
|
salary: salary.value,
|
|
durationStart: dateToISO(new Date(duration.value[0])),
|
|
durationEnd: dateToISO(new Date(duration.value[1])),
|
|
reason: reason.value
|
|
})
|
|
.then(() => {
|
|
success($q, 'บันทึกข้อมูลสำเร็จ')
|
|
})
|
|
.catch(() => {
|
|
// modalError.value = true
|
|
// modalErrorTittle.value = 'ไม่สามารถบันทึกข้อมูลร่างได้'
|
|
// modalErrorDetail.value = e.response.data.message
|
|
// statusCode.value = e.response.data.status
|
|
})
|
|
.finally(async () => {
|
|
loader.value = false
|
|
edit.value = false
|
|
modal.value = false
|
|
await fetchData()
|
|
})
|
|
}
|
|
|
|
/**
|
|
* บันทึกแก้ไขข้อมูล
|
|
*/
|
|
const editData = async () => {
|
|
loader.value = true
|
|
await http
|
|
.put(config.API.candidateCareer(id.value), {
|
|
name: location.value,
|
|
position: position.value,
|
|
salary: salary.value,
|
|
durationStart: dateToISO(new Date(duration.value[0])),
|
|
durationEnd: dateToISO(new Date(duration.value[1])),
|
|
reason: reason.value
|
|
})
|
|
.then(() => {
|
|
success($q, 'บันทึกข้อมูลสำเร็จ')
|
|
})
|
|
.catch(() => {
|
|
// modalError.value = true
|
|
// modalErrorTittle.value = 'ไม่สามารถบันทึกข้อมูลร่างได้'
|
|
// modalErrorDetail.value = e.response.data.message
|
|
// statusCode.value = e.response.data.status
|
|
})
|
|
.finally(async () => {
|
|
loader.value = false
|
|
edit.value = false
|
|
modal.value = false
|
|
await fetchData()
|
|
})
|
|
}
|
|
|
|
const checkClose = async () => {
|
|
if (editRow.value == true) {
|
|
modalConfirm($q, 'ข้อมูลมีการแก้ไข', 'ยืนยันการดำเนินต่อใช่หรือไม่', clickClose)
|
|
} else {
|
|
await clickClose()
|
|
}
|
|
await fetchData()
|
|
}
|
|
|
|
/**
|
|
* กดปิด dialog
|
|
*/
|
|
const clickClose = async () => {
|
|
modal.value = false
|
|
editRow.value = false
|
|
next.value = false
|
|
previous.value = false
|
|
}
|
|
|
|
/**
|
|
* กดเลือกข้อมูลที่จะแก้ไข
|
|
* @param props ค่า props ใน row ที่เลือก
|
|
*/
|
|
const selectData = (props: DataProps) => {
|
|
modalEdit.value = true
|
|
modal.value = true
|
|
editRow.value = false
|
|
rawItem.value = props.row
|
|
rowIndex.value = props.rowIndex
|
|
location.value = props.row.location
|
|
position.value = props.row.position
|
|
salary.value = props.row.salary
|
|
duration.value = props.row.duration
|
|
reason.value = props.row.reason
|
|
id.value = props.row.id
|
|
if (edit.value == true) {
|
|
next.value = false
|
|
previous.value = false
|
|
} else {
|
|
checkRowPage()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* กดปุ่มเพิ่มบน table
|
|
*/
|
|
const addRow = () => {
|
|
modalEdit.value = false
|
|
modal.value = true
|
|
location.value = ''
|
|
position.value = ''
|
|
salary.value = null
|
|
duration.value = [new Date(), new Date()]
|
|
reason.value = ''
|
|
}
|
|
|
|
const consenClose = () => {
|
|
modalConsend.value = false
|
|
}
|
|
|
|
const consendOk = () => {
|
|
modalConsend.value = false
|
|
store.consend = true
|
|
clickSave()
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันปุ่มยกเลิกการแก้ไขข้อมูล
|
|
*/
|
|
const clickCancel = async () => {
|
|
edit.value = false
|
|
}
|
|
|
|
/**
|
|
* เช็คว่ามีการแก้ไขข้อมูล
|
|
*/
|
|
const clickEditRow = () => {
|
|
editRow.value = true
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
}
|
|
}
|
|
</script>
|
|
<style lang="scss">
|
|
.modalfix {
|
|
position: fixed !important;
|
|
}
|
|
</style>
|