hrms-mgt/src/modules/05_placement/components/probation/MainProbation.vue

753 lines
22 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, useAttrs, onMounted, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import router from "@/router";
import { checkPermission } from "@/utils/permissions";
import { useCounterMixin } from "@/stores/mixin";
2023-09-28 14:22:25 +07:00
import { useTransferDataStore } from "@/modules/05_placement/store";
import type { QTableProps } from "quasar";
2023-09-28 14:22:25 +07:00
import type {
FormMainProbation,
FormMainProbation2,
OpfillterType,
} from "@/modules/05_placement/interface/request/Main";
import DialogHeader from "@/modules/04_registry/components/DialogHeader.vue";
import DialogOrder from "@/modules/05_placement/components/probation/DialogOrder.vue";
const $q = useQuasar(); //ใช้ noti quasar
const storeFn = useTransferDataStore();
const mixin = useCounterMixin();
const { statusProbationMain } = storeFn;
const { messageError, success, showLoader, hideLoader, dialogConfirm } = mixin;
const modalCommand = ref<boolean>(false); // ตัวแปร popup ออกคำสั่ง
const filterRef = ref<any>(null);
const modal = ref<boolean>(false);
const paging = ref<boolean>(true);
const filterRef2 = ref<any>(null);
const attrs = ref<any>(useAttrs());
const paging2 = ref<boolean>(true);
const fillterStatus = ref<any>([]);
const fillter = ref<number | null>(0);
const filterKeyword = ref<string>("");
const filterKeyword2 = ref<string>("");
const rows = ref<FormMainProbation[]>([]);
const rows2 = ref<FormMainProbation2[]>([]);
const dataUpdate = ref<FormMainProbation[]>([]);
const Opfillter = ref<OpfillterType[]>([]);
const Opfillter2 = ref<OpfillterType[]>([
{
id: 0,
value: "ทั้งหมด",
},
]);
const formProbation = reactive({ keyword: "", pageSize: 10, page: 1 });
const maxPage = ref<number>(1);
2023-09-28 14:22:25 +07:00
const pagination = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination2 = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
/** ข้อมูลที่เเสดง */
const visibleColumns = ref<string[]>([
"no",
"name",
2023-08-09 12:09:46 +07:00
"position_line",
"position_level",
"organization",
"probation_no",
"order_number",
"probation_status",
2023-08-30 13:04:45 +07:00
]);
/** หัวตาราง */
const columns = 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",
},
2023-08-03 10:12:01 +07:00
{
2023-08-09 12:09:46 +07:00
name: "position_line",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
2023-08-09 12:09:46 +07:00
field: "position_line",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2023-08-03 10:12:01 +07:00
{
2023-08-09 12:09:46 +07:00
name: "position_level",
align: "left",
label: "ระดับ",
sortable: true,
2023-08-09 12:09:46 +07:00
field: "position_level",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2023-08-03 10:12:01 +07:00
{
2023-08-09 12:09:46 +07:00
name: "organization",
align: "left",
label: "สังกัด",
sortable: true,
2023-08-09 12:09:46 +07:00
field: "organization",
headerStyle: "font-size: 14px",
style: "font-size: 14px ",
classes: "table_ellipsis",
},
2023-08-03 10:12:01 +07:00
{
2023-08-09 12:09:46 +07:00
name: "probation_no",
align: "center",
label: "ครั้งที่ทดลองปฏิบัติหน้าที่ราชการ",
sortable: true,
2023-08-09 12:09:46 +07:00
field: "probation_no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format(val, row) {
return row.probation_no ? row.probation_no : "-";
},
},
2023-08-03 10:12:01 +07:00
{
2023-08-09 12:09:46 +07:00
name: "order_number",
align: "center",
label: "เลขที่คําสั่งบรรจุแต่งตั้ง",
sortable: true,
2023-08-09 12:09:46 +07:00
field: "order_number",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format(val, row) {
return row.order_number ? row.order_number : "-";
},
},
{
2023-08-09 12:09:46 +07:00
name: "probation_status",
align: "left",
label: "สถานะ",
sortable: true,
2023-08-09 12:09:46 +07:00
field: "probation_status",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
2023-08-03 10:12:01 +07:00
},
]);
/** หัวตาราง2 */
const columns2 = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
2023-08-03 10:12:01 +07:00
style: "font-size: 14px",
},
{
2023-08-03 10:12:01 +07:00
name: "fullname",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
2023-08-03 10:12:01 +07:00
field: "fullname",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2023-08-03 10:12:01 +07:00
{
name: "position",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2023-08-03 10:12:01 +07:00
{
name: "posLevelName",
align: "left",
2024-06-07 12:10:11 +07:00
label: "ประเภทตำแหน่ง",
sortable: true,
field: "posLevelName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
2024-06-07 12:10:11 +07:00
format(val, row) {
return (
(row.posTypeName ? row.posTypeName : "") +
(row.posLevelName !== null ? " (" + row.posLevelName + ")" : "")
);
2024-06-07 12:10:11 +07:00
},
},
2023-08-03 10:12:01 +07:00
{
name: "organizationOrganization",
align: "left",
label: "สังกัด",
sortable: true,
2023-08-03 10:12:01 +07:00
field: "organizationOrganization",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
2023-08-03 10:12:01 +07:00
},
2023-08-30 13:04:45 +07:00
{
name: "status",
align: "left",
label: "ทดลองปฏิบัติหน้าที่ราชการ",
2023-08-30 13:04:45 +07:00
sortable: true,
field: "status",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/** get ข้อมูล */
async function getpersonalList() {
2023-08-03 10:12:01 +07:00
showLoader();
await http
.get(
config.API.probationPersonalList() +
`?status=${fillter.value}&page=${pagination.value.page}&pageSize=${pagination.value.rowsPerPage}`
)
.then(async (res) => {
2024-10-07 16:36:00 +07:00
const data = await res.data.data.data;
const resTotal = await res.data.data.total;
rows.value = data;
fillterStatus.value = data;
dataUpdate.value = rows.value;
Opfillter.value = storeFn.optionStatusProbation;
2024-10-07 16:36:00 +07:00
totalList.value = Math.ceil(resTotal / pagination.value.rowsPerPage);
total.value = resTotal;
2024-10-07 16:38:03 +07:00
hideLoader();
2023-08-03 10:12:01 +07:00
})
2024-10-07 16:38:03 +07:00
.catch((e) => {
messageError($q, e);
2023-08-03 10:12:01 +07:00
hideLoader();
2024-10-07 16:38:03 +07:00
})
.finally(() => {});
}
async function onclickAddProbation() {
modal.value = true;
modal.value && showLoader();
await http
.post(config.API.orgProfileProbation, formProbation)
.then((res) => {
maxPage.value = Math.ceil(res.data.result.total / formProbation.pageSize);
rows2.value = res.data.result.data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* function updatePagination
* @param newPagination อม Pagination ใหม
*/
function updatePagination(newPagination: any) {
formProbation.page = 1;
formProbation.pageSize = newPagination.rowsPerPage;
}
async function filterKeyword2Fn(page: number) {
page !== 1 ? (formProbation.page = 1) : await onclickAddProbation();
}
/**
* เพมขอม ทดลองปฏหนาทราชการ
* @param data personal data
*/
function clickAdd(data: any) {
2023-08-29 17:09:25 +07:00
dialogConfirm(
$q,
async () => {
showLoader();
await http
.post(config.API.personalAdd(), data)
.then(async () => {
await http
.get(config.API.orgProfileStatus(data.id))
.then((res) => {
getpersonalList();
success($q, "เพิ่มข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
});
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
clickClose();
hideLoader();
});
2023-08-29 17:09:25 +07:00
},
"ยันยันการเพิ่มข้อมูล",
"ต้องการเพิ่มข้อมูลนี้หรือไม่ ?"
);
}
/** ปิด dialog */
async function clickClose() {
modal.value = false;
}
/** reset ฟิลเตอร์ */
function resetFilter() {
filterKeyword.value = "";
filterRef.value.focus();
}
/** reset ฟิลเตอร์ ใน dialog */
function resetFilter2() {
filterKeyword2.value = "";
filterRef2.value.focus();
}
function paginationLabel(start: string, end: string, total: string) {
if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
}
function paginationLabel2(start: string, end: string, total: string) {
2023-08-30 13:04:45 +07:00
if (paging2.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
}
2023-09-28 14:22:25 +07:00
/**
* นหาตาม text
* @param val าทนหา
* @param update fn
*/
2023-09-28 14:22:25 +07:00
function filterFn(val: string, update: any) {
if (val == "") {
update(() => {
Opfillter2.value = Opfillter.value;
fillter.value = null;
});
} else {
update(() => {
Opfillter2.value = Opfillter.value.filter(
(e: any) => e.value.search(val) !== -1
);
});
}
}
/** ส่งไปออกคำสั่ง */
function onCommand() {
modalCommand.value = true;
}
watch([() => formProbation.page, () => formProbation.pageSize], () => {
onclickAddProbation();
});
watch(
() => pagination.value.rowsPerPage,
async () => {
await getpersonalList();
}
);
/** get ค่า เมื่อโหลดหน้า */
onMounted(async () => {
getpersonalList();
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
รายการผทดลองปฏหนาทราชการ
</div>
<q-card flat bordered class="col-12 q-mt-sm q-pa-md">
<div class="row q-col-gutter-sm">
<div class="row col-12 q-col-gutter-sm">
<div class="col-6">
<div class="row">
2023-09-28 14:22:25 +07:00
<q-select
class="col-5 col-sm-3 col-md-8"
2023-09-28 14:22:25 +07:00
v-model="fillter"
label="สถานะ"
dense
map-options
option-label="value"
:options="Opfillter2"
option-value="id"
lazy-rules
emit-value
2023-09-28 14:22:25 +07:00
hide-bottom-space
:readonly="false"
:borderless="false"
:outlined="true"
:hide-dropdown-icon="false"
@update:model-value="getpersonalList()"
2023-09-28 14:22:25 +07:00
@filter="filterFn"
use-input
behavior="menu"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
<div>
2023-09-28 14:22:25 +07:00
<q-btn
v-if="checkPermission($route)?.attrIsCreate"
@click="onclickAddProbation"
2023-09-28 14:22:25 +07:00
flat
round
color="add"
icon="mdi-plus"
>
<q-tooltip>เพมผทดลองปฏหนาทราชการ</q-tooltip>
</q-btn>
</div>
<div>
<q-btn
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
@click="onCommand"
flat
round
color="add"
icon="mdi-account-arrow-right"
>
<q-tooltip>งไปออกคำส</q-tooltip>
</q-btn>
</div>
</div>
</div>
<q-space />
2023-09-28 14:22:25 +07:00
<q-input
class="col-xs-12 col-sm-3 col-md-2"
standout
dense
v-model="filterKeyword"
ref="filterRef"
outlined
debounce="300"
placeholder="ค้นหา"
>
<template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" />
2023-09-28 14:22:25 +07:00
<q-icon
v-if="filterKeyword !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
</template>
</q-input>
2023-09-28 14:22:25 +07:00
<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"
options-cover
style="min-width: 150px"
class="col-xs-12 col-sm-3 col-md-2"
/>
</div>
<div class="col-12">
<d-table
2023-09-28 14:22:25 +07:00
ref="table"
:columns="columns"
:rows="rows"
:filter="filterKeyword"
row-key="Order"
flat
bordered
:paging="true"
dense
class="custom-header-table"
v-bind="attrs"
:visible-columns="visibleColumns"
:pagination-label="paginationLabel"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
2023-09-28 14:22:25 +07:00
>
<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="checkPermission($route)?.attrIsGet"
flat
dense
round
color="info"
icon="mdi-eye"
@click="
router.push(`/probation/detail/${props.row.personal_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 == 'no'">
{{
(pagination.page - 1) * pagination.rowsPerPage +
props.rowIndex +
1
}}
</div>
<div v-else-if="col.name == 'order_number'">
{{
props.row.order_number
? props.row.order_number != "xx/2566"
? props.row.order_number
: "-"
: "-"
}}
</div>
<div v-else-if="col.name == 'probation_status'">
{{
props.row.probation_status
? statusProbationMain(props.row.probation_status)
: "-"
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
งหมด {{ total }} รายการ
2023-09-28 14:22:25 +07:00
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="Number(totalList)"
2023-09-28 14:22:25 +07:00
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="getpersonalList"
2023-09-28 14:22:25 +07:00
></q-pagination>
</template>
</d-table>
</div>
</div>
</q-card>
<q-dialog v-model="modal" persistent>
<q-card style="width: 900px; max-width: 80vw">
<q-form ref="myForm">
2023-09-28 14:22:25 +07:00
<DialogHeader
tittle="เพิ่มผู้ทดลองปฏิบัติหน้าที่ราชการ "
:close="clickClose"
/>
<q-separator />
<q-card-section class="q-pa-md q-col-gutter-sm">
2023-09-28 14:22:25 +07:00
<q-input
class="col-12"
standout
dense
v-model="formProbation.keyword"
2023-09-28 14:22:25 +07:00
ref="filterRef2"
outlined
debounce="300"
placeholder="ค้นหา"
@keydown.enter.prevent="filterKeyword2Fn(formProbation.page)"
2023-09-28 14:22:25 +07:00
>
<template v-slot:append>
<q-icon v-if="filterKeyword2 == ''" name="search" />
2023-09-28 14:22:25 +07:00
<q-icon
v-if="filterKeyword2 !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter2"
/>
</template>
</q-input>
<div class="col-12">
<d-table
2023-09-28 14:22:25 +07:00
ref="table2"
:columns="columns2"
:rows="rows2"
row-key="Order"
flat
bordered
:paging="true"
dense
class="custom-header-table"
v-bind="attrs"
:pagination-label="paginationLabel2"
v-model:pagination="pagination2"
@update:pagination="updatePagination"
:rows-per-page-options="[10, 25, 50, 100]"
2023-09-28 14:22:25 +07:00
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th auto-width />
2023-09-28 14:22:25 +07:00
<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" class="cursor-pointer">
<q-td auto-width>
<q-btn
dense
class="q-px-md"
outline
color="primary"
label="เพิ่ม"
@click="clickAdd(props.row)"
>
</q-btn>
</q-td>
2023-09-28 14:22:25 +07:00
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name == 'no'">
{{
(formProbation.page - 1) * formProbation.pageSize +
props.rowIndex +
1
}}
</div>
<div v-else-if="col.name == 'fullname'">
{{
(props.row.prefix ? props.row.prefix : "") +
props.row.firstName +
" " +
props.row.lastName
}}
</div>
<div v-else-if="col.name == 'status'" class="text-center">
2023-09-28 14:22:25 +07:00
<q-icon
v-if="props.row.isProbation === true"
2023-09-28 14:22:25 +07:00
name="mdi-check"
color="positive"
size="sm"
/>
</div>
<div
v-else-if="col.name == 'organizationOrganization'"
class="table_ellipsis"
>
<div
v-if="
props.row.orgChild4Name === null &&
props.row.orgChild3Name === null &&
props.row.orgChild2Name === null &&
props.row.orgChild1Name === null &&
props.row.orgRootName === null
"
>
-
</div>
{{
`${
props.row.orgChild4Name
? props.row.orgChild4Name + "/"
: ""
}${
props.row.orgChild3Name
? props.row.orgChild3Name + "/"
: ""
}${
props.row.orgChild2Name
? props.row.orgChild2Name + "-"
: ""
}${
props.row.orgChild1Name
? props.row.orgChild1Name + "/"
: ""
}${props.row.orgRootName ? props.row.orgRootName : ""}`
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
2023-09-28 14:22:25 +07:00
<q-pagination
v-model="formProbation.page"
2023-09-28 14:22:25 +07:00
active-color="primary"
color="dark"
:max="maxPage"
2023-09-28 14:22:25 +07:00
size="sm"
boundary-links
direction-links
2024-02-22 17:27:05 +07:00
:max-pages="5"
2023-09-28 14:22:25 +07:00
></q-pagination>
</template>
</d-table>
</div>
</q-card-section>
</q-form>
</q-card>
</q-dialog>
<DialogOrder v-model:modal="modalCommand" />
</template>