hrms-admin/src/modules/02_users/views/03_permissionsView.vue

878 lines
29 KiB
Vue
Raw Normal View History

2024-05-31 16:42:25 +07:00
<script setup lang="ts">
import { ref, reactive, onMounted, watch } from "vue";
2024-05-31 16:42:25 +07:00
import { useQuasar } from "quasar";
2024-09-09 14:59:32 +07:00
2024-05-31 16:42:25 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-09 14:59:32 +07:00
import { usePermissionsStore } from "@/modules/02_users/stores/permissions";
import { useCounterMixin } from "@/stores/mixin";
2024-05-31 16:42:25 +07:00
/** importType*/
import type { QTableProps } from "quasar";
import type { Pagination } from "@/modules/02_users/interface/index/Main";
import type { FilterReqMaster } from "@/modules/02_users/interface/request/Main";
import type {
NodeTree,
PosMaster,
Position,
} from "@/modules/02_users/interface/response/Main";
2024-05-31 16:42:25 +07:00
2024-09-09 14:59:32 +07:00
/** importComponents*/
import DialogAdd from "@/modules/02_users/components/Permissions/DialogAdd.vue";
import PopupPersonal from "@/modules/02_users/components/RoleOrganization/DialogPersonal.vue";
2024-05-31 16:42:25 +07:00
2024-09-09 14:59:32 +07:00
/**
* use
*/
2024-05-31 16:42:25 +07:00
const $q = useQuasar();
const store = usePermissionsStore();
const { showLoader, hideLoader, messageError, success, dialogRemove } =
useCounterMixin();
2024-05-31 16:42:25 +07:00
/** Tree*/
2024-09-09 14:59:32 +07:00
const filter = ref<string>(""); // ค้นหาข้อมูลโครงาสร้าง
const nodes = ref<Array<NodeTree>>([
{
labelName: "",
orgCode: "",
orgLevel: 0,
orgName: "",
orgRevisionId: "",
orgRootName: "",
orgTreeCode: "",
orgTreeFax: "",
orgTreeId: "",
orgTreeName: "หน่วยงานทั้งหมด",
orgTreeOrder: 0,
orgTreePhoneEx: "",
orgTreePhoneIn: "",
orgTreeRank: "",
orgTreeRankSub: "",
orgTreeShortName: "",
responsibility: "",
totalPosition: 0,
totalPositionCurrentUse: 0,
totalPositionCurrentVacant: 0,
totalPositionNextUse: 0,
totalPositionNextVacant: 0,
totalRootPosition: 0,
totalRootPositionCurrentUse: 0,
totalRootPositionCurrentVacant: 0,
totalRootPositionNextUse: 0,
totalRootPositionNextVacant: 0,
children: [] as NodeTree[],
isOfficer: false,
},
]); // ข้อมูลโครงสร้าง
2024-05-31 16:42:25 +07:00
const lazy = ref(nodes);
2024-09-09 14:59:32 +07:00
const expanded = ref<string[]>([]); // แสดงข้อมูลในโหนดที่เลือก
const nodeId = ref<string>(""); // id โหนด
2024-05-31 16:42:25 +07:00
/** Table*/
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: (row) =>
(reqMaster.page - 1) * reqMaster.pageSize +
posMaster.value.indexOf(row) +
1,
2024-05-31 16:42:25 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posMasterNo",
align: "left",
label: "เลขที่ตำแหน่ง",
sortable: false,
field: (row) =>
row.orgShortname +
(row.posMasterNoPrefix ? row.posMasterNoPrefix : "") +
(row.posMasterNo ? row.posMasterNo : "") +
(row.posMasterNoSuffix ? row.posMasterNoSuffix : "") +
(row.isSit ? "(ทับที่)" : ""),
2024-05-31 16:42:25 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionName",
align: "left",
label: "ตำแหน่งในสายงาน",
field: (row) => (row.isSit ? row.profilePosition : row.positionName),
2024-05-31 16:42:25 +07:00
sortable: false,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posTypeName",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: false,
field: (row) => (row.isSit ? row.profilePostype : row.posTypeName),
2024-05-31 16:42:25 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevelName",
align: "left",
label: "ระดับตำแหน่ง",
sortable: false,
field: (row) => (row.isSit ? row.profilePoslevel : row.posLevelName),
2024-05-31 16:42:25 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionIsSelected",
align: "left",
label: "คนครอง",
sortable: false,
field: (row) =>
store.typeOrganizational === "draft" && row.fullNameNextHolder !== null
? row.fullNameNextHolder
: store.typeOrganizational !== "draft" &&
row.fullNameCurrentHolder !== null
? row.fullNameCurrentHolder
: "ว่าง",
2024-05-31 16:42:25 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "authRoleName",
align: "left",
2024-06-11 14:07:20 +07:00
label: "สิทธิ์",
sortable: false,
field: "authRoleName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2024-05-31 16:42:25 +07:00
]);
const columnsExpand = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionName",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
field: "positionName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionField",
align: "left",
label: "สายงาน",
sortable: true,
field: "positionField",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posTypeName",
align: "left",
label: "ประเภทตำเเหน่ง",
sortable: true,
field: "posTypeName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevelName",
align: "left",
label: "ระดับตำแหน่ง",
sortable: true,
field: "posLevelName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posExecutiveName",
align: "left",
label: "ตำแหน่งทางการบริหาร",
sortable: true,
field: "posExecutiveName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionExecutiveField",
align: "left",
label: "ด้านทางการบริหาร",
sortable: true,
field: "positionExecutiveField",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionArea",
align: "left",
label: "ด้าน/สาขา",
sortable: true,
field: "positionArea",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
2024-09-09 14:59:32 +07:00
// ฟอร์มค้นหาตำแหน่ง
const reqMaster = reactive<FilterReqMaster>({
id: null,
type: 0,
isAll: false,
isBlank: false,
page: 1,
pageSize: 10,
keyword: "",
revisionId: "",
});
const maxPage = ref<number>(0);
const totalRow = ref<number>(0);
2024-09-09 14:59:32 +07:00
const posMaster = ref<PosMaster[]>([]); // ข้อมูลรายการตำแหน่ง
const dataPosMaster = ref<PosMaster>(); // ข้อมูลตำแหน่ง
const pagination = ref<Pagination>({
page: reqMaster.page,
rowsPerPage: reqMaster.pageSize,
});
2024-09-09 14:59:32 +07:00
const modalDialogAdd = ref<boolean>(false); // popup จัดการสิทธิ์
2024-05-31 16:42:25 +07:00
2024-09-09 14:59:32 +07:00
/**
* function เรยกขอมลโครงสราง แบบปนและ แบบราง
*/
async function fetchOrganizationActive() {
showLoader();
await http
2024-05-31 16:42:25 +07:00
.get(config.API.activeOrganization)
2024-09-09 14:59:32 +07:00
.then(async (res) => {
2024-05-31 16:42:25 +07:00
const data = res.data.result;
if (data) {
store.activeId = data.activeId;
store.draftId = data.draftId;
const id =
store.typeOrganizational === "current"
? store.activeId
: store.draftId;
2024-09-09 14:59:32 +07:00
await fetchDataTree(id);
2024-05-31 16:42:25 +07:00
}
})
.catch((err) => {
messageError($q, err);
2024-09-09 14:59:32 +07:00
})
.finally(() => {
hideLoader();
2024-05-31 16:42:25 +07:00
});
}
/**
* function fetch อมลของ Tree
* @param id id โครงสราง
*/
2024-09-09 14:59:32 +07:00
async function fetchDataTree(id: string) {
2024-05-31 16:42:25 +07:00
showLoader();
2024-09-09 14:59:32 +07:00
await http
2024-05-31 16:42:25 +07:00
.get(config.API.orgByid(id.toString()))
2024-09-09 14:59:32 +07:00
.then(async (res) => {
const data = await res.data.result;
nodes.value.push(...data);
nodes.value[0].orgRevisionId = id;
await fetchDataTable(reqMaster.id, id, reqMaster.type);
2024-05-31 16:42:25 +07:00
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* function fetch อรายการตำแหน
* @param id idTree
* @param level levelTree
*/
async function fetchDataTable(
id: string | null,
revisionId: string,
level: number
) {
showLoader();
reqMaster.id = id === "" ? null : id;
reqMaster.revisionId = revisionId;
reqMaster.type = level;
2024-09-09 14:59:32 +07:00
await http
.post(config.API.orgPosMasterList, reqMaster)
.then(async (res) => {
posMaster.value = [];
const dataMain: PosMaster[] = [];
maxPage.value = Math.ceil(res.data.result.total / reqMaster.pageSize);
totalRow.value = res.data.result.total;
2024-09-09 14:59:32 +07:00
await res.data.result.data.forEach((e: PosMaster) => {
const p = e.positions;
if (p.length !== 0) {
const a = p.find((el: Position) => el.positionIsSelected === true);
const { id, ...rest } = a ? a : p[0];
const pos = { ...e, ...rest };
dataMain.push(pos);
}
});
posMaster.value = dataMain;
})
.catch((err) => {
messageError($q, err);
posMaster.value = [];
})
.finally(() => {
hideLoader();
});
}
/**
* function เลอกขอมลโครางสราง
* @param data
*/
function updateSelected(data: NodeTree) {
2024-05-31 16:42:25 +07:00
nodeId.value = data.orgTreeId;
fetchDataTable(data.orgTreeId, data.orgRevisionId, data.orgLevel);
}
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: Pagination) {
reqMaster.pageSize = newPagination.rowsPerPage;
reqMaster.page = 1;
2024-05-31 16:42:25 +07:00
}
function onClickAddRole(data: PosMaster) {
modalDialogAdd.value = true;
dataPosMaster.value = data;
}
2024-09-09 14:59:32 +07:00
/**
* นยนการลบสทธ
* @param id ตำแหน
*/
function onDeleteRole(id: string) {
dialogRemove(
$q,
() => {
showLoader();
http
.post(config.API.managementPermission, {
authRoleId: "",
posMasterId: id,
})
.then(async () => {
await fetchDataTable(
reqMaster.id,
reqMaster.revisionId,
reqMaster.type
);
2024-09-09 14:59:32 +07:00
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการลบสิทธิ์",
"ต้องการยืนยันการลบสิทธิ์นี้หรือไม่ ?"
);
}
const modalPersonal = ref<boolean>(false);
const personId = ref<string>("");
function onOpenModalPersonal(id: string) {
personId.value = id;
modalPersonal.value = true;
}
function updatemodalPersonal(modal: boolean) {
modalPersonal.value = modal;
}
/** callblck function ทำการ fetch ข้อมูล tree เมื่อมีการเปลี่ยน Tab ปัจจับัน,แบบร่าง*/
watch(
() => store.typeOrganizational,
async () => {
const id =
store.typeOrganizational === "current" ? store.activeId : store.draftId;
nodeId.value = "";
posMaster.value = [];
reqMaster.id = null;
reqMaster.type = 0;
reqMaster.isAll = false;
reqMaster.page = 1;
reqMaster.pageSize = 10;
reqMaster.keyword = "";
reqMaster.revisionId = "";
await fetchDataTree(id);
}
);
/** callblck function ทำการ fetch ข้อมูล Table เมื่อมีการเปลี่ยนหน้า*/
watch([() => reqMaster.pageSize], () => {
fetchDataTable(reqMaster.id, reqMaster.revisionId, reqMaster.type);
});
/** callblck function ทำการ fetch ข้อมูล Table เมื่อมีการเปลี่ยนจำนวนต่อแแแถว*/
watch(
() => [reqMaster.isAll, reqMaster.isBlank],
() => {
reqMaster.page = 1;
reqMaster.id &&
fetchDataTable(reqMaster.id, reqMaster.revisionId, reqMaster.type);
}
);
2024-05-31 16:42:25 +07:00
onMounted(() => {
fetchOrganizationActive();
});
</script>
<template>
<div class="row items-center">
2024-06-11 14:07:20 +07:00
<div class="toptitle text-dark row items-center q-py-xs">กำหนดสทธ</div>
2024-05-31 16:42:25 +07:00
</div>
<q-card flast bordered>
<q-card-section>
<q-toolbar class="q-gutter-md items-center" style="padding: 0px">
<q-btn-group outline>
<q-btn
dense
class="q-px-md"
:outline="store.typeOrganizational === 'current' ? false : true"
color="blue"
label="ปัจจุบัน"
:disable="store.activeId == '' || store.activeId == null"
@click="store.typeOrganizational = 'current'"
/>
<q-btn
dense
class="q-px-md"
:outline="store.typeOrganizational === 'draft' ? false : true"
color="blue"
label="แบบร่าง"
:disable="store.draftId == '' || store.draftId == null"
@click="store.typeOrganizational = 'draft'"
/>
</q-btn-group>
2024-11-21 18:05:31 +07:00
<div
v-if="store.typeOrganizational === 'draft'"
class="q-pl-sm text-red"
>
*ทธกำหนดในแบบรางจะใชงานไดเมอเผยแพรโครงสรางเปนปจจนแลวเทาน
</div>
2024-05-31 16:42:25 +07:00
</q-toolbar>
</q-card-section>
<q-separator />
<q-card-section style="padding: 0px">
<div class="col-12">
<q-card bordered class="col-12 row caedNone">
<!-- Tree -->
<div class="col-xs-12 col-sm-3 row">
<div class="col-12 row no-wrap bg-grey-1">
<div class="col-12 q-py-sm q-px-sm">
<div class="q-gutter-sm">
<div class="row q-col-gutter-sm q-pl-sm">
<div class="col-12">
<q-input dense outlined v-model="filter" label="ค้นหา">
<template v-slot:append>
<q-icon
v-if="filter !== ''"
name="clear"
class="cursor-pointer"
@click="filter = ''"
/>
<q-icon name="search" color="grey-5" />
</template>
</q-input>
</div>
</div>
<div class="bg-white tree-container q-pa-xs">
<q-tree
class="q-pa-sm q-gutter-sm"
dense
default-expand-all
:nodes="lazy"
node-key="orgTreeId"
label-key="labelName"
:filter="filter"
no-results-label="ไม่พบข้อมูลที่ค้นหา"
no-nodes-label="ไม่มีข้อมูล"
v-model:expanded="expanded"
>
<template v-slot:default-header="prop">
<q-item
@click.stop="updateSelected(prop.node)"
:active="nodeId == prop.node.orgTreeId"
clickable
active-class="my-list-link text-primary text-weight-medium"
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
>
<div>
2024-10-28 17:04:55 +07:00
<div
:class="
prop.node.isOfficer
? 'text-weight-medium text-blue'
: 'text-weight-medium'
"
>
<div
v-if="
prop.node.isDeputy == true &&
prop.node.orgLevel == 0
"
class="text-info"
>
{{ prop.node.orgTreeName }}
</div>
<div v-else>
{{ prop.node.orgTreeName }}
</div>
{{ prop.node.isOfficer ? "(สกจ.)" : "" }}
2024-05-31 16:42:25 +07:00
</div>
<div class="text-weight-light text-grey-8">
{{
prop.node.orgCode == null
? null
: prop.node.orgCode
}}
{{
prop.node.orgTreeShortName == null
? null
: prop.node.orgTreeShortName
}}
</div>
</div>
</q-item>
</template>
</q-tree>
</div>
</div>
</div>
</div>
<div class="col-12 row">
<q-separator :vertical="!$q.screen.lt.md" />
</div>
</div>
<!-- TOOLBAR -->
2024-05-31 16:42:25 +07:00
<div class="col-xs-12 col-sm-9 q-pa-md row">
<div class="col-12">
<q-toolbar style="padding: 0">
<q-space />
<div class="row q-gutter-md">
<div>
<q-checkbox
keep-color
v-model="reqMaster.isBlank"
label="แสดงเฉพาะตำแหน่งว่าง"
color="primary"
>
<q-tooltip>แสดงเฉพาะตำแหนงวาง</q-tooltip>
</q-checkbox>
</div>
<div>
<q-checkbox
keep-color
v-model="reqMaster.isAll"
label="แสดงตำแหน่งทั้งหมด"
color="primary"
>
<q-tooltip
>แสดงตำแหนงทงหมดภายใตหนวยงาน/วนราชการทเลอก</q-tooltip
2024-05-31 16:42:25 +07:00
>
</q-checkbox>
</div>
<div>
<q-input
outlined
dense
v-model="reqMaster.keyword"
label="ค้นหา"
@keydown.enter.prevent="
(reqMaster.page = 1),
fetchDataTable(
reqMaster.id,
reqMaster.revisionId,
reqMaster.type
)
"
>
<template v-slot:append>
<q-icon name="search" color="grey-5" />
</template>
</q-input>
</div>
</div>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="posMaster"
:paging="true"
row-key="id"
flat
bordered
dense
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
v-model:pagination="pagination"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th auto-width></q-th>
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width></q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td>
<q-btn
flat
size="14px"
color="primary"
round
dense
@click="props.expand = !props.expand"
:icon="
props.expand ? 'mdi-menu-down' : 'mdi-menu-right'
"
/>
</q-td>
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name === 'positionIsSelected'">
{{ col.value ? col.value : "-" }}
<q-btn
v-if="col.value !== 'ว่าง'"
flat
dense
color="info"
icon="info"
round
@click.prevent="
onOpenModalPersonal(
store.typeOrganizational === 'draft'
? props.row.profileIdNextHolder
: props.row.profileIdCurrentHolder
)
"
>
<q-tooltip>อม</q-tooltip>
</q-btn>
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
<q-td>
<q-btn
flat
dense
icon="mdi-dots-vertical"
class="q-pa-none q-ml-xs"
color="grey-13"
size="12px"
>
<q-menu>
<q-list dense style="min-width: 150px">
<q-item
clickable
v-close-popup
@click="onClickAddRole(props.row)"
>
<q-item-section>
<div class="row items-center">
<q-icon
color="blue-9"
size="17px"
name="mdi-account-group"
/>
2024-06-11 14:07:20 +07:00
<div class="q-pl-md">กำหนดสทธ</div>
</div>
</q-item-section>
</q-item>
</q-list>
<q-list dense style="min-width: 150px">
<q-item
clickable
v-close-popup
@click="onDeleteRole(props.row.id)"
>
<q-item-section>
<div class="row items-center">
<q-icon
color="red"
size="17px"
name="delete"
/>
<div class="q-pl-md">ลบสทธ</div>
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
</q-tr>
<q-tr v-show="props.expand" :props="props">
<q-td colspan="100%" class="bg-grey-1">
<q-card flat bordered class="text-left q-ma-sm">
<d-table
2024-05-31 16:42:25 +07:00
flat
:columns="columnsExpand"
:rows="props.row.positions"
table-class="text-grey-9"
row-key="id"
2024-05-31 16:42:25 +07:00
dense
hide-bottom
bordered
separator="vertical"
class="custom-header-table-expand"
2024-05-31 16:42:25 +07:00
>
<template v-slot:header="props">
<q-tr :props="props" class="bg-grey-2">
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
2024-05-31 16:42:25 +07:00
>
<span class="q-px-sm text-body2 text-black">{{
col.label
}}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
2024-05-31 16:42:25 +07:00
>
<div v-if="col.name == 'no'" class="text-body2">
{{ props.rowIndex + 1 }}
</div>
<div
v-else-if="col.name === 'posExecutiveName'"
class="text-body2"
2024-05-31 16:42:25 +07:00
>
{{ col.value ? col.value : "-" }}
</div>
2024-05-31 16:42:25 +07:00
<div
v-else-if="
col.name === 'positionExecutiveField'
"
class="text-body2"
>
{{ col.value ? col.value : "-" }}
</div>
2024-05-31 16:42:25 +07:00
<div
v-else-if="col.name === 'positionArea'"
class="text-body2"
>
{{ col.value ? col.value : "-" }}
</div>
2024-05-31 16:42:25 +07:00
<div v-else class="text-body2">
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</q-card>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
งหมด {{ totalRow }} รายการ
<q-pagination
v-model="reqMaster.page"
active-color="primary"
color="dark"
:max="maxPage"
:max-pages="5"
size="sm"
boundary-links
direction-links
@update:model-value="
fetchDataTable(
reqMaster.id,
reqMaster.revisionId,
reqMaster.type
)
"
></q-pagination>
</template>
</d-table>
2024-05-31 16:42:25 +07:00
</div>
</div>
</q-card>
</div>
</q-card-section>
</q-card>
<DialogAdd
v-model:modal="modalDialogAdd"
v-model:reqMaster="reqMaster"
:dataPosMaster="dataPosMaster as PosMaster"
:fetchDataTable="fetchDataTable"
/>
<PopupPersonal
:modal="modalPersonal"
:id="personId"
@update:modal="updatemodalPersonal"
/>
2024-05-31 16:42:25 +07:00
</template>
<style scoped>
.tree-container {
overflow: auto;
height: 70vh;
border: 1px solid #e6e6e7;
border-radius: 10px;
}
.my-list-link {
color: rgb(118, 168, 222);
border-radius: 5px;
background: #a3d3fb48 !important;
font-weight: 600;
border: 1px solid rgba(175, 185, 196, 0.217);
}
</style>