hrms-mgt/src/modules/06_retirement/components/DismissOrder/outRegistry.vue

403 lines
12 KiB
Vue
Raw Normal View History

2023-09-15 15:42:23 +07:00
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import keycloak from "@/plugins/keycloak";
/**Import type */
2023-09-15 15:42:23 +07:00
import type { QForm } from "quasar";
import type { DataProfile } from "@/modules/05_placement/interface/index/Main";
/** importComponents*/
import CardProfile from "@/components/CardProfile.vue";
2024-04-30 10:59:11 +07:00
/** use */
2023-09-15 15:42:23 +07:00
const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const mixin = useCounterMixin();
const dataId = route.params.id.toString();
const {
date2Thai,
dialogMessage,
messageError,
showLoader,
hideLoader,
success,
findOrgName,
2023-09-15 15:42:23 +07:00
} = mixin;
/**
* กำหนดคาตวแปร
*/
2023-09-15 15:42:23 +07:00
const myForm = ref<QForm | null>(null);
const roleAdmin = ref<boolean>(false);
const edit = ref<boolean>(false);
const organizationPositionOld = ref<string>("");
const positionTypeOld = ref<string>("");
const positionLevelOld = ref<string>("");
const posNo = ref<string>("");
const salary = ref<number>(0);
const organization = ref<string>("");
const date = ref<Date | null>(null);
const reason = ref<string>("");
const dataProfile = ref<DataProfile>();
2023-09-15 15:42:23 +07:00
const fullName = ref<string>("");
const status = ref<string>("");
2023-09-15 15:42:23 +07:00
//นำข้อมูลจาก API มาแสดง
2023-09-15 15:42:23 +07:00
const getData = async () => {
showLoader();
await http
.get(config.API.outByid(dataId))
.then((res) => {
2023-09-15 15:42:23 +07:00
const data = res.data.result;
dataProfile.value = data as DataProfile;
fullName.value = `${data.prefix}${data.firstName ?? "-"} ${
2023-09-15 15:42:23 +07:00
data.lastName ?? "-"
}`;
status.value = data.status;
organizationPositionOld.value = data.organizationPositionOld
? data.organizationPositionOld
: findOrgName(data);
2023-09-15 15:42:23 +07:00
positionTypeOld.value = data.positionTypeOld ?? "";
positionLevelOld.value = data.positionLevelOld ?? "";
posNo.value = data.positionNumberOld ?? "";
2023-09-15 15:42:23 +07:00
salary.value = data.salary ?? "";
organization.value = data.organization ?? "";
date.value = data.date !== null ? new Date(data.date) : null;
reason.value = data.reason ?? "";
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
/**
* งก Cancle
*/
const clickCancel = async () => {
await getData();
edit.value = false;
myForm.value?.resetValidation();
2023-09-15 15:42:23 +07:00
};
/**
* งก Saveจาก API
*/
const onSubmit = async () => {
dialogMessage(
$q,
"ต้องการแก้ไขข้อมูลหรือไม่?",
"แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย",
"mdi-help-circle-outline",
"ตกลง",
"public",
async () => {
const body = {
organizationPositionOld: organizationPositionOld.value,
positionTypeOld: positionTypeOld.value,
positionLevelOld: positionLevelOld.value,
positionNumberOld: posNo.value,
2024-05-16 10:58:18 +07:00
amountOld: salary.value.toString().replace(/,/g, ""),
organization: organization.value,
reason: reason.value,
date: date.value,
};
showLoader();
await http
.put(config.API.outByid(dataId), body)
.then(() => {
success($q, "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้ายสำเร็จ");
edit.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await getData();
hideLoader();
});
},
undefined
);
2023-09-15 15:42:23 +07:00
};
/**
* Function เพ Class เวลา Edit
* @param val เมอเปนEdit จะเปลยน Class
*/
2023-09-15 15:42:23 +07:00
const getClass = (val: boolean) => {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
};
/** Hook */
onMounted(async () => {
if (keycloak.tokenParsed != null) {
roleAdmin.value = await keycloak.tokenParsed.role.includes("placement1");
}
await getData();
});
2023-09-15 15:42:23 +07:00
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.go(-1)"
/>
รายละเอยดการใหออกของ {{ fullName }}
</div>
<CardProfile :data="dataProfile as DataProfile" />
<q-card bordered class="row col-12 text-dark q-mt-sm">
<q-form
ref="myForm"
greedy
@submit.prevent
@validation-success="onSubmit"
class="col-12"
>
<div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
<div class="q-pl-sm text-weight-bold text-dark">
แกไขขอมลเพอลงบญชแนบทาย
</div>
<q-space />
<div v-if="status !== 'DONE' && status !== 'REPORT'">
<div class="q-gutter-sm" v-if="!edit">
<q-btn
outline
color="primary"
dense
icon-right="mdi-file-edit-outline"
class="q-px-sm"
label="แก้ไข"
style="width: 80px"
@click="edit = !edit"
/>
</div>
<div class="q-gutter-sm" v-else>
<q-btn
outline
color="public"
dense
class="q-px-sm"
label="บันทึก"
style="width: 80px"
type="submit"
/>
<q-btn
outline
color="red"
dense
class="q-px-sm"
label="ยกเลิก"
style="width: 80px"
@click="clickCancel"
/>
</div>
</div>
</div>
<div class="col-12"><q-separator /></div>
<div class="row col-12 q-pa-md">
<div class="col-12 row bg-white q-col-gutter-md">
<div class="col-xs-12 row items-center">
<div class="col-12">
<div class="text-weight-bold">ตำแหนงและหนวยงานเด</div>
</div>
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="organizationPositionOld"
:rules="[(val) => !!val || `${'กรุณากรอกตำแหน่ง/สังกัด'}`]"
hide-bottom-space
:label="`${'ตำแหน่ง/สังกัด'}`"
type="textarea"
/>
</div>
</div>
2023-09-15 15:42:23 +07:00
<div class="col-xs-6 col-sm-3 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="positionTypeOld"
:rules="[(val) => !!val || `${'กรุณากรอกประเภทตำแหน่ง'}`]"
hide-bottom-space
:label="`${'ประเภทตำแหน่ง'}`"
/>
</div>
</div>
2023-09-15 15:42:23 +07:00
<div class="col-xs-6 col-sm-3 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="positionLevelOld"
:rules="[(val) => !!val || `${'กรุณากรอกระดับ'}`]"
hide-bottom-space
:label="`${'ระดับ'}`"
/>
</div>
</div>
2023-09-15 15:42:23 +07:00
<div class="col-xs-6 col-sm-3 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="posNo"
:rules="[(val) => !!val || `${'กรุณากรอกเลขที่'}`]"
hide-bottom-space
:label="`${'เลขที่'}`"
/>
</div>
</div>
2023-09-15 15:42:23 +07:00
<div class="col-xs-6 col-sm-3 row">
<div class="col-12">
2024-05-16 10:58:18 +07:00
<q-input
2023-08-22 09:33:53 +07:00
v-model="salary"
2024-05-16 10:58:18 +07:00
:outlined="edit"
dense
:readonly="!edit"
hide-bottom-space
:borderless="!edit"
2023-08-22 09:33:53 +07:00
:label="`${'เงินเดือน'}`"
2024-05-16 10:58:18 +07:00
:rules="[(val:number) => !!val || `${'กรุณากรอกเงินเดือน'}`]"
lazy-rules
mask="###,###,###,###"
reverse-fill-mask
class="inputgreen"
/>
</div>
</div>
<div class="col-12"><q-separator /></div>
2023-09-15 15:42:23 +07:00
<div class="col-xs-6 col-sm-6 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="organization"
:rules="[(val) => !!val || `${'กรุณากรอกการให้ออกสังกัด'}`]"
hide-bottom-space
:label="`${'การให้ออกสังกัด'}`"
/>
</div>
</div>
2023-09-15 15:42:23 +07:00
<div class="col-xs-6 col-sm-6 row">
<div class="col-12">
<datepicker
menu-class-name="modalfix"
:readonly="!edit"
v-model="date"
:locale="'th'"
autoApply
: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)"
:outlined="edit"
dense
2023-08-22 14:02:35 +07:00
:readonly="!edit"
:borderless="!edit"
:model-value="date !== null ? date2Thai(date) : null"
: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-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="reason"
hide-bottom-space
:label="`${'หมายเหตุ '}`"
type="textarea"
/>
</div>
</div>
</div>
</q-form>
</q-card>
</template>
<style lang="scss" scope>
.q-img {
border-radius: 5px;
height: 70px;
}
.text-top {
color: gray;
font-weight: 400;
padding-bottom: 3px;
}
.text-detail {
font-weight: 500;
}
</style>