แต่งตั้งคณะกรรมการทดลองงาน

This commit is contained in:
setthawutttty 2024-10-17 15:36:48 +07:00
parent 77120a0f7b
commit 3ec0614e39
9 changed files with 1150 additions and 30 deletions

View file

@ -0,0 +1,630 @@
<script setup lang="ts">
import { useQuasar, type QTableProps } from "quasar";
import { ref, reactive, watch, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type {
FormAppointData,
OpfillterTypeSt,
MemBerType,
PersonsAppointData,
} from "@/modules/05_placement/interface/request/Main";
import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar(); // noti quasar
const route = useRoute();
const router = useRouter();
const mixin = useCounterMixin();
const {
dialogRemove,
showLoader,
hideLoader,
messageError,
dialogConfirm,
success,
} = mixin;
const checkRoutePermisson = ref<boolean>(
route.name == "probationAppointDetail"
);
const id = ref<string>(route.params.id as string);
const profileId = ref<string>("");
const isSave = ref<boolean>(false);
const topic = ref<string>("");
const status = ref<string>("");
const rows = ref<PersonsAppointData[]>([]);
const modal = ref<boolean>(false);
const member = ref<string>("");
const selected = ref<MemBerType[]>([]);
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
const optionsTypeMain = ref<OpfillterTypeSt[]>([]);
const optionsType = ref<OpfillterTypeSt[]>([
{ id: "chairman", value: "ประธาน" },
{ id: "committee", value: "กรรมการ" },
]);
const commanderRows = ref<MemBerType[]>([]);
const chairmanRows = ref<MemBerType[]>([]);
const visibleColumns = ref<string[]>([
"no",
"role",
"name",
"position",
"positionType",
"positionLevel",
]);
const visibleColumnsMember = ref<string[]>([
"no",
"name",
"position",
"posLevel",
"posType",
]);
/** หัวตาราง */
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "role",
align: "left",
label: "บทบาท",
sortable: true,
field: "role",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ",
sortable: true,
field: "name",
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: "positionType",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: true,
field: "positionType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionLevel",
align: "left",
label: "ระดับตำแหน่ง",
sortable: true,
field: "positionLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const columnsMember = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ",
sortable: true,
field: "name",
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: "posLevel",
align: "left",
label: "ระดับตำแหน่ง",
sortable: true,
field: "posLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posType",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: true,
field: "posType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/** เพิ่ม ประธาน/กรรมการ */
function onAdd() {
modal.value = true;
}
function close() {
modal.value = false;
member.value = "";
}
function updatePagination(newPagination: any) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
function onAddPerson() {
changeFormData();
const data = selected.value.map((item: MemBerType) => ({
profileId: item.id,
name: `${item.prefix}${item.firstName} ${item.lastName}`,
citizenId: item.citizenId,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
positionType: item.posType,
positionLevel: item.posLevel,
role: member.value == "chairman" ? "chairman" : "committee",
}));
rows.value = [...rows.value, ...data];
rows.value.sort((a, b) => (a.role === "chairman" ? -1 : 1));
close();
}
function getPerson() {
showLoader();
http
.get(config.API.orgProfilePlacement(profileId.value))
.then((res) => {
const data = res.data.result;
commanderRows.value = data.commander.map((item: any) => ({
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
posLevel: item.posLevel,
posType: item.posType,
position: item.position,
isDirector: item.isDirector,
}));
chairmanRows.value = data.chairman.map((item: any) => ({
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
posLevel: item.posLevel,
posType: item.posType,
position: item.position,
isDirector: item.isDirector,
}));
hideLoader();
})
.catch((e) => {
messageError($q, e);
hideLoader();
})
.finally(() => {});
}
function onChangeMember() {
selected.value = [];
commanderRows.value = commanderRows.value.filter(
(item: MemBerType) =>
!rows.value.some((i: PersonsAppointData) => i.profileId == item.id)
);
chairmanRows.value = chairmanRows.value.filter(
(item: MemBerType) =>
!rows.value.some((i: PersonsAppointData) => i.profileId == item.id)
);
}
function onDelete(id: string) {
changeFormData();
rows.value = rows.value.filter((row) => row.profileId !== id);
}
function convertText(val: string) {
switch (val) {
case "chairman":
return "ประธาน";
case "committee":
return "กรรมการ";
default:
"-";
}
}
//
const topicCheck = ref<string>(topic.value);
const rowsCheck = ref<PersonsAppointData[]>(rows.value);
function changeFormData() {
if (topic.value !== topicCheck.value || rows.value !== rowsCheck.value) {
isSave.value = true;
} else {
isSave.value = false;
}
topicCheck.value = topic.value;
rowsCheck.value = rows.value;
}
function onSubmit() {
const body = {
topic: topic.value,
persons: rows.value.map(
({ prefix, firstName, lastName, citizenId, ...newData }) => newData
),
};
dialogConfirm($q, () => {
showLoader();
http
.put(config.API.appointMain + `/${id.value}`, body)
.then(async (res) => {
await getData();
success($q, "บันทึกข้อมูลสำเร็จ");
isSave.value = false;
hideLoader();
})
.catch((e) => {
messageError($q, e);
hideLoader();
})
.finally(() => {});
});
}
/** ดึงข้อมูลหลัก */
async function getData() {
showLoader();
await http
.get(config.API.appointMain + `/${id.value}`)
.then(async (res) => {
const data = await res.data.data;
topic.value = data.topic;
status.value = data.status;
profileId.value = data.profileId;
rows.value = data.directors.map((item: any) => ({
profileId: item.profileId,
name: item.name,
citizenId: item.citizenId,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
positionType: item.positionType,
positionLevel: item.positionLevel,
role: item.role,
}));
hideLoader();
})
.catch((e) => {
messageError($q, e);
hideLoader();
})
.finally(() => {});
}
watch(
() => modal.value,
() => {
if (modal.value) {
optionsTypeMain.value = optionsType.value;
const optionData = optionsType.value;
optionsTypeMain.value = optionData.filter(
(item: OpfillterTypeSt) =>
!rows.value.some(
(i) => i.role === "chairman" && item.id === "chairman"
)
);
getPerson();
}
}
);
onMounted(async () => {
await getData();
});
</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)"
/>
{{
checkRoutePermisson ? "รายละเอียด" : ""
}}แตงตงคณะกรรมการประเมนผลการทดลองปฏหนาทราชการ
</div>
<q-card flat>
<q-form greedy @submit.prevent @validation-success="onSubmit">
<div class="row q-col-gutter-sm q-pa-sm">
<div v-if="isSave" class="col-12 q-pt-none">
<q-banner
inline-actions
bordered
rounded
dense
class="bg-red-1 text-red border-orange"
>
<q-icon name="mdi-information-outline" size="20px" /> แจงเตอน
งไมไดนทกขอม
</q-banner>
</div>
<div class="col-12">
<q-input
dense
outlined
label="หัวข้อ"
:readonly="checkRoutePermisson"
v-model="topic"
class="inputgreen"
hide-bottom-space
@update:model-value="changeFormData"
:rules="[(val:string) => !!val || `${'กรุณากรอกหัวข้อ'}`,]"
></q-input>
</div>
<div class="col-12">
<q-card bordered style="border: 1px solid #d6dee1">
<div
class="col-xs-12 col-sm-12 text-weight-medium bg-grey-1 q-py-xs q-px-md"
>
ประธาน/กรรมการ
<q-btn
v-if="!checkRoutePermisson"
size="12px"
flat
round
dense
color="add"
class="q-ml-sm"
@click="onAdd"
icon="mdi-plus"
>
<q-tooltip>เพมประธาน/กรรมการ</q-tooltip>
</q-btn>
</div>
<q-separator />
<div class="q-pa-sm">
<d-table
ref="table"
:columns="columns"
:rows="rows"
row-key="profileId"
flat
:visible-columns="visibleColumns"
bordered
:paging="true"
dense
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
>
<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-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td auto-width>
<q-btn
v-if="!checkRoutePermisson"
flat
round
dense
icon="delete"
color="red"
@click="onDelete(props.row.profileId)"
>
<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 == 'no'">
{{
(pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex +
1
}}
</div>
<div v-else-if="col.name == 'role'">
{{ props.row.role ? convertText(props.row.role) : "-" }}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
</q-card>
</div>
</div>
<q-separator v-if="!checkRoutePermisson" />
<q-card-actions align="right" v-if="!checkRoutePermisson">
<q-btn label="บันทึก" color="secondary" type="submit"
><q-tooltip>นท</q-tooltip></q-btn
>
</q-card-actions>
</q-form>
</q-card>
<q-dialog v-model="modal" persistent>
<q-card class="col-12" style="width: 80%">
<q-form greedy @submit.prevent @validation-success="onAddPerson">
<DialogHeader tittle="เพิ่มประธาน/กรรมการ" :close="close" />
<q-separator />
<q-card-section>
<div class="row q-col-gutter-sm">
<div class="col-12">
<q-select
v-model="member"
outlined
dense
label="ประธาน/กรรมการ"
:options="optionsTypeMain"
option-value="id"
option-label="value"
map-options
emit-value
@update:model-value="onChangeMember()"
>
</q-select>
</div>
<div class="col-12">
<d-table
ref="table"
:columns="columnsMember"
:rows="
member == 'committee'
? commanderRows
: member == 'chairman'
? chairmanRows
: []
"
row-key="id"
flat
:visible-columns="visibleColumnsMember"
bordered
:paging="true"
dense
:selection="member == 'chairman' ? 'single' : 'multiple'"
v-model:selected="selected"
:rows-per-page-options="[10, 25, 50, 100]"
>
<template v-slot:header-selection="scope">
<q-checkbox
keep-color
color="primary"
dense
:disable="!member"
v-model="scope.selected"
/>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<td class="text-center">
<q-checkbox
keep-color
:disable="!member"
color="primary"
dense
v-model="props.selected"
/>
</td>
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name == 'no'">
{{
(pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex +
1
}}
</div>
<div v-else-if="col.name == 'name'">
{{
props.row.firstName
? `${props.row.prefix}${props.row.firstName} ${props.row.lastName}`
: "-"
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn
label="เพิ่มรายชื่อประธาน/กรรมการ"
color="secondary"
type="submit"
:disable="selected.length == 0"
><q-tooltip>เพมรายชอประธาน/กรรมการ</q-tooltip></q-btn
>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>