กำหนดสิทธิ์จัดการโครงสร้าง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-06 15:47:06 +07:00
parent 79875347f9
commit 6e9c8bf593
8 changed files with 801 additions and 4 deletions

View file

@ -0,0 +1,274 @@
<script setup lang="ts">
import { reactive, ref, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useDataStoreUser } from "@/modules/02_users/stores/main";
import type { QTableProps } from "quasar";
import type {
DataProfile,
Pagination,
} from "@/modules/02_users/interface/index/Main";
import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar();
const store = useDataStoreUser();
const { showLoader, hideLoader, messageError, success, dialogConfirm } =
useCounterMixin();
const modal = defineModel<boolean>("modal", { required: true });
const orgId = defineModel<string>("orgId", { required: true });
const props = defineProps({
fetchData: {
type: Function,
required: true,
},
});
const qurey = reactive({
searchKeyword: "",
searchField: "fullName",
page: 1,
pageSize: 10,
});
const selected = ref<DataProfile[]>([]);
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: "posNo",
align: "left",
label: "เลขที่ตำแห่นง",
sortable: true,
field: "posNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posType",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: true,
field: (row) =>
`${row.posType ? row.posType : "-"} ${
row.posLevel ? `(${row.posLevel})` : ``
} `,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
async function onSearchListPerson(newPage: boolean = false) {
qurey.page = newPage ? 1 : qurey.page;
selected.value = [];
showLoader();
await http
.get(config.API.permissionOrgProfile, {
params: qurey,
})
.then((res) => {
const data = res.data.result;
maxPage.value = Math.ceil(data.total / qurey.pageSize);
total.value = data.total;
rows.value = data.data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function onSubmitPerson() {
dialogConfirm(
$q,
async () => {
showLoader();
const person = selected.value[0];
const body = {
nodeId: orgId.value,
personId: person.id,
};
await http
.post(config.API.permissionOrg, body)
.then(async () => {
await props.fetchData?.(false);
success($q, "เพิ่มราชชื่อสำเร็จ");
onClose();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการเพิ่มรายชื่อ",
"ต้องการยืนยันการเพิ่มรายชื่อนี้หรือไม่ ?"
);
}
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: Pagination) {
qurey.pageSize = newPagination.rowsPerPage;
}
function onClose() {
modal.value = false;
qurey.page = 1;
qurey.pageSize = 10;
qurey.searchField = "fullName";
qurey.searchKeyword = "";
rows.value = [];
selected.value = [];
}
watch(
() => qurey.pageSize,
() => {
onSearchListPerson(true);
}
);
</script>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 60%">
<DialogHeader :tittle="'รายชื่อ'" :close="onClose" />
<q-separator />
<q-card-section>
<div class="col-12">
<q-toolbar style="padding: 0">
<q-select
outlined
dense
v-model="qurey.searchField"
:options="store.searchFieldOption"
label="เลือกที่ต้องการค้นหา"
emit-value
map-options
option-label="name"
option-value="id"
style="width: 250px"
/>
<q-toolbar-title>
<q-input
outlined
dense
v-model="qurey.searchKeyword"
label="คำค้นหา"
clearable
>
<template v-slot:append v-if="!qurey.searchKeyword">
<q-icon name="search" color="grey-5" />
</template>
</q-input>
</q-toolbar-title>
<q-btn
label="ค้นหา"
color="primary"
@click="onSearchListPerson(true)"
/>
</q-toolbar>
</div>
<div class="col-12">
<d-table
:columns="columns"
:rows="rows"
:paging="true"
row-key="id"
flat
bordered
dense
:rows-per-page-options="[10, 25, 50, 100]"
selection="single"
v-model:selected="selected"
@update:pagination="updatePagination"
>
<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">
<td auto-width>
<q-checkbox
keep-color
color="primary"
dense
v-model="props.selected"
/>
</td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
งหมด {{ total }} รายการ
<q-pagination
v-model="qurey.page"
active-color="primary"
color="dark"
:max="maxPage"
:max-pages="5"
size="sm"
boundary-links
direction-links
@update:model-value="onSearchListPerson(false)"
></q-pagination>
</template>
</d-table>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn
label="เพิ่ม"
color="public"
:disable="selected.length === 0"
@click="onSubmitPerson"
/>
</q-card-actions>
</q-card>
</q-dialog>
</template>
<style scoped></style>