hrms-admin/src/modules/01_metadata/components/position-employee/GroupDetail.vue

386 lines
12 KiB
Vue
Raw Normal View History

2024-05-29 17:58:57 +07:00
<script setup lang="ts">
import { ref, onMounted, reactive } from "vue";
import { useQuasar } from "quasar";
import { useRouter, useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
/** importType*/
import type { QTableProps } from "quasar";
import type {
ResGroup,
ResLevel,
} from "@/modules/01_metadata/interface/response/positionEmployee/Main";
import type { DataGroup } from "@/modules/01_metadata/interface/index/positionEmployee";
2024-05-29 17:58:57 +07:00
import type { FormDataLevel } from "@/modules/01_metadata/interface/request/positionEmployee";
/** importComponts*/
import DialogHeader from "@/components/DialogHeader.vue";
/** importStore*/
import { useMainOptionDataStore } from "@/modules/01_metadata/stores/main";
import { useCounterMixin } from "@/stores/mixin";
/**use*/
const $q = useQuasar();
const storeOption = useMainOptionDataStore();
2024-05-29 17:58:57 +07:00
const route = useRoute();
const router = useRouter();
const { dialogConfirm, showLoader, hideLoader, messageError, success } =
useCounterMixin();
2024-05-29 17:58:57 +07:00
// Table
const rows = ref<DataGroup[]>([]); // รายการกลุ่มงาน
const filter = ref<string>(""); // คำค้นหา
2024-05-29 17:58:57 +07:00
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px; width:0px",
style: "font-size: 14px",
},
{
name: "posLevelName",
align: "left",
label: "ระดับชั้นงาน",
sortable: true,
field: "posLevelName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posTypeName",
align: "left",
label: "ระดับชั้นงาน",
2024-05-29 17:58:57 +07:00
sortable: true,
field: "posTypeName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevelAuthority",
align: "left",
label: "ผู้มีอำนาจสั่งบรรจุ",
sortable: true,
field: "posLevelAuthority",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const visibleColumns = ref<string[]>([
"no",
"posLevelName",
"posTypeName",
"posLevelAuthority",
]);
const posTypeId = ref<string>(route.params.id.toString()); // id กลุ่มงาน
const titleName = ref<string | null>(""); // ชื่อกลุ่มงาน
const levelId = ref<string>(""); // id ระดับชั้นงานที่จะแก้ไข
const isStatusEdit = ref<boolean>(false); // สถานะแก่ไขข้อมูล
const modalDialog = ref<boolean>(false); // popup
// ฟอร์มระดับชั้นงาน
2024-05-29 17:58:57 +07:00
const formDataLevel = reactive<FormDataLevel>({
posLevelName: null,
posTypeName: "",
posLevelAuthority: "",
});
/**
* งกนดงขอมลรายการระดบชนงาน API
*
* เกบขอมลรรายการระดบชนงานไวใน rows.value
*/
async function fetchData() {
2024-05-29 17:58:57 +07:00
showLoader();
await http
.get(config.API.orgEmployeeTypeById(posTypeId.value))
.then(async (res) => {
2024-05-29 17:58:57 +07:00
titleName.value = res.data.result.posTypeName ?? null;
formDataLevel.posTypeName = res.data.result.posTypeName;
rows.value = await res.data.result.posLevels.map((x: ResLevel) => ({
2024-05-29 17:58:57 +07:00
...x,
posTypeName: res.data.result.posTypeName,
}));
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* งกนเป popup แกไขขอมลระดบชนงาน
* @param data อมลระดบชนงานทจะแกไข
*
* กำหนด isStatusEdit เป true และกำหนดให ฟอรมขอมลระดบชนงาน เป อมลทจะแกไข
*
*/
function onClickOpenDialog(
statusEdit: boolean = false,
data: DataGroup = {} as DataGroup
) {
2024-05-29 17:58:57 +07:00
isStatusEdit.value = statusEdit;
modalDialog.value = true;
if (statusEdit) {
levelId.value = data.id;
formDataLevel.posLevelName = data.posLevelName;
formDataLevel.posTypeName = titleName.value;
formDataLevel.posLevelAuthority = data.posLevelAuthority;
} else {
formDataLevel.posTypeName = titleName.value ? titleName.value : "";
}
}
/**
* งกนป popup แกไขหรอเพมขอมลระดบชนงาน
*
* และกำหนดให ฟอรมขอมลระดบชนงาน เปนคาวาง
*/
2024-05-29 17:58:57 +07:00
function onClickCloseDialog() {
modalDialog.value = false;
formDataLevel.posLevelName = null;
formDataLevel.posTypeName = "";
formDataLevel.posLevelAuthority = "";
}
/**
* นยนการบนทกขอมลรายการระดบชนงาน
*
* dialogStatus เป 'false' จะทำการเพมขอมลรายการระดบชนงาน าไมจะทำการแกไขขอม
* เมอบนทกขอมลเสรจจะเรยก function fetchData() เพอดงขอมลรายการระดบชนงานใหม
*
*/
function onSubmit() {
dialogConfirm($q, async () => {
showLoader();
const body = {
posLevelName: Number(formDataLevel.posLevelName),
posTypeId: posTypeId.value,
posLevelRank: Number(formDataLevel.posLevelName),
posLevelAuthority: formDataLevel.posLevelAuthority,
};
// กำหนด Phat APi
2024-05-29 17:58:57 +07:00
const url = !isStatusEdit.value
? config.API.orgEmployeelevel
: config.API.orgEmployeelevelById(levelId.value);
await http[!isStatusEdit.value ? "post" : "put"](url, body)
.then(async () => {
await fetchData();
success($q, "บันทีกข้อมูลสำเร็จ");
onClickCloseDialog();
2024-05-29 17:58:57 +07:00
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
2024-05-29 17:58:57 +07:00
});
});
}
/**
* งกนแปลงตำแหนงผอำนาจ
* @param val าของผอำนาจ
* @returns ตำแหนงผอำนาจ
*/
2024-05-29 17:58:57 +07:00
function convertPosLevelAuthority(val: string) {
const result = storeOption.posLevelAuthorityOption.find((e) => e.id === val);
return result?.label;
}
/**
* hook ทำงานเม Components กเรยกใชงาน
*
* าม posTypeId จะดงขอมลรายการระดบชนงาน
*/
2024-05-29 17:58:57 +07:00
onMounted(() => {
posTypeId.value && fetchData();
});
</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)"
/>
รายการระดบชนงาน{{ titleName }}
</div>
<q-card flat bordered>
<div class="q-pa-md">
<q-toolbar style="padding: 0">
<q-btn
flat
round
color="primary"
icon="add"
@click.stop.pervent="onClickOpenDialog()"
>
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-input outlined dense v-model="filter" label="ค้นหา"></q-input>
<q-select
v-model="visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="columns"
option-value="name"
2024-11-05 16:45:53 +07:00
style="min-width: 140px"
2024-05-29 17:58:57 +07:00
/>
</div>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="rows"
:filter="filter"
row-key="name"
flat
bordered
:paging="true"
dense
class="custom-header-table"
:visible-columns="visibleColumns"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th auto-width />
2024-05-29 17:58:57 +07:00
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-bold">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
2024-08-20 17:21:12 +07:00
<q-tr :props="props">
2024-05-29 17:58:57 +07:00
<q-td auto-width>
<q-btn
color="edit"
flat
dense
round
class="q-mr-xs"
icon="edit"
@click.stop.pervent="onClickOpenDialog(true, props.row)"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
</q-td>
<q-td v-for="(col, index) in props.cols" :key="col.id">
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else-if="col.name === 'posLevelAuthority'">
{{ col.value ? convertPosLevelAuthority(col.value) : "-" }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
2024-05-29 17:58:57 +07:00
</q-tr>
</template>
</d-table>
</div>
</q-card>
<q-dialog v-model="modalDialog" class="dialog" persistent>
<q-card style="width: 350px">
<q-form greedy @submit.prevent @validation-success="onSubmit">
2024-05-29 17:58:57 +07:00
<q-card-section class="flex justify-between" style="padding: 0">
<DialogHeader
:tittle="isStatusEdit ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
:close="onClickCloseDialog"
/>
</q-card-section>
<q-separator />
2024-05-29 17:58:57 +07:00
<q-card-section class="row q-gutter-y-md">
<div class="col-12">
<q-input
outlined
ref="posLevelNameRef"
v-model="formDataLevel.posLevelName"
label="ระดับชั้นงาน"
dense
lazy-rules
borderless
bg-color="white"
hide-bottom-space
mask="#"
reverse-fill-mask
:rules="[(val:string) => !!val || 'กรุณากรอกระดับชั้นงาน']"
class="inputgreen"
2024-05-29 17:58:57 +07:00
/>
</div>
<div class="col-12">
<q-select
ref="commanderRef"
outlined
v-model="formDataLevel.posLevelAuthority"
emit-value
map-options
:options="storeOption.posLevelAuthorityOption"
option-value="id"
label="ผู้มีอำนาจสั่งบรรจุ"
dense
lazy-rules
borderless
bg-color="white"
hide-bottom-space
:rules="[(val:string) => !!val || 'กรุณาเลือกผู้มีอำนาจสั่งบรรจุ']"
class="inputgreen"
2024-05-29 17:58:57 +07:00
/>
</div>
<div class="col-12">
<q-select
ref="posTypeIdRef"
v-model="formDataLevel.posTypeName"
label="ระดับชั้นงาน"
2024-05-29 17:58:57 +07:00
outlined
dense
bg-color="white"
2024-11-05 16:45:53 +07:00
2024-05-29 17:58:57 +07:00
hide-bottom-space
readonly
/>
</div>
</q-card-section>
<q-separator />
2024-05-29 17:58:57 +07:00
<q-card-actions align="right">
<q-btn id="onSubmit" type="submit" label="บันทึก" color="public">
2024-05-29 17:58:57 +07:00
<q-tooltip>นทกขอม</q-tooltip>
</q-btn>
</q-card-actions>
</q-form>
2024-05-29 17:58:57 +07:00
</q-card>
</q-dialog>
</template>
<style scoped></style>