2024-03-14 16:03:27 +07:00
|
|
|
<script setup lang="ts">
|
2024-09-17 09:28:34 +07:00
|
|
|
import { ref, reactive, watch } from "vue";
|
2024-03-14 16:03:27 +07:00
|
|
|
import { useQuasar } from "quasar";
|
|
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
|
|
|
|
|
2024-07-25 15:00:26 +07:00
|
|
|
/**
|
|
|
|
|
* importType
|
|
|
|
|
*/
|
2024-03-14 16:03:27 +07:00
|
|
|
import type {
|
2024-03-14 17:39:20 +07:00
|
|
|
ResGroup,
|
|
|
|
|
ResLevel,
|
2024-07-31 09:48:33 +07:00
|
|
|
} from "@/modules/01_masterdata/interface/response/positionEmployee/Main";
|
|
|
|
|
import type { ObjectPosRef } from "@/modules/01_masterdata/interface/index/positionEmployee";
|
2024-03-14 17:39:20 +07:00
|
|
|
import type { DataOption } from "@/modules/16_positionEmployee/interface/index/Main";
|
|
|
|
|
import type { OptionType } from "@/modules/16_positionEmployee/interface/response/organizational";
|
|
|
|
|
|
2024-07-25 15:00:26 +07:00
|
|
|
/**
|
|
|
|
|
* importComponents
|
|
|
|
|
*/
|
2024-03-14 17:39:20 +07:00
|
|
|
import DialogHeader from "@/components/DialogHeader.vue";
|
|
|
|
|
|
2024-07-25 15:00:26 +07:00
|
|
|
/**
|
|
|
|
|
* importStore
|
|
|
|
|
*/
|
2024-03-14 17:39:20 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2024-03-14 16:03:27 +07:00
|
|
|
|
2024-07-25 15:00:26 +07:00
|
|
|
/**
|
|
|
|
|
* use
|
|
|
|
|
*/
|
|
|
|
|
const $q = useQuasar();
|
|
|
|
|
const mixin = useCounterMixin();
|
|
|
|
|
const { dialogConfirm, showLoader, hideLoader, messageError, success } = mixin;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* props
|
|
|
|
|
*/
|
|
|
|
|
const modal = defineModel<boolean>("modalAdd", { required: true });
|
|
|
|
|
const isEditCheck = defineModel<boolean>("isEdit", { required: true });
|
2024-03-14 16:03:27 +07:00
|
|
|
const props = defineProps({
|
|
|
|
|
emitSearch: Function,
|
|
|
|
|
getData: Function,
|
|
|
|
|
data: Object,
|
|
|
|
|
levelOp: Object,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const isDisValidate = ref<boolean>(false);
|
2024-07-25 15:00:26 +07:00
|
|
|
const isSpecial = ref<boolean>(false);
|
2024-03-14 17:39:20 +07:00
|
|
|
const formDataPos = reactive({
|
|
|
|
|
posName: "",
|
|
|
|
|
posTypeName: "",
|
|
|
|
|
posLevelName: "",
|
2024-03-14 16:03:27 +07:00
|
|
|
});
|
|
|
|
|
|
2024-03-14 17:39:20 +07:00
|
|
|
const posNameRef = ref<object | null>(null);
|
|
|
|
|
const posTypeNameRef = ref<object | null>(null);
|
|
|
|
|
const posLevelNameRef = ref<object | null>(null);
|
|
|
|
|
const objectRef: ObjectPosRef = {
|
|
|
|
|
posName: posNameRef,
|
|
|
|
|
posTypeName: posTypeNameRef,
|
|
|
|
|
posLevelName: posLevelNameRef,
|
2024-03-14 16:03:27 +07:00
|
|
|
};
|
2024-03-14 17:39:20 +07:00
|
|
|
const posTypeMain = ref<ResGroup[]>([]);
|
|
|
|
|
const posTypeOp = ref<DataOption[]>([]);
|
|
|
|
|
const posLevelOp = ref<DataOption[]>([]);
|
2024-03-14 16:03:27 +07:00
|
|
|
|
2024-07-25 15:00:26 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม
|
|
|
|
|
*/
|
2024-03-14 16:03:27 +07:00
|
|
|
function validateFormPositionEdit() {
|
|
|
|
|
isDisValidate.value = false;
|
|
|
|
|
const hasError = [];
|
2024-03-14 17:39:20 +07:00
|
|
|
for (const key in objectRef) {
|
|
|
|
|
if (Object.prototype.hasOwnProperty.call(objectRef, key)) {
|
|
|
|
|
const property = objectRef[key];
|
2024-03-14 16:03:27 +07:00
|
|
|
if (property.value && typeof property.value.validate === "function") {
|
|
|
|
|
const isValid = property.value.validate();
|
|
|
|
|
hasError.push(isValid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasError.every((result) => result === true)) {
|
2024-03-14 17:39:20 +07:00
|
|
|
dialogConfirm($q, () => {
|
|
|
|
|
submit();
|
|
|
|
|
});
|
2024-03-14 16:03:27 +07:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-14 17:39:20 +07:00
|
|
|
async function submit() {
|
|
|
|
|
const body = {
|
|
|
|
|
posDictName: formDataPos.posName,
|
|
|
|
|
posTypeId: formDataPos.posTypeName,
|
|
|
|
|
posLevelId: formDataPos.posLevelName,
|
|
|
|
|
};
|
|
|
|
|
showLoader();
|
|
|
|
|
try {
|
|
|
|
|
const url = !isEditCheck.value
|
|
|
|
|
? config.API.orgEmployeePos
|
|
|
|
|
: config.API.orgEmployeePosById(props?.data?.id);
|
|
|
|
|
await http[!isEditCheck.value ? "post" : "put"](url, body);
|
2024-07-25 15:00:26 +07:00
|
|
|
await props.emitSearch?.(formDataPos.posName, "positionName");
|
|
|
|
|
await success($q, "บันทีกข้อมูลสำเร็จ");
|
|
|
|
|
await close();
|
2024-03-14 17:39:20 +07:00
|
|
|
} catch (err) {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
} finally {
|
|
|
|
|
hideLoader();
|
|
|
|
|
}
|
2024-03-14 16:03:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function clearFormPositionSelect() {
|
|
|
|
|
isEditCheck.value = false;
|
2024-03-14 17:39:20 +07:00
|
|
|
isDisValidate.value = true;
|
|
|
|
|
formDataPos.posName = "";
|
|
|
|
|
formDataPos.posTypeName = "";
|
|
|
|
|
formDataPos.posLevelName = "";
|
2024-03-14 16:03:27 +07:00
|
|
|
isSpecial.value = false;
|
2024-03-14 17:39:20 +07:00
|
|
|
setTimeout(() => {
|
|
|
|
|
isDisValidate.value = false;
|
2024-03-14 16:03:27 +07:00
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
|
modal.value = false;
|
|
|
|
|
clearFormPositionSelect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fetchType() {
|
|
|
|
|
showLoader();
|
|
|
|
|
await http
|
2024-03-14 17:39:20 +07:00
|
|
|
.get(config.API.orgEmployeeType)
|
2024-03-14 16:03:27 +07:00
|
|
|
.then((res) => {
|
2024-03-14 17:39:20 +07:00
|
|
|
posTypeMain.value = res.data.result;
|
|
|
|
|
posTypeOp.value = res.data.result.map((e: OptionType) => ({
|
2024-03-14 16:03:27 +07:00
|
|
|
id: e.id,
|
|
|
|
|
name: e.posTypeName,
|
|
|
|
|
}));
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 17:39:20 +07:00
|
|
|
function updatePosTypeName(id: string) {
|
|
|
|
|
const posLevel = posTypeMain.value.find((e: ResGroup) => e.id === id);
|
|
|
|
|
posLevelOp.value =
|
|
|
|
|
posLevel?.posLevels.map((e: ResLevel) => ({
|
|
|
|
|
id: e.id,
|
|
|
|
|
name: e.posLevelName.toString(),
|
|
|
|
|
})) ?? [];
|
|
|
|
|
formDataPos.posLevelName = "";
|
2024-03-14 16:03:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => modal.value,
|
|
|
|
|
async () => {
|
|
|
|
|
if (modal.value === true) {
|
|
|
|
|
await fetchType();
|
2024-03-14 17:39:20 +07:00
|
|
|
|
2024-03-14 16:03:27 +07:00
|
|
|
if (props.data) {
|
|
|
|
|
const dataList = props.data;
|
2024-03-14 17:39:20 +07:00
|
|
|
updatePosTypeName(dataList.posTypeId);
|
|
|
|
|
|
|
|
|
|
formDataPos.posName = dataList.posDictName;
|
|
|
|
|
formDataPos.posTypeName = dataList.posTypeId;
|
|
|
|
|
formDataPos.posLevelName = dataList.posLevelId;
|
2024-03-14 16:03:27 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
</script>
|
2024-03-14 17:39:20 +07:00
|
|
|
|
2024-03-14 16:03:27 +07:00
|
|
|
<template>
|
|
|
|
|
<q-dialog v-model="modal" persistent>
|
|
|
|
|
<q-card style="min-width: 50vw">
|
|
|
|
|
<DialogHeader
|
|
|
|
|
:tittle="`${isEditCheck ? `แก้ไขข้อมูลตำแหน่ง` : `เพิ่มข้อมูลตำแหน่ง`}`"
|
|
|
|
|
:close="close"
|
|
|
|
|
/>
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
|
|
<q-card-section class="q-pa-none">
|
|
|
|
|
<form @submit.prevent="validateFormPositionEdit">
|
2024-03-14 17:39:20 +07:00
|
|
|
<div class="row q-col-gutter-sm col-12 q-pa-md">
|
|
|
|
|
<div class="col-12">
|
2024-03-14 16:03:27 +07:00
|
|
|
<q-input
|
2024-03-14 17:39:20 +07:00
|
|
|
ref="posNameRef"
|
|
|
|
|
v-model="formDataPos.posName"
|
2024-03-14 16:03:27 +07:00
|
|
|
dense
|
|
|
|
|
outlined
|
|
|
|
|
for="#positionName"
|
2024-03-14 17:39:20 +07:00
|
|
|
label="ชื่อตำแหน่ง"
|
2024-03-14 16:03:27 +07:00
|
|
|
lazy-rules
|
|
|
|
|
hide-bottom-space
|
2024-03-14 17:39:20 +07:00
|
|
|
:rules="[(val) => !!val || `${'กรุณากรอกชื่อตำแหน่ง'}`]"
|
2024-03-14 16:03:27 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
2024-03-14 17:39:20 +07:00
|
|
|
|
2024-03-14 16:03:27 +07:00
|
|
|
<div class="col-6">
|
|
|
|
|
<q-select
|
2024-03-14 17:39:20 +07:00
|
|
|
ref="posTypeNameRef"
|
|
|
|
|
label="กลุ่มงาน"
|
|
|
|
|
v-model="formDataPos.posTypeName"
|
|
|
|
|
:options="posTypeOp"
|
2024-03-14 16:03:27 +07:00
|
|
|
emit-value
|
|
|
|
|
dense
|
|
|
|
|
map-options
|
|
|
|
|
outlined
|
|
|
|
|
option-label="name"
|
|
|
|
|
option-value="id"
|
|
|
|
|
lazy-rules
|
|
|
|
|
hide-bottom-space
|
2024-03-14 17:39:20 +07:00
|
|
|
:rules="[(val) => !!val || `${'กรุณาเลือกกลุ่มงาน'}`]"
|
|
|
|
|
@update:model-value="updatePosTypeName"
|
2024-03-14 16:03:27 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
2024-03-14 17:39:20 +07:00
|
|
|
|
2024-03-14 16:03:27 +07:00
|
|
|
<div class="col-6">
|
|
|
|
|
<q-select
|
2024-03-14 17:39:20 +07:00
|
|
|
ref="posLevelNameRef"
|
|
|
|
|
label="ระดับชั้นงาน"
|
|
|
|
|
v-model="formDataPos.posLevelName"
|
|
|
|
|
:disable="formDataPos.posTypeName === ''"
|
|
|
|
|
:options="posLevelOp"
|
2024-03-14 16:03:27 +07:00
|
|
|
emit-value
|
|
|
|
|
dense
|
|
|
|
|
map-options
|
|
|
|
|
outlined
|
|
|
|
|
option-label="name"
|
|
|
|
|
option-value="id"
|
|
|
|
|
lazy-rules
|
|
|
|
|
hide-bottom-space
|
2024-03-14 17:39:20 +07:00
|
|
|
:rules="[(val) => !!val || `${'กรุณาเลือกระดับชั้นงาน'}`]"
|
2024-03-14 16:03:27 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-03-14 17:39:20 +07:00
|
|
|
|
2024-03-14 16:03:27 +07:00
|
|
|
<q-separator />
|
|
|
|
|
<q-card-actions align="right" class="bg-white text-teal q-pa-sm">
|
|
|
|
|
<q-btn
|
|
|
|
|
type="submit"
|
|
|
|
|
:label="`${isEditCheck ? 'แก้ไขตำแหน่ง' : 'เพิ่มตำแหน่ง'}`"
|
|
|
|
|
color="public"
|
|
|
|
|
/>
|
|
|
|
|
</q-card-actions>
|
|
|
|
|
</form>
|
|
|
|
|
</q-card-section>
|
|
|
|
|
</q-card>
|
|
|
|
|
</q-dialog>
|
|
|
|
|
</template>
|