504 lines
18 KiB
Vue
504 lines
18 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, reactive, watch } from "vue";
|
|
import { useQuasar } from "quasar";
|
|
import { storeToRefs } from "pinia";
|
|
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
import { useDataStoreUser } from "@/modules/02_users/stores/main";
|
|
import { tokenParsed } from "@/plugins/auth";
|
|
import { usekeycloakPosition } from "@/stores/keycloakPosition";
|
|
|
|
import type { QTableProps } from "quasar";
|
|
import type {
|
|
DataTree,
|
|
DataProfile,
|
|
Pagination,
|
|
} from "@/modules/02_users/interface/index/Main";
|
|
import type { QueryProfile } from "@/modules/02_users/interface/request/Main";
|
|
|
|
import DialogAddPerson from "@/modules/02_users/components/RoleOrganization/DialogAddPerson.vue";
|
|
import PopupPersonal from "@/modules/02_users/components/RoleOrganization/DialogPersonal.vue";
|
|
|
|
const $q = useQuasar();
|
|
const store = useDataStoreUser();
|
|
const { dataPosition } = storeToRefs(usekeycloakPosition());
|
|
const { showLoader, hideLoader, messageError, success, dialogRemove } =
|
|
useCounterMixin();
|
|
|
|
/******* โครงสร้าง *******/
|
|
const filter = ref<string>(""); // ค้นหาข้อมูลรายการโครงสร้าง
|
|
const nodeTree = ref<DataTree[]>([
|
|
{
|
|
ancestorDNA: "",
|
|
createdAt: "",
|
|
createdFullName: "",
|
|
createdUserId: "",
|
|
id: "",
|
|
lastUpdateFullName: "",
|
|
lastUpdateUserId: "",
|
|
lastUpdatedAt: "",
|
|
orgRevisionId: "",
|
|
orgRootCode: "",
|
|
orgRootFax: "",
|
|
orgRootName: "หน่วยงานทั้งหมด",
|
|
orgRootOrder: 0,
|
|
orgRootPhoneEx: "",
|
|
orgRootPhoneIn: "",
|
|
orgRootRank: "",
|
|
orgRootRankSub: "",
|
|
orgRootShortName: "",
|
|
responsibility: "",
|
|
isDeputy: false,
|
|
labelName: "หน่วยงานทั้งหมด",
|
|
},
|
|
]); // ข้อมูลรายการโครงสร้าง
|
|
const expanded = ref<Array<string>>([]); // เปิดรายการโครงสร้าง
|
|
const orgId = ref<string>(""); // id หน่วยงานที่เลือก
|
|
const modalPersonal = ref<boolean>(false);
|
|
const personId = ref<string>("");
|
|
|
|
/**
|
|
* ฟังก์ชันดึงข้อมูลโครงสร้าง
|
|
* เก็บข้อมูลโครงสร้างไว้ใน nodeTree
|
|
*/
|
|
async function fetchOrg() {
|
|
const isSuperAdmin = tokenParsedData.value.includes("SUPER_ADMIN");
|
|
if (!isSuperAdmin) {
|
|
nodeTree.value = [];
|
|
}
|
|
|
|
showLoader();
|
|
await http
|
|
.get(config.API.permissionOrg)
|
|
.then(async (res) => {
|
|
const data = await res.data.result;
|
|
|
|
nodeTree.value.push(...data);
|
|
|
|
if (data.length === 1) {
|
|
selectedOrg(data[0].id);
|
|
} else if (data.length > 1) {
|
|
await fetchListPerson(); // ดึงข้อมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันเลือกหน่วยงาน
|
|
* @param id หน่วยงานที่เลือก
|
|
* กำหนดค่าของ qureyBody ให้เป็นค่า defult และกำหนดค่าของ qureyBody.id เป็นหน่วยงานที่เลือก
|
|
* และดึงข้อมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้างในหน่วยงานที่เลือก
|
|
*/
|
|
function selectedOrg(id: string) {
|
|
orgId.value = id;
|
|
qureyBody.id = id === "" ? null : id;
|
|
qureyBody.searchKeyword = "";
|
|
qureyBody.searchField = "fullName";
|
|
qureyBody.page = 1;
|
|
fetchListPerson(true);
|
|
}
|
|
|
|
/******* รายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง *******/
|
|
const qureyBody = reactive<QueryProfile>({
|
|
searchKeyword: "", // คำค้นหา
|
|
searchField: "fullName", // field ที่ต้องการค้นหา
|
|
page: 1, // หน้า
|
|
pageSize: 10, // จำนวนที่ต้องการ
|
|
id: null, // หน่วยงานที่เลือก
|
|
});
|
|
const rows = ref<DataProfile[]>([]); // ข้อมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
const total = ref<number>(0); // จำนวนข้อมูลทั้งหมด
|
|
const maxPage = ref<number>(0); // จำนวนหน้า
|
|
const columns = ref<QTableProps["columns"]>([
|
|
{
|
|
name: "fullName",
|
|
align: "left",
|
|
label: "ชื่อ-นามสกุล",
|
|
sortable: true,
|
|
field: (row) => `${row.prefix}${row.firstName} ${row.lastName}`,
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
{
|
|
name: "orgNew",
|
|
align: "left",
|
|
label: "หน่วยงานที่รับผิดชอบ",
|
|
sortable: true,
|
|
field: "orgNew",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
]);
|
|
const visibleColumns = ref<string[]>(["fullName", "orgNew"]);
|
|
const modalAdd = ref<boolean>(false); // modal เพิ่มข้อมูลรายชื่อ
|
|
|
|
/**
|
|
* ฟังก์ชันดึงข้อมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
* @param newPage โหลดหน้าแรก ถ้าเป็บ true โหลดหน้าแรก false ให้โหลดหน้าปัจจุบัน
|
|
*
|
|
* เก็บมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้างไว่ใน rows.value
|
|
*/
|
|
async function fetchListPerson(newPage: boolean = false) {
|
|
qureyBody.page = newPage ? 1 : qureyBody.page;
|
|
showLoader();
|
|
await http
|
|
.post(config.API.permissionOrgProfile, qureyBody)
|
|
.then(async (res) => {
|
|
const data = await res.data.result;
|
|
maxPage.value = Math.ceil(data.total / qureyBody.pageSize); // คำนวนหาจำนวนหน้า
|
|
total.value = data.total; // จำนวนรายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
rows.value = data.data;
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันยืนยันการลบรายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
* @param id รายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
* ลบเสร็จจะโหลดข้อมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
*/
|
|
function onDeletePerson(id: string) {
|
|
dialogRemove($q, async () => {
|
|
showLoader();
|
|
await http
|
|
.delete(config.API.permissionOrg + `/${id}`)
|
|
.then(async () => {
|
|
// ถ้า maxPage.value ไม่เท่ากับ 1 ให้ โหลดข้อมูลรายชื่อคนที่มีสิทธิ์จัดการโครงสร้างหน้าปัจจุบัน
|
|
if (maxPage.value !== 1) {
|
|
// ถ้ามีแค่หนึ่งแถวในหน้าปัจจุบัน ให้ลด page ลง 1
|
|
if (rows.value.length === 1) {
|
|
qureyBody.page = qureyBody.page - 1;
|
|
}
|
|
await fetchListPerson(false); // โหลดข้อมูลจากหน้าปัจจุบันโดยไม่รีเซ็ต
|
|
} else {
|
|
await fetchListPerson(true); // โหลดข้อมูลหน้าแรก
|
|
}
|
|
success($q, "ลบข้อมูสำเร็จ");
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* function updatePagination
|
|
* @param newPagination ข้อมูล Pagination ใหม่
|
|
*/
|
|
function updatePagination(newPagination: Pagination) {
|
|
qureyBody.pageSize = newPagination.rowsPerPage;
|
|
}
|
|
|
|
function onOpenModalPersonal(id: string) {
|
|
personId.value = id;
|
|
modalPersonal.value = true;
|
|
}
|
|
|
|
function updatemodalPersonal(modal: boolean) {
|
|
modalPersonal.value = modal;
|
|
}
|
|
|
|
const tokenParsedData = ref<string[]>([]);
|
|
function checkhideBtnAction(id: string) {
|
|
if (
|
|
dataPosition.value?.profileId === id &&
|
|
tokenParsedData.value.includes("ADMIN") &&
|
|
!tokenParsedData.value.includes("SUPER_ADMIN")
|
|
) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ดูการเปลี่ยนแปลงของ pageSize ใน queryBody
|
|
* เมื่อ pageSize มีการเปลี่ยนแปลงให้โหลดข้อมูลหน้าแรก
|
|
*/
|
|
watch(
|
|
() => qureyBody.pageSize,
|
|
() => {
|
|
fetchListPerson(true);
|
|
}
|
|
);
|
|
|
|
/** hook ทำงานเมื่อ Components ถูกเรียกใช้งาน*/
|
|
onMounted(async () => {
|
|
await fetchOrg(); // ดึงข้อมูลโครงสร้าง
|
|
const token = await tokenParsed();
|
|
tokenParsedData.value = token?.role || [];
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="toptitle text-dark col-12 row items-center">
|
|
กำหนดหน้าที่จัดการโครงสร้าง (แบบร่าง)
|
|
</div>
|
|
<q-card style="height: 100%">
|
|
<q-card-section :horizontal="$q.screen.gt.sm">
|
|
<q-card-section class="col-lg-3 col-md-4 col-xs-12 q-gutter-sm">
|
|
<div>
|
|
<q-input dense outlined v-model="filter" label="ค้นหา">
|
|
<template v-slot:append>
|
|
<q-icon name="search" />
|
|
</template>
|
|
</q-input>
|
|
</div>
|
|
<div class="bg-white tree-container q-pa-xs">
|
|
<q-tree
|
|
class="q-pa-sm q-gutter-sm"
|
|
dense
|
|
:nodes="nodeTree"
|
|
node-key="orgRootName"
|
|
label-key="labelName"
|
|
:filter="filter?.trim()"
|
|
no-results-label="ไม่พบข้อมูลที่ค้นหา"
|
|
no-nodes-label="ไม่มีข้อมูล"
|
|
v-model:expanded="expanded"
|
|
>
|
|
<template v-slot:default-header="prop">
|
|
<q-item
|
|
clickable
|
|
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
|
|
:active="orgId == prop.node.id"
|
|
active-class="my-list-link text-primary text-weight-medium"
|
|
@click.stop="selectedOrg(prop.node.id)"
|
|
>
|
|
<div>
|
|
<div
|
|
v-if="prop.node.isDeputy == true"
|
|
class="text-info text-weight-medium"
|
|
>
|
|
{{ prop.node.orgRootName }}
|
|
</div>
|
|
<div v-else class="text-weight-medium">
|
|
{{ prop.node.orgRootName }}
|
|
</div>
|
|
<div class="text-weight-light text-grey-8">
|
|
{{
|
|
prop.node.orgRootCode == null
|
|
? null
|
|
: prop.node.orgRootCode
|
|
}}
|
|
{{
|
|
prop.node.orgRootShortName == null
|
|
? null
|
|
: prop.node.orgRootShortName
|
|
}}
|
|
</div>
|
|
</div>
|
|
</q-item>
|
|
</template>
|
|
</q-tree>
|
|
</div>
|
|
</q-card-section>
|
|
<q-separator :vertical="$q.screen.gt.sm" />
|
|
<q-card-section class="col-lg-9 col-md-8 col-xs-12" style="height: 85vh">
|
|
<q-card bordered style="height: 100%; border: 1px solid #d6dee1">
|
|
<div class="col-12 text-weight-medium bg-grey-1 q-py-sm q-px-md">
|
|
รายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง
|
|
</div>
|
|
<div class="col-12"><q-separator /></div>
|
|
<q-card-section style="height: 92%" class="scroll">
|
|
<div class="row col-12 q-col-md">
|
|
<q-btn
|
|
v-if="orgId"
|
|
flat
|
|
dense
|
|
color="primary"
|
|
icon="add"
|
|
round
|
|
@click="modalAdd = true"
|
|
>
|
|
<q-tooltip>เพิ่มข้อมูล</q-tooltip>
|
|
</q-btn>
|
|
</div>
|
|
<div class="row q-mt-sm q-col-gutter-sm">
|
|
<div class="col-12 col-sm-3 col-md-4 col-lg-2">
|
|
<q-select
|
|
outlined
|
|
dense
|
|
v-model="qureyBody.searchField"
|
|
:options="store.searchFieldOption"
|
|
label="เลือกที่ต้องการค้นหา"
|
|
emit-value
|
|
map-options
|
|
option-label="name"
|
|
option-value="id"
|
|
/>
|
|
</div>
|
|
<div class="col-12 col-sm-6 col-md-5 col-lg-3">
|
|
<q-input
|
|
v-model="qureyBody.searchKeyword"
|
|
outlined
|
|
dense
|
|
lazy-rules
|
|
label="คำค้น"
|
|
hide-bottom-space
|
|
@keydown.enter.prevent="fetchListPerson(true)"
|
|
>
|
|
</q-input>
|
|
</div>
|
|
<div class="col-12 col-sm-3 col-md-3 col-lg-2">
|
|
<q-btn
|
|
outline
|
|
color="primary"
|
|
icon="search"
|
|
label="ค้นหา"
|
|
class="full-width full-height"
|
|
@click="fetchListPerson(true)"
|
|
/>
|
|
</div>
|
|
|
|
<q-space v-if="$q.screen.gt.md" />
|
|
<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"
|
|
style="min-width: 140px"
|
|
/>
|
|
</div>
|
|
|
|
<div class="col-12 q-mt-sm">
|
|
<d-table
|
|
:columns="columns"
|
|
:rows="rows"
|
|
:paging="true"
|
|
row-key="id"
|
|
flat
|
|
bordered
|
|
dense
|
|
:rows-per-page-options="[10, 25, 50, 100]"
|
|
@update:pagination="updatePagination"
|
|
:visible-columns="visibleColumns"
|
|
>
|
|
<template v-slot:header="props">
|
|
<q-tr :props="props">
|
|
<q-th auto-width />
|
|
<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>
|
|
<q-btn
|
|
v-if="checkhideBtnAction(props.row.profileId)"
|
|
flat
|
|
dense
|
|
color="red"
|
|
icon="delete"
|
|
round
|
|
@click.pervent="onDeletePerson(props.row.id)"
|
|
>
|
|
<q-tooltip>ลบข้อมูล</q-tooltip>
|
|
</q-btn>
|
|
</q-td>
|
|
<q-td
|
|
v-for="col in props.cols"
|
|
:key="col.name"
|
|
:props="props"
|
|
>
|
|
<div v-if="col.name === 'fullName'">
|
|
{{ col.value ? col.value : "-" }}
|
|
|
|
<q-btn
|
|
flat
|
|
dense
|
|
color="info"
|
|
icon="info"
|
|
round
|
|
@click.pervent="
|
|
onOpenModalPersonal(props.row.profileId)
|
|
"
|
|
>
|
|
<q-tooltip>ดูข้อมูล</q-tooltip>
|
|
</q-btn>
|
|
</div>
|
|
|
|
<div v-else>
|
|
{{ col.value ? col.value : "-" }}
|
|
</div>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
<template v-slot:pagination="scope">
|
|
ทั้งหมด {{ total }} รายการ
|
|
<q-pagination
|
|
v-model="qureyBody.page"
|
|
active-color="primary"
|
|
color="dark"
|
|
:max="maxPage"
|
|
:max-pages="5"
|
|
size="sm"
|
|
boundary-links
|
|
direction-links
|
|
@update:model-value="fetchListPerson(false)"
|
|
>
|
|
</q-pagination>
|
|
</template>
|
|
</d-table>
|
|
</div>
|
|
</q-card-section>
|
|
</q-card>
|
|
</q-card-section>
|
|
</q-card-section>
|
|
</q-card>
|
|
|
|
<DialogAddPerson
|
|
v-model:modal="modalAdd"
|
|
v-model:org-id="orgId"
|
|
:fetch-data="fetchListPerson"
|
|
/>
|
|
|
|
<PopupPersonal
|
|
:modal="modalPersonal"
|
|
:id="personId"
|
|
@update:modal="updatemodalPersonal"
|
|
/>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.tree-container {
|
|
overflow: auto;
|
|
height: 76vh;
|
|
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>
|