hrms-mgt/src/modules/08_registryEmployee/views/Main.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 0612820928 ปรับ UI
2024-11-22 18:04:12 +07:00

533 lines
16 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { checkPermission } from "@/utils/permissions";
import { useCounterMixin } from "@/stores/mixin";
import { useRegistryEmp } from "@/modules/08_registryEmployee/stores/registry-employee";
import http from "@/plugins/http";
import config from "@/app.config";
/** importType*/
import type { QInput, QTableProps } from "quasar";
import type {
NewPagination,
DataOption,
} from "@/modules/08_registryEmployee/interface/index/Main";
import type { DataEmployee } from "@/modules/08_registryEmployee/interface/response/Employee";
/** importComponents*/
import DialogAddEmployee from "@/modules/08_registryEmployee/components/DialogAddEmployee.vue"; //เพิ่มข้อมูลลูกจ้างชั่วคราว
import DialogSelectPos from "@/modules/08_registryEmployee/components/DialogSelectPos.vue"; //เลือกหน่วยงานที่รับบรรจุ
import DialogSendOrder from "@/modules/08_registryEmployee/components/DialogSendOrder.vue"; //ส่งรายชื่อไปออกคำสั่ง
const $q = useQuasar();
const router = useRouter();
const {
success,
messageError,
showLoader,
hideLoader,
date2Thai,
dialogRemove,
} = useCounterMixin();
const { statusText } = useRegistryEmp();
const modalAddEmployee = ref<boolean>(false); // popup เพิ่มข้อมูลลูกจ้างชั่วคราว
const modalPos = ref<boolean>(false); //popup กำหนดตำแหน่ง
const modalSendOrder = ref<boolean>(false); //popup ส่งไปออกคำสั่ง
const dataRow = ref<DataEmployee>(); //ข้อมูลรายชื่อลูกจ้างชั่วคราวที่ต้องการกำหนดตำแหน่ง
/** Table*/
const rows = ref<DataEmployee[]>([]); //รายชื่อลูกจ้างชั่วคราว
const maxPage = ref<number>(0); //จำนวนหน้า
const total = ref<number>(0); //จำนวนข้อมูล
const queryParams = reactive({
page: 1,
pageSize: 10,
type: "temp",
searchField: "fullName",
searchKeyword: "",
});
//ประเภทการค้นหา
const searchTypeOption = ref<DataOption[]>([
{ id: "fullName", name: "ชื่อ-นามสกุล" },
{ id: "citizenId", name: "เลขประจำตัวประชาชน" },
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: (row) =>
(queryParams.page - 1) * queryParams.pageSize +
rows.value.indexOf(row) +
1,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "citizenId",
align: "left",
label: "เลขประจำตัวประชาชน",
sortable: true,
field: "citizenId",
headerStyle: "font-size: 14px; min-width: 200px",
style: "font-size: 14px; ",
},
{
name: "fullname",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: (row) => `${row.prefix}${row.firstName} ${row.lastName}`,
headerStyle: "font-size: 14px; min-width: 200px",
style: "font-size: 14px; ",
},
{
name: "draftOrganizationOrganization",
align: "left",
label: "หน่วยงานที่รับการบรรจุ",
sortable: true,
field: "draftOrganizationOrganization",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "draftPositionEmployee",
align: "left",
label: "หน่วยงานที่บรรจุ",
sortable: true,
field: "draftPositionEmployee",
headerStyle: "font-size: 14px; min-width: 200px",
style: "font-size: 14px; ",
},
{
name: "govAge",
align: "left",
label: "อายุราชการ(ปี)",
sortable: true,
field: "govAge",
format(val) {
return val;
},
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "dateEmployment",
align: "left",
label: "วันที่จ้าง",
sortable: true,
field: "dateEmployment",
format: (val) => date2Thai(val),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "dateAppoint",
align: "left",
label: "วันที่แต่งตั้ง",
sortable: true,
field: "dateAppoint",
headerStyle: "font-size: 14px",
format: (val) => date2Thai(val),
style: "font-size: 14px",
},
{
name: "age",
align: "left",
label: "อายุ",
sortable: true,
field: "age",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "createdAt",
align: "left",
label: "วันที่สร้าง",
sortable: true,
field: "createdAt",
format(val) {
return date2Thai(val);
},
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "dateRetireLaw",
align: "left",
label: "วันที่พ้นราชการ",
sortable: true,
field: "dateRetireLaw",
format(val) {
return date2Thai(val);
},
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "statustext",
align: "left",
label: "สถานะ",
sortable: true,
field: (row) => statusText(row.draftOrgEmployeeStatus),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const visibleColumns = ref<String[]>([
"no",
"citizenId",
"fullname",
"draftOrganizationOrganization",
"draftPositionEmployee",
"govAge",
"dateEmployment",
"age",
"createdAt",
"dateRetireLaw",
"statustext",
"dateAppoint",
]);
/**
* ฟังก์ชันดึงข้อมูลรายชื่อลูกจ้างชั่วคราว
*/
async function fetchList() {
showLoader();
await http
.get(config.API.registryNew("-temp"), { params: queryParams })
.then(async (res) => {
rows.value = await res.data.result.data;
maxPage.value = Math.ceil(res.data.result.total / queryParams.pageSize);
total.value = res.data.result.total;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* ฟังก์ชันลบข้อมูลรายชื่อลูกจ้างชั่วคราว
* @param id รายชื่อลูกจ้างชั่วคราวที่ต้องการลบ
*/
function onClickDelete(id: string) {
dialogRemove($q, async () => {
showLoader();
await http
.delete(config.API.registryNew("-employee") + `/${id}`)
.then(async () => {
await fetchList();
await success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
}
/**
* ฟังก์ชันดูข้อมูลรายชื่อลูกจ้างชั่วคราว ไปยัง ทะเบียนประวัติลูกจ้างชั่วคราว
* @param id รายชื่อลูกจ้างชั่วคราวที่ต้องการ
*/
function redirectToPageDetail(id: string) {
router.push(`/registry-temp/${id}`);
}
/**
* ฟังก์ชันเปิด popup เพิ่มข้อมูลลูกจ้างชั่วคราว
*/
function onClickAddEmployee() {
modalAddEmployee.value = true;
}
/**
* ฟังก์ชันเปิด popup เลือกหน่วยงานที่รับบรรจุ
*/
function onClickSelectPos(data: DataEmployee) {
modalPos.value = true;
dataRow.value = data;
}
/**
* ฟังก์ชันเปิด popup ส่งรายชื่อไปออกคำสั่ง
*/
function onClickSendOrder() {
modalSendOrder.value = true;
}
/**
* function updatePagination
* @param newPagination ข้อมูล Pagination ใหม่
*/
function updatePagination(newPagination: NewPagination) {
queryParams.page = 1;
queryParams.pageSize = newPagination.rowsPerPage;
}
/**
* ทำงานเมื่อมีการเปลี่่ยนจำนวนข้อมูลต่อหน้า
*/
watch(
() => queryParams.pageSize,
() => {
fetchList();
}
);
/**
* ทำงานเมื่อมีการเรียกใข้ Components
*/
onMounted(async () => {
await fetchList();
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
รายชอลกจางชวคราว
</div>
<q-card flat bordered class="q-pa-md">
<div class="col-12 row items-center">
<q-btn
v-if="checkPermission($route)?.attrIsCreate"
flat
round
color="primary"
icon="mdi-plus"
@click="onClickAddEmployee"
>
<q-tooltip>เพิ่มข้อมูล</q-tooltip>
</q-btn>
<q-btn
v-if="checkPermission($route)?.attrIsUpdate"
flat
round
color="primary"
icon="mdi-account-arrow-right"
@click="onClickSendOrder"
>
<q-tooltip>ส่งรายชื่อไปออกคำสั่ง</q-tooltip>
</q-btn>
<q-space />
<div class="items-center" style="display: flex">
<q-select
outlined
v-model="queryParams.searchField"
:options="searchTypeOption"
emit-value
dense
emit-option
option-label="name"
option-value="id"
map-options
/>
<!-- ค้นหาข้อความใน table -->
<q-input
standout
dense
v-model="queryParams.searchKeyword"
ref="filterRef"
outlined
placeholder="ค้นหา"
style="max-width: 200px"
class="q-ml-sm"
@keydown.enter.prevent="(queryParams.page = 1), fetchList()"
>
<template v-slot:append>
<q-icon v-if="queryParams.searchKeyword == ''" name="search" />
<q-icon
v-if="queryParams.searchKeyword !== ''"
name="clear"
class="cursor-pointer"
@click="
(queryParams.searchKeyword = ''),
(queryParams.page = 1),
fetchList()
"
/>
</template>
</q-input>
<!-- แสดงคอลัมน์ใน table -->
<q-select
v-model="visibleColumns"
:display-value="$q.lang.table.columns"
multiple
outlined
dense
:options="columns"
options-dense
option-value="name"
map-options
emit-value
style="min-width: 140px"
class="gt-xs q-ml-sm"
/>
</div>
</div>
<div class="col-12 q-pt-sm">
<d-table
:rows="rows"
:columns="columns"
:visible-columns="visibleColumns"
row-key="id"
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th
auto-width
v-if="
checkPermission($route)?.attrIsDelete ||
checkPermission($route)?.attrIsUpdate
"
/>
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td
auto-width
v-if="
checkPermission($route)?.attrIsDelete ||
checkPermission($route)?.attrIsUpdate
"
>
<q-btn
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
:disable="
props.row.draftOrgEmployeeStatus !== null &&
props.row.draftOrgEmployeeStatus !== 'WAITTING' &&
props.row.draftOrgEmployeeStatus !== 'PENDING'
"
flat
round
dense
:color="
props.row.draftOrgEmployeeStatus !== null &&
props.row.draftOrgEmployeeStatus !== 'WAITTING' &&
props.row.draftOrgEmployeeStatus !== 'PENDING'
? 'grey-5'
: 'blue'
"
icon="mdi-account-settings"
@click.pervent="onClickSelectPos(props.row)"
>
<q-tooltip>กำหนดตำแหน่ง </q-tooltip>
</q-btn>
<q-btn
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
flat
round
dense
color="edit"
icon="edit"
@click.pervent="redirectToPageDetail(props.row.id)"
>
<q-tooltip>แก้ไขข้อมูล </q-tooltip>
</q-btn>
<q-btn
v-if="checkPermission($route)?.attrIsDelete"
flat
round
dense
color="red"
icon="mdi-delete"
@click.pervent="onClickDelete(props.row.id)"
>
<q-tooltip>ลบ </q-tooltip>
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<template v-if="col.name === 'draftOrganizationOrganization'">
<div
v-if="
props.row.orgName !== null ||
props.row.positionPath !== null
"
>
<div class="col-4">
<div class="text-weight-medium">
{{ props.row.root !== null ? props.row.root : "-" }}
{{
props.row.rootShortName !== null
? `(${props.row.rootShortName})`
: ""
}}
</div>
<div class="text-weight-light">
{{
props.row.nodeName !== null ? props.row.nodeName : ""
}}
{{
props.row.nodeShortName !== null
? `(${props.row.nodeShortName}${props.row.posNo})`
: ""
}}
</div>
</div>
</div>
<div v-else>
<div class="col-4">
<div class="text-weight-medium">-</div>
</div>
</div>
</template>
<div v-else>
{{ col.value !== null && col.value !== "" ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
ทั้งหมด {{ total }} รายการ
<q-pagination
v-model="queryParams.page"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchList"
></q-pagination>
</template>
</d-table>
</div>
</q-card>
<DialogAddEmployee v-model:modal="modalAddEmployee" :fetch-data="fetchList" />
<DialogSelectPos
v-model:modal="modalPos"
:data-row="dataRow"
:fetch-data="fetchList"
/>
<DialogSendOrder v-model:modal="modalSendOrder" :fetch-data="fetchList" />
</template>