hrms-mgt/src/modules/06_retirement/components/ListRetirement/TableList.vue

605 lines
22 KiB
Vue
Raw Normal View History

2023-07-17 14:56:08 +07:00
<script setup lang="ts">
2023-07-25 18:04:11 +07:00
import { ref, onMounted, computed, watch } from "vue";
2023-07-17 14:56:08 +07:00
import AddList from "../ListRetirement/AddList.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
2023-07-24 15:26:22 +07:00
import { useRoute } from "vue-router";
2023-08-07 11:06:04 +07:00
import { useRouter } from "vue-router";
2023-07-25 09:04:49 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
import DialogHeader from "@/components/DialogHeader.vue";
import DialogPopupReason from "@/components/Dialogs/PopupReason.vue";
2023-07-17 14:56:08 +07:00
2023-07-24 15:26:22 +07:00
const route = useRoute();
2023-08-07 11:06:04 +07:00
const router = useRouter();
2023-07-27 16:59:07 +07:00
const $q = useQuasar();
2023-07-17 14:56:08 +07:00
const mixin = useCounterMixin();
const {
showLoader,
hideLoader,
messageError,
success,
dialogConfirm,
dialogRemove,
} = mixin;
2023-09-15 15:42:23 +07:00
2023-08-07 11:06:04 +07:00
const retireld_params = route.params.retirementId;
2023-07-24 15:26:22 +07:00
const modalNote = ref<boolean>(false);
const note = ref<string>("");
2023-07-25 14:11:16 +07:00
const retireProfileId = ref<string>("");
const retireld = ref<string>(retireld_params.toString());
const profileId = ref<string>("");
2023-07-27 16:59:07 +07:00
const filter = ref<string>("");
const statusUpload = ref<boolean>();
const modalEdit = ref<boolean>(false);
const textReport = ref<string>("");
const employeeType = ref<string>("OFFICER")
const columns = ref<any["columns"]>([])
const rows = ref<any>([]);
2023-07-27 16:59:07 +07:00
const visibleColumns = ref<string[]>([
2023-07-25 14:11:16 +07:00
"order",
2023-07-17 14:56:08 +07:00
"name",
2023-07-25 14:11:16 +07:00
"organizationOrganization",
"positionEmployeePosition",
"positionEmployeeLevel",
"positionEmployeeGroup",
"organizationAgency",
"organizationGovernmentAgency",
2023-07-17 14:56:08 +07:00
"positionNumber",
"govGroup",
"govOffice",
"bureau",
]);
2023-08-07 11:06:04 +07:00
const action = ref<string>("");
const fileUpload = ref<any>(null);
2023-08-07 11:06:04 +07:00
2023-07-27 16:59:07 +07:00
onMounted(() => {
2023-08-07 11:06:04 +07:00
retireld.value = retireld_params.toString();
fecthlistprofile(retireld.value);
2023-07-27 16:59:07 +07:00
});
const closeDialog = () => {
modalNote.value = false;
};
2023-08-07 11:06:04 +07:00
const round = ref<number>();
const typeReport = ref<string>("");
const statusReport = ref<boolean>();
2023-08-07 18:12:26 +07:00
const dataProfile = ref<Object>([]);
2023-07-27 16:59:07 +07:00
// fecthlist
2023-08-07 11:06:04 +07:00
const fecthlistprofile = async (id: string) => {
2023-07-27 16:59:07 +07:00
showLoader();
await http
2023-08-07 11:06:04 +07:00
.get(config.API.listRetire(id))
.then((res) => {
2023-08-07 18:12:26 +07:00
dataProfile.value = res.data.result;
2023-08-07 11:06:04 +07:00
round.value = res.data.result.round;
statusReport.value = res.data.result.json;
2023-08-07 11:06:04 +07:00
typeReport.value = res.data.result.typeReport;
textReport.value = res.data.result.detail;
employeeType.value = res.data.result.type;
// รายชื่อผู้เกษียณอายุราชการ
2023-07-27 16:59:07 +07:00
rows.value = res.data.result.profile.map((e: any) => ({
id: e.id,
profileId: e.profileId,
order: e.order,
name: e.fullName,
organizationOrganization: e.organizationOrganization,
positionEmployeePosition: res.data.result.type == 'OFFICER' ? e.positionType : e.positionEmployeePosition,
positionEmployeeLevel: res.data.result.type == 'OFFICER' ? (e.positionExecutive != null ? e.positionExecutive : "-") : e.positionEmployeeLevel,
positionNumber: res.data.result.type == 'OFFICER' ? e.posNo : e.posNoEmployee,
positionEmployeeGroup: res.data.result.type == 'OFFICER' ? e.position : e.positionEmployeeGroup,
organizationAgency: e.organizationAgency,
organizationGovernmentAgency: e.organizationGovernmentAgency,
2023-07-27 16:59:07 +07:00
bureau: e.oc,
2023-08-07 11:06:04 +07:00
reason: e.reason,
remove: e.remove,
2023-07-27 16:59:07 +07:00
}));
2023-08-23 16:00:32 +07:00
if (statusReport.value == false) {
fecthCheck(retireld.value);
} else statusUpload.value = true;
2023-07-27 16:59:07 +07:00
})
2023-08-07 11:06:04 +07:00
.catch((e) => {
2023-07-27 16:59:07 +07:00
messageError($q, e);
})
.finally(() => {
columns.value = [
{
name: "order",
label: "ลำดับ",
title: "ลำดับ",
field: "order",
align: "left",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ - นามสกุล",
title: "ชื่อ - นามสกุล",
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "organizationOrganization",
align: "left",
label: "สังกัด",
title: "สังกัด",
field: "organizationOrganization",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionEmployeeGroup",
align: "left",
label: employeeType.value == "OFFICER" ? "ตำแหน่ง (ในสายงาน/ระดับ)" : "กลุ่มงาน",
title: employeeType.value == "OFFICER" ? "ตำแหน่ง" : "กลุ่มงาน",
subtitle: employeeType.value == "OFFICER" ? "ในสายงาน/ระดับ" : "",
field: "positionEmployeeGroup",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionEmployeePosition",
align: "left",
label: employeeType.value == "OFFICER" ? "ตำแหน่ง (ประเภท)" : "ตำแหน่ง",
title: employeeType.value == "OFFICER" ? "ตำแหน่ง" : "ตำแหน่ง",
subtitle: employeeType.value == "OFFICER" ? "ประเภท" : "",
field: "positionEmployeePosition",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionEmployeeLevel",
align: "left",
label: employeeType.value == "OFFICER" ? "ตำแหน่ง (ทางการบริหาร)" : "ระดับชั้น",
title: employeeType.value == "OFFICER" ? "ตำแหน่ง" : "ระดับชั้น",
subtitle: employeeType.value == "OFFICER" ? "ทางการบริหาร" : "",
field: "positionEmployeeLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionNumber",
align: "left",
label: "ตำแหน่ง (เลขที่) ",
title: "ตำแหน่ง",
subtitle: "เลขที่",
field: "positionNumber",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "organizationAgency",
align: "left",
label: "ส่วนราชการ (ระดับฝ่าย/กลุ่มงาน/ส่วน)",
title: "ส่วนราชการ",
subtitle: "ระดับฝ่าย/กลุ่มงาน/ส่วน",
field: "organizationAgency",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "organizationGovernmentAgency",
align: "left",
label: "ส่วนราชการ (ระดับสถาบัน/สำนักงาน/กอง)",
title: "ส่วนราชการ",
subtitle: "ระดับสถาบัน/สำนักงาน/กอง",
field: "organizationGovernmentAgency",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "bureau",
align: "left",
label: "หน่วยงาน",
title: "หน่วยงาน",
field: "bureau",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
];
2023-07-27 16:59:07 +07:00
hideLoader();
});
};
// เช็คสถานะการอัพโหลด
const fecthCheck = async (id: string) => {
await http
.get(config.API.checkfileupload(id))
.then((res) => {
statusUpload.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
});
};
2023-07-27 16:59:07 +07:00
// DelProfile
2023-08-07 11:06:04 +07:00
const clickDelete = () => {
dialogRemove(
$q,
async () => {
2023-07-25 09:04:49 +07:00
await http
2023-08-07 11:06:04 +07:00
.post(config.API.removeProfile(), {
retireProfileId: retireProfileId.value,
reason: note.value,
})
2023-07-25 09:04:49 +07:00
.then(() => {
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
2023-07-27 16:59:07 +07:00
.finally(async () => {
2023-08-07 11:06:04 +07:00
retireld.value = retireld_params.toString();
await fecthlistprofile(retireld.value);
modalNote.value = false;
2023-07-25 09:04:49 +07:00
});
},
"ยืนยันการลบข้อมูล",
"ต้องการลบข้อมูลนี้ใช่หรือไม่ ?"
);
2023-07-17 14:56:08 +07:00
};
// แก้ไข้ข้อมูล
2023-07-24 15:26:22 +07:00
const saveNote = () => {
dialogConfirm(
$q,
async () => {
2023-07-25 09:04:49 +07:00
await http
2023-07-25 14:11:16 +07:00
.post(config.API.createnote(), {
retireProfileId: retireProfileId.value,
reason: note.value,
})
2023-07-25 09:04:49 +07:00
.then(() => {
2023-07-25 14:11:16 +07:00
success($q, "บันทึกข้อมูลสำเร็จ");
2023-07-25 09:04:49 +07:00
})
.catch((e) => {
messageError($q, e);
})
2023-07-27 16:59:07 +07:00
.finally(async () => {
2023-08-07 11:06:04 +07:00
retireld.value = retireld_params.toString();
fecthlistprofile(retireld.value);
2023-07-25 14:11:16 +07:00
modalNote.value = false;
2023-07-25 09:04:49 +07:00
});
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการบันทึกข้อมูลนี้ใช่หรือไม่ ?"
);
2023-07-24 15:26:22 +07:00
};
2023-07-27 16:59:07 +07:00
const UpdateListId = (retireld: string, pId: string) => {
profileId.value = pId;
2023-08-07 11:06:04 +07:00
fecthlistprofile(retireld);
2023-07-27 16:59:07 +07:00
};
// กลับหน้าเดิม
2023-07-27 16:59:07 +07:00
const backHistory = () => {
window.history.back();
};
2023-07-25 09:04:49 +07:00
const visibleNote = computed(() => {
if (note.value === "" || note.value === undefined) {
return true;
}
});
// อัปโหลดไฟล์
const uploadFile = async (event: any) => {
showLoader();
const selectedFile = event;
const formdata = new FormData();
formdata.append("file", selectedFile);
await http
.put(config.API.fileRetirement(retireld.value.toString()), formdata)
.then(() => {
success($q, "เพิ่มไฟล์สำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
fileUpload.value = null;
fecthlistprofile(retireld.value);
fecthCheck(retireld.value);
hideLoader();
});
};
// downloadAttachment
const downloadAttachment = async (type: string, id: string) => {
showLoader();
await http
.get(config.API.reportRetireList(type, id), {
responseType: "blob",
})
.then(async (res) => {
downloadFile(res, `${"รายชื่อผู้เกษียณอายุราชการ"}.${type}`);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
// downloadFile
const downloadFile = (response: any, filename: string) => {
const link = document.createElement("a");
var fileName = filename;
link.href = window.URL.createObjectURL(new Blob([response.data]));
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
// ยืนยันการแก้ไขข้อมูล
const saveEdiitReport = (reason: string) => {
const formdata = new FormData();
formdata.append("Detail", reason);
dialogConfirm(
$q,
async () => {
await http
.put(config.API.editDetail(retireld.value), formdata)
.then(() => {
success($q, "แก้ไขข้อความสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
fecthlistprofile(retireld.value);
closemodalEditReport();
});
},
"ยืนยันการแก้ไขข้อมูล",
"ต้องการยืนยันการแก้ไขข้อมูลนี้หรือไม่ ?"
);
};
// เปิด popup เหตุผล
const openmodalEditReport = () => {
modalEdit.value = true;
};
// ปิด popup เหตุผล
const closemodalEditReport = () => {
modalEdit.value = false;
};
2023-07-25 18:04:11 +07:00
const paging = ref<boolean>(true);
const pagination = ref({
sortBy: "order",
2023-07-26 00:57:05 +07:00
descending: false,
2023-07-25 18:04:11 +07:00
page: 1,
rowsPerPage: 10,
});
const paginationLabel = (start: number, end: number, total: number) => {
if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
};
2023-07-17 14:56:08 +07:00
</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="backHistory" />
2023-07-17 16:13:18 +07:00
รายชอผเกษยณอายราชการ
2023-07-17 14:56:08 +07:00
</div>
<div>
<q-card class="col-12 q-pa-md">
<div class="row col-12 q-pb-sm">
<div class="row">
<AddList :dataProfile="dataProfile" :retireld="retireld" :profile-id="profileId" :UpdateListId="UpdateListId"
v-if="statusReport === false &&
(typeReport == 'ADD' || typeReport == '' || typeReport == null) &&
statusUpload !== true
" />
<q-btn color="primary" flat round icon="mdi-dots-vertical">
<q-menu>
<q-list style="min-width: 100px">
<q-item clickable v-close-popup type="a" @click="openmodalEditReport()" target="_blank">
<q-item-section avatar><q-icon color="primary" name="mdi-pencil" /></q-item-section>
<q-item-section>แกไข มต ... </q-item-section>
</q-item>
<q-separator />
<q-item clickable v-close-popup type="a" @click="downloadAttachment('pdf', retireld)" target="_blank">
<q-item-section avatar><q-icon color="red" name="mdi-file-pdf" /></q-item-section>
<q-item-section>ไฟล .PDF</q-item-section>
</q-item>
<q-item clickable v-close-popup type="a" @click="downloadAttachment('docx', retireld)" target="_blank">
<q-item-section avatar><q-icon color="blue" name="mdi-file-word" /></q-item-section>
<q-item-section>ไฟล .docx</q-item-section>
</q-item>
</q-list>
</q-menu>
<q-tooltip>ดาวนโหลดไฟล</q-tooltip>
</q-btn>
<q-file bg-color="white" clearable outlined dense v-model="fileUpload" accept=".pdf"
:style="fileUpload === null ? 'width: 150px' : 'width: auto'" label="อัปโหลดไฟล์"
v-if="statusUpload !== true">
<template v-slot:prepend>
<q-icon color="light-blue" name="attach_file" />
2023-09-04 14:56:00 +07:00
<q-tooltip>ปโหลดไฟล</q-tooltip>
2023-07-17 14:56:08 +07:00
</template>
</q-file>
<q-btn flat round color="light-blue" icon="upload" @click="uploadFile(fileUpload)" v-if="fileUpload !== null" />
</div>
<q-space />
<div class="row">
<q-tabs shrink>
<q-input borderless outlined dense debounce="300" v-model="filter" placeholder="ค้นหา"
style="max-width: 200px" class="q-ml-sm">
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
<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="gt-xs q-ml-sm">
</q-select>
</q-tabs>
</div>
</div>
2023-07-17 14:56:08 +07:00
<div>
<q-table flat dense bordered :rows="rows" :columns="columns" row-key="order" class="custom-header-table"
:filter="filter" :visible-columns="visibleColumns" no-data-label="ไม่มีข้อมูล"
:pagination-label="paginationLabel" v-model:pagination="pagination">
2023-07-17 14:56:08 +07:00
<template v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<div class="text-grey-7 text-weight-medium">
2023-07-27 16:59:07 +07:00
<span class="row">{{ col.title }}</span>
2023-07-17 14:56:08 +07:00
<span class="row" style="font-size: 12px">{{
2023-07-27 16:59:07 +07:00
col.subtitle
2023-07-17 14:56:08 +07:00
}}</span>
</div>
</q-th>
2023-07-27 16:59:07 +07:00
<q-th auto-width />
<q-th auto-width v-if="(typeReport === 'EDIT' ||
typeReport === null ||
typeReport === '') &&
statusReport === false &&
statusUpload !== true
" />
<q-th auto-width v-else></q-th>
<q-th auto-width v-if="(typeReport === 'REMOVE' ||
typeReport === null ||
typeReport === '') &&
statusReport === false &&
statusUpload !== true
" />
<q-th auto-width v-else></q-th>
2023-07-17 14:56:08 +07:00
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer" :style="props.row.profileId === profileId && 'color: #26a69a;'"
@click.stop="router.push(`/registry/${props.row.profileId}`)">
2023-07-25 18:04:11 +07:00
<q-td key="order" :props="props">{{ props.row.order }} </q-td>
<q-td key="name" :props="props">{{ props.row.name }}</q-td>
<q-td class="table_ellipsis" key="organizationOrganization" :props="props">{{
props.row.organizationOrganization }}</q-td>
<q-td key="positionEmployeeGroup" :props="props">{{
props.row.positionEmployeeGroup
}}</q-td>
<q-td key="positionEmployeePosition" :props="props">{{
props.row.positionEmployeePosition
2023-07-17 14:56:08 +07:00
}}</q-td>
<q-td key="positionEmployeeLevel" :props="props">{{
props.row.positionEmployeeLevel
2023-07-17 14:56:08 +07:00
}}</q-td>
2023-07-17 14:56:08 +07:00
<q-td key="positionNumber" :props="props">{{
props.row.positionNumber
}}</q-td>
<q-td key="organizationAgency" :props="props">{{
props.row.organizationAgency
2023-07-17 14:56:08 +07:00
}}</q-td>
<q-td key="organizationGovernmentAgency" :props="props">{{
props.row.organizationGovernmentAgency
2023-07-17 14:56:08 +07:00
}}</q-td>
2023-08-07 11:06:04 +07:00
<q-td class="table_ellipsis" key="bureau" :props="props">{{
props.row.bureau
}}</q-td>
<q-td auto-width></q-td>
<q-td auto-width v-if="(typeReport === 'EDIT' ||
2023-08-07 18:12:26 +07:00
typeReport === null ||
typeReport === '') &&
statusReport === false &&
statusUpload !== true
">
<q-btn flat round color="primary" icon="mdi-pencil" dense @click.stop="
(modalNote = true),
(note = props.row.reason),
(action = 'edit'),
(retireProfileId = props.row.id)
">
2023-08-07 11:06:04 +07:00
<q-tooltip>กรอกเหตผล</q-tooltip>
</q-btn>
</q-td>
<q-td auto-width v-else></q-td>
<q-td auto-width v-if="(typeReport === 'REMOVE' ||
typeReport === null ||
typeReport === '') &&
statusReport === false &&
statusUpload !== true
">
<q-btn flat round class="text-red-14" icon="mdi-delete" dense @click.stop="
(modalNote = true),
(action = 'delete'),
(note = props.row.reason),
(retireProfileId = props.row.id)
"><q-tooltip>ลบขอม</q-tooltip></q-btn>
2023-07-17 14:56:08 +07:00
</q-td>
<q-td auto-width v-else></q-td>
2023-07-17 14:56:08 +07:00
</q-tr>
</template>
2023-07-25 18:04:11 +07:00
<template v-slot:pagination="scope">
<q-pagination v-model="pagination.page" color="primary" :max="scope.pagesNumber" :max-pages="5" size="sm"
boundary-links direction-links></q-pagination>
2023-07-25 18:04:11 +07:00
</template>
2023-07-17 14:56:08 +07:00
</q-table>
</div>
</q-card>
</div>
2023-07-24 15:26:22 +07:00
<!-- note -->
<q-dialog v-model="modalNote">
2023-09-15 15:42:23 +07:00
<q-card style="width: 50vw">
2023-09-14 17:23:30 +07:00
<DialogHeader tittle="กรอกเหตุผล" :close="closeDialog" />
<q-separator />
<q-card-section class="q-pt-none bg-grey-1">
2023-09-14 17:23:30 +07:00
<div class="row q-col-gutter-sm">
<div class="col-12">
<q-input outlined dense lazy-rules v-model="note" :rules="[(val) => !!val || 'กรุณากรอกเหตุผล']"
:label="`${'กรอกเหตุผล'}`" type="textarea" />
2023-09-14 17:23:30 +07:00
</div>
</div>
2023-07-24 15:26:22 +07:00
</q-card-section>
<q-card-actions align="right">
<q-btn v-if="action === 'delete'" label="บันทึก" color="secondary" :disable="visibleNote" @click="clickDelete" />
<q-btn v-else label="บักทึก" color="secondary" @click="saveNote" :disable="visibleNote" />
2023-07-24 15:26:22 +07:00
</q-card-actions>
</q-card>
</q-dialog>
<DialogPopupReason :modal="modalEdit" title="แก้ไขมติ อ.ก.ก." label="มติ อ.ก.ก." :click-close="closemodalEditReport"
:savaForm="saveEdiitReport" :textReport="textReport" />
2023-07-17 14:56:08 +07:00
</template>
<style lang="scss" scope>
.custom-header-table {
max-height: 64vh;
.q-table tr:nth-child(odd) td {
background: white;
}
.q-table tr:nth-child(even) td {
background: #f8f8f8;
}
.q-table thead tr {
background: #ecebeb;
}
.q-table thead tr th {
position: sticky;
z-index: 1;
}
2023-07-17 14:56:08 +07:00
.q-table thead tr:last-child th {
top: 48px;
}
2023-07-17 14:56:08 +07:00
.q-table thead tr:first-child th {
top: 0;
}
}
2023-07-24 15:26:22 +07:00
.q-btn-dropdown__arrow {
display: none;
}
2023-07-17 14:56:08 +07:00
</style>