hrms-mgt/src/modules/05_placement/views/03_receiveMain.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 50fdb30920 fix(receive): Display columns posTypeOld
2026-05-12 18:07:29 +07:00

784 lines
26 KiB
Vue

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import {
checkPermission,
checkPermissionList,
checkPermissionCreate,
} from "@/utils/permissions";
import { useCounterMixin } from "@/stores/mixin";
import { useTransferDataStore } from "@/modules/05_placement/store";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
import type { FormDataAppoint } from "@/modules/05_placement/interface/request/Main";
import type {
ResponseData,
ResponseRow,
} from "@/modules/05_placement/interface/response/Receive";
import Dialogbody from "@/modules/05_placement/components/Receive/DialogOrders.vue";
import DialogHeader from "@/components/DialogHeader.vue";
import DialogOrgSelect from "@/components/Dialogs/DialogOrgSelect.vue";
const $q = useQuasar();
const router = useRouter();
const mixin = useCounterMixin();
const store = useTransferDataStore();
const { statusText, filterOption } = useTransferDataStore();
const {
showLoader,
hideLoader,
success,
messageError,
date2Thai,
dialogRemove,
onSearchDataTable,
findOrgNameHtml,
findOrgName,
} = mixin;
const status = ref<string>("");
const dataRecevice = ref<ResponseData[]>([]); //ข้อมูลรายการรับโอน
const filters = ref<ResponseRow[]>([]); //ข้อมูลรายการรับโอน
const dataRows = ref<ResponseRow>(); //ข้อมูลที่ต้องการเลือกหน่วยงานที่รับโอน
const modal = ref<boolean>(false); //แสดง popup ส่งไปออกคำสั่งรับโอน
const modalupload = ref<boolean>(false); //แสดง popup อัปโหลดเอกสาร
const modalTree = ref<boolean>(false); //แสดง popup เลือกหน่วยงานที่รับโอน
const personal = ref<ResponseData[]>([]); //ข้อมูลบุคคล
const personalId = ref<string>(""); //บุคคล
const files = ref<any>(); //ไฟล์
const posType = ref<string>(""); //ตำแหน่งประเภท
const posLevel = ref<string>(""); //ระดับตำแหน่ง
const position = ref<string>(""); //ตำแหน่ง
const type = ref<string | null>(null);
//Table
const rows = ref<ResponseRow[]>([]); //รายการรับโอน
const rowsData = ref<ResponseRow[]>([]); //รายการรับโอน
const rows2 = ref<ResponseRow[]>([]); //รายการออกคำสั่ง
const rows2Data = ref<ResponseRow[]>([]); //รายการออกคำสั่ง
const filterKeyword = ref<string>(""); //คำค้นหารายการรับโอน
const filterKeyword2 = ref<string>(""); //คำค้นหารายการออกคำสั่ง
const visibleColumns = ref<string[]>([
"no",
"citizenId",
"fullname",
"posTypeOld",
"positionNumberOld",
"organizationNameOld",
"organizationName",
"dateOfBirth",
"createdAt",
"status",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "citizenId",
align: "left",
label: "เลขประจำตัวประชาชน",
sortable: true,
field: "citizenId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "fullname",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "fullname",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
format(val, row) {
return ` ${row.rank ? row.rank : row.prefix ?? ""}${
row.firstName ?? ""
} ${row.lastName ?? ""}`;
},
},
{
name: "positionNumberOld",
align: "left",
label: "เลขที่ตำแหน่งเดิม",
sortable: true,
field: "positionNumberOld",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posTypeOld",
align: "left",
label: "ตำแหน่งประเภทเดิม",
sortable: true,
field: "posTypeOld",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format(val, row) {
return row.positionTypeOld && row.positionTypeOld !== "-"
? `${row.positionTypeOld}${
row.positionLevelOld && row.positionLevelOld !== "-"
? `(${row.positionLevelOld})`
: ""
}`
: "";
},
},
{
name: "organizationNameOld",
align: "left",
label: "ตำแหน่ง/สังกัดเดิม",
sortable: true,
field: "organizationNameOld",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (val, row) => {
return row.organizationPositionOld
? `${row.organizationPositionOld.replace(/(.*)\s(.*)$/, "$1\n$2")} `
: "-";
},
},
{
name: "organizationName",
align: "left",
label: "หน่วยงานที่รับโอน",
sortable: true,
field: "organizationName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
format: (val, row) => {
// return `${row.root} (${row.rootShortName}) ${row.nodeName} (${row.nodeShortName}${row.posMasterNo})`;
return `${row.position !== null ? row.position : ""}${
row.posLevelName !== null ? `${row.posLevelName}` : ""
} ${
row.nodeShortName !== null
? `(${row.nodeShortName} ${row.posMasterNo})`
: ""
} ${findOrgName(row)}`;
},
},
{
name: "dateOfBirth",
align: "left",
label: "วัน/เดือน/ปี เกิด",
sortable: true,
field: "dateOfBirth",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
format(val, row) {
return date2Thai(row.dateOfBirth);
},
},
{
name: "createdAt",
align: "left",
label: "วันที่ดำเนินการ",
sortable: true,
field: "createdAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
sortOrder: "da",
format(val, row) {
return date2Thai(row.createdAt);
},
},
{
name: "status",
align: "left",
label: "สถานะ",
sortable: true,
field: "status",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
format(val, row) {
return statusText(row.status);
},
},
]);
/** ฟังก์ชันดึงข้อมูลรายการรับโอน*/
async function fecthlistRecevice() {
showLoader();
await http
.get(config.API.receiveData() + `?status=${status.value}`)
.then(async (res) => {
const data = await res.data.result;
dataRecevice.value = data;
rows.value = data;
rowsData.value = data;
filters.value = data;
onSearch();
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/** ไปหน้าเพิ่มข้อมูลรายการรับโอน*/
function onAddReceive() {
router.push(`/placement/receive/add`);
}
/** ฟังก์ชันบันทึกการอัปโหลดเอกสาร*/
function onSubmitDoc() {
const formData = new FormData();
formData.append("File", files.value);
showLoader();
http
.put(config.API.receiveFile(personalId.value), formData)
.then(async () => {
await success($q, "บันทึกข้อมูลสำเร็จ");
clickCloseUpload();
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/** ฟังก์ชันปิด popup ออกคำสั่ง*/
function clickClose() {
modal.value = false;
filterKeyword2.value = "";
}
/** ฟังก์ชันปิด popup อัปเดตไฟล์*/
function clickCloseUpload() {
modalupload.value = false;
files.value = null;
}
/**
* ฟังก์ชันเปิด popup เลือกหน่วยงานที่รับโอน
* @param id id รายการรับโอนที่เลือกหน่วยงานที่รับโอน
* @param data ข้อมูลรายการรับโอน
*/
function openModalTree(id: string, data: ResponseRow) {
personalId.value = id;
personal.value = dataRecevice.value.filter((e: ResponseData) => e.id === id);
dataRows.value = data;
modalTree.value = true;
type.value = null;
posType.value = data.posTypeOldId;
posLevel.value = data.posLevelOldId;
position.value = data.positionOld;
}
/**
* ฟังก์ชันเปิด popup อัปเดตไฟล์
* @param id รายการที่ต้องการอัปเดตไฟล์
*/
function openUpload(id: string) {
personalId.value = id;
modalupload.value = true;
}
/**
* ฟังก์ชันยืนยันการลบข้อมูล
* @param id รายการที่ต้องการลบ
*/
function openDelete(id: string) {
dialogRemove($q, async () => {
showLoader();
await http
.delete(config.API.receiveDataId(id))
.then(async () => {
await fecthlistRecevice();
await success($q, "ลบข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
/**
* ฟังก์ชันไปหน้ารายละเอียด
* @param id รายการที่ต้องการดูรายละเอียก
*/
function nextPage(id: string) {
router.push({
path: `/placement/receive/${id}`,
});
}
/**
* ฟังก์ชันส่งไปออกคำสั่ง
* ค้นหารายชื่อออกคำสั่งตามสถานะ อนุมัติ (APPROVE)
*/
function openModalOrder() {
const row = filters.value.filter(
(r: ResponseRow) =>
(r.status == "WAITTING" ||
r.status == "PENDING" ||
r.status == "APPROVE") &&
r.posMasterNo != null &&
r.educationOld &&
r.organizationPositionOld &&
r.positionTypeOld &&
r.positionLevelOld &&
r.positionNumberOld
);
rows2.value = row;
rows2Data.value = row;
modal.value = true;
}
/**
* ฟังก์ชันบันทึกการเลือกหน่วยงานที่รับโอน
* @param data ข้อมูลหน่วยงานที่รับโอน
*/
async function onSave(data: FormDataAppoint) {
const dataAppoint = {
node: data.node,
nodeId: data.nodeId,
orgRevisionId: data.orgRevisionId,
positionId: data.positionId,
posMasterNo: data.posMasterNo ?? "",
positionName: data.positionName ?? "",
posTypeId: data.posTypeId,
posTypeName: data.posTypeName ?? "",
posLevelId: data.posLevelId,
posLevelName: data.posLevelName ?? "",
posExecutiveName: data.posExecutiveName ?? "",
reportingDate: data.reportingDate,
posmasterId: data.posmasterId,
typeCommand: data.typeCommand,
positionExecutiveField: data.positionExecutiveField,
positionArea: data.positionArea,
};
showLoader();
await http
.put(config.API.receivePosition(personalId.value), dataAppoint)
.then(async () => {
await fecthlistRecevice();
await success($q, "บันทึกข้อมูลสำเร็จ");
modalTree.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function onSearch() {
rows.value = onSearchDataTable(
filterKeyword.value,
rowsData.value,
columns.value ? columns.value : []
);
}
/** ทำงานเมื่อมีการเรียกใช้ Components*/
onMounted(async () => {
await fecthlistRecevice();
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">รายการรบโอน</div>
<q-card flat bordered class="col-12 q-mt-sm">
<div class="row q-pa-md">
<div class="col-12 q-gutter-sm">
<div class="row">
<div class="col-2">
<q-select
:model-value="status ? status : 'ทั้งหมด'"
outlined
dense
label="สถานะ"
:options="store.statusOp"
emit-value
map-options
option-label="name"
option-value="id"
fill-input
use-input
hide-selected
bg-color="white"
@filter="(inputValue:any,doneFn:Function) => filterOption(inputValue, doneFn) "
@update:model-value="(value:string)=>{(status = value),fecthlistRecevice()}"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไม่มีข้อมูล
</q-item-section>
</q-item>
</template>
<template v-if="status" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="(status = ''), fecthlistRecevice()"
class="cursor-pointer"
style="opacity: 0.6"
/>
</template>
</q-select>
</div>
<q-btn
v-if="checkPermission($route)?.attrIsCreate"
flat
round
color="primary"
@click="onAddReceive"
icon="mdi-plus"
>
<q-tooltip>เพิ่มข้อมูล</q-tooltip>
</q-btn>
<q-btn
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermissionList(['COMMAND']) &&
checkPermissionCreate('COMMAND')
"
size="14px"
flat
round
color="primary"
icon="mdi-account-arrow-right"
@click="openModalOrder()"
>
<q-tooltip>ส่งไปออกคำสั่งรับโอน</q-tooltip>
</q-btn>
<q-space />
<q-input
standout
dense
v-model="filterKeyword"
ref="filterRef"
outlined
placeholder="นหา"
@keydown.enter.prevent="onSearch"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
<q-select
class="q-ml-sm"
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">
<d-table
:columns="columns"
:rows="rows"
row-key="id"
: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
icon="mdi-dots-horizontal-circle-outline"
color="secondary"
flat
round
dense
v-if="
(props.row.status !== 'REPORT' &&
props.row.status !== 'DONE' &&
checkPermission($route)?.attrIsGet) ||
(checkPermission($route)?.attrIsDelete &&
props.row.status !== 'REPORT' &&
props.row.status !== 'DONE') ||
(checkPermission($route)?.attrIsGet &&
checkPermission($route)?.attrIsDelete) ||
checkPermission($route)?.attrIsGet
"
>
<q-menu
transition-show="jump-down"
transition-hide="jump-up"
>
<q-list dense style="min-width: 100px">
<q-item
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet &&
props.row.status !== 'REPORT' &&
props.row.status !== 'DONE'
"
clickable
v-close-popup
@click="openModalTree(props.row.id, props.row)"
>
<q-item-section style="min-width: 0px" avatar>
<q-icon
color="primary"
size="xs"
name="mdi-bookmark-outline"
/>
</q-item-section>
<q-item-section
>เลือกหน่วยงานที่รับโอน
</q-item-section>
</q-item>
<q-item
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet &&
props.row.status !== 'REPORT' &&
props.row.status !== 'DONE'
"
clickable
v-close-popup
@click="openUpload(props.row.id)"
>
<q-item-section style="min-width: 0px" avatar>
<q-icon size="xs" name="attach_file" color="blue" />
</q-item-section>
<q-item-section>อัปโหลดเอกสาร</q-item-section>
</q-item>
<q-item
v-if="checkPermission($route)?.attrIsGet"
clickable
v-close-popup
@click="nextPage(props.row.id)"
>
<q-item-section style="min-width: 0px" avatar>
<q-tooltip>รายละเอียด</q-tooltip>
<q-icon color="info" size="xs" name="mdi-eye" />
</q-item-section>
<q-item-section>รายละเอียด</q-item-section>
</q-item>
<q-item
v-if="
checkPermission($route)?.attrIsDelete &&
props.row.status !== 'REPORT' &&
props.row.status !== 'DONE'
"
clickable
v-close-popup
@click="openDelete(props.row.id)"
>
<q-item-section style="min-width: 0px" avatar>
<q-tooltip>ลบข้อมูล</q-tooltip>
<q-icon color="red" size="xs" name="mdi-delete" />
</q-item-section>
<q-item-section>ลบ</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else-if="col.name == 'dateOfBirth'">
{{
props.row.dateOfBirth
? date2Thai(props.row.dateOfBirth)
: "-"
}}
</div>
<div
v-else-if="col.name == 'organizationNameOld'"
class="text-html"
>
{{ col.value ? col.value : "-" }}
</div>
<div v-else-if="col.name == 'createdAt'">
{{
props.row.createdAt ? date2Thai(props.row.createdAt) : "-"
}}
</div>
<div v-else-if="col.name == 'organizationName'">
{{ props.row.position !== null ? props.row.position : ""
}}{{
props.row.posLevelName !== null
? `${props.row.posLevelName}`
: ""
}}
{{
props.row.nodeShortName !== null
? `(${props.row.nodeShortName} ${props.row.posMasterNo})`
: ""
}}
<!-- <div>
{{
props.row.positionExecutive !== null
? `${props.row.positionExecutive}${
props.row.positionExecutiveField
? ` (${props.row.positionExecutiveField})`
: ""
}`
: ""
}}
</div> -->
<div class="text-html">
{{ findOrgNameHtml(props.row) }}
</div>
<!-- <div>
{{
props.row.position !== null ? props.row.position : ""
}}{{
(props.row.posTypeName !== null &&
props.row.posTypeName === "บรหาร") ||
props.row.posTypeName === "อำนวยการ"
? `${props.row.posTypeName}`
: ""
}}{{
props.row.posLevelName !== null
? `${props.row.posLevelName}`
: ""
}}
</div>
<div>
{{ props.row.root !== null ? props.row.root : "-" }}
{{
props.row.rootShortName !== null
? `(${props.row.rootShortName})`
: ""
}}
</div>
<div>
{{
props.row.nodeName !== null ? props.row.nodeName : ""
}}
{{
props.row.nodeShortName !== null
? `(${props.row.nodeShortName}${props.row.posMasterNo})`
: ""
}}
</div> -->
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
</div>
</div>
</q-card>
<!-- อัปโหลดเอกสาร -->
<q-dialog v-model="modalupload" persistent>
<q-card style="width: 600px">
<q-form greedy @submit.prevent @validation-success="onSubmitDoc">
<DialogHeader tittle="ปโหลดเอกสาร" :close="clickCloseUpload" />
<q-separator />
<q-card-section class="q-py-sm">
<div class="col-12 row items-center q-col-gutter-sm">
<div class="col-12">
<q-file
outlined
dense
v-model="files"
label="ปโหลดเอกสาร"
lazy-rules
:rules="[
(val:string) => val || 'กรุณาเลือกไฟล์หนังสือถึงหน่วยงานที่รับโอน',
]"
hide-bottom-space
>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
</q-file>
</div>
</div>
</q-card-section>
<q-separator />
<div class="row q-pa-sm">
<q-space />
<q-btn label="นท" color="secondary" type="submit">
<q-tooltip>บันทึก</q-tooltip>
</q-btn>
</div>
</q-form>
</q-card>
</q-dialog>
<!-- ออกคำสั่ง -->
<Dialogbody
v-model:modal="modal"
v-model:filter-keyword2="filterKeyword2"
:click-close="clickClose"
v-model:rows="rows2"
v-model:rowsData="rows2Data"
:fecthlist-recevice="fecthlistRecevice"
:next-page="nextPage"
/>
<!-- เลือกหน่วยงานที่รับโอน -->
<DialogOrgSelect
:title="`เลือกหน่วยงานที่รับโอน`"
v-model:modal="modalTree"
v-model:type="type"
:pos-type="posType"
:pos-level="posLevel"
:position="position"
:data-rows="dataRows"
:onSubmit="onSave"
/>
</template>
<style scoped lang="scss"></style>