hrms-mgt/src/modules/12_evaluatePersonal/views/MainPage.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 490f02309e Refactoring code module 12_evaluatePersonal
2024-09-20 13:13:43 +07:00

317 lines
9.4 KiB
Vue

<script setup lang="ts">
import { onMounted, ref, watch, computed } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { checkPermission } from "@/utils/permissions";
import http from "@/plugins/http";
import config from "@/app.config";
/** importType*/
import type { OptionStatus } from "@/modules/12_evaluatePersonal/interface/index/Main";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
import { useEvalutuonStore } from "@/modules/12_evaluatePersonal/store/Evaluate";
/** use*/
const $q = useQuasar();
const router = useRouter();
const mixin = useCounterMixin();
const store = useEvalutuonStore();
const { showLoader, hideLoader, messageError } = mixin;
/** request body*/
const currentPage = ref<number>(1); //หน้าปัจจุบัน
const maxPage = ref<number>(0); //จำนวนหน่า
const page = ref<number>(1); //หน้า
const total = ref<number>(0); //จำนวนข้อมูลทั้งหมด
const filter = ref<string>(""); //คำค้นหา
const pageSize = ref<number>(10); //จำนวนรายการต่อหน้า
const filterRef = ref<HTMLInputElement | null>(null);
//ค้นหาตามสถานะ
const selectedStatus = ref<string[]>([
"CHECK_SPEC",
"PREPARE_DOC_V1",
"CHECK_DOC_V1",
"WAIT_CHECK_DOC_V1",
"ANNOUNCE_WEB",
"PREPARE_DOC_V2",
"WAIT_CHECK_DOC_V2",
"CHECK_DOC_V2",
]);
//ข้อมูลค้นหาตามสถานะ
const optionsMain = ref<OptionStatus[]>([
{ val: "CHECK_SPEC", label: "ตรวจสอบคุณสมบัติด้วยตนเอง" },
{ val: "PREPARE_DOC_V1", label: "จัดเตรียมเอกสารเล่ม 1" },
{ val: "CHECK_DOC_V1", label: "ตรวจสอบเอกสารเล่ม 1" },
{ val: "WAIT_CHECK_DOC_V1", label: "รอตรวจสอบคุณสมบัติ" },
{ val: "ANNOUNCE_WEB", label: "ประกาศบนเว็บไซต์" },
{ val: "PREPARE_DOC_V2", label: "จัดเตรียมเอกสารเล่ม 2" },
{ val: "WAIT_CHECK_DOC_V2", label: "ตรวจสอบเอกสารเล่ม 2" },
{ val: "CHECK_DOC_V2", label: "รอพิจารณาผลการประเมิน" },
{ val: "DONE", label: "เสร็จสิ้น" },
]);
const options = ref<OptionStatus[]>([]); //ตัวเลือกค้นหาตามสถานะ
/** pagination ของตาราง*/
const initialPagination = ref<any>({
sortBy: null,
descending: false,
page: 1,
rowsPerPage: pageSize,
});
/**
* function อัปเดท paging
* @param initialPagination ข้อมูล pagination
*/
async function updatePagination(initialPagination: any) {
currentPage.value = 1;
pageSize.value = initialPagination.rowsPerPage;
}
/**
* function ค้นหาตาม keyword
*/
function filterFn() {
updatePagination(filter.value);
pageSize.value = initialPagination.value.rowsPerPage;
fetchEvaluteList();
}
/**
* functrion ล้างค้นหาD
*/
function resetFilter() {
filter.value = "";
fetchEvaluteList();
if (filterRef.value) {
filterRef.value.focus();
}
}
/**
* function เรียกรายการคำขอประเมินD
*/
async function fetchEvaluteList() {
showLoader();
const body = {
page: currentPage.value,
pageSize: pageSize.value,
keyword: filter.value,
status: selectedStatus.value,
};
await http
.post(config.API.evaluationMain(), body)
.then(async (res) => {
const data = res.data.result.data;
total.value = res.data.result.total;
maxPage.value = Math.ceil(total.value / pageSize.value);
store.fetchData(data);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/**
* funcition redirectToDetail
* @param id รายการคำขอประเมิน
*/
function Detailpage(id: string) {
router.push(`/evaluate/detail/${id}`);
}
/**
* ชื่อค่าที่ค้นหาสภานะ
*/
const label = computed(() => {
const filterOption = optionsMain.value.filter((option) =>
selectedStatus.value.includes(option.val)
);
const labelval = filterOption.map((e) => e.label);
if (labelval.length !== 0) {
return labelval.length <= 2
? `${labelval.slice(0, 2).join(", ")}`
: `${labelval.slice(0, 2).join(", ")}, อื่นๆ (${labelval.length - 2})`;
} else return "";
});
/**
* function ต้นหาข้อมูลของ Option
* @param val ค่าที่ต้องการฟิลเตอร์
* @param update อัพเดทค่า
* @param refData ดาต้าที่ต้องการฟิลเตอร์
*/
function filterOption(val: string, update: Function) {
update(() => {
options.value = optionsMain.value.filter(
(v: OptionStatus) => v.label.indexOf(val) > -1
);
});
}
/** function callback เมื่อมีการเปลี่ยนหน้า*/
watch(
() => pageSize.value,
() => {
fetchEvaluteList();
}
);
/** HookLifecycle */
onMounted(async () => {
await fetchEvaluteList(); // เรียกข้อมูลรายการปรัเมิน
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
รายการคำขอประเม
</div>
<q-card flat bordered class="col-12 q-mt-sm q-pt-sm q-pa-md">
<div class="row col-12 q-col-gutter-sm q-mb-sm">
<q-select
dense
outlined
multiple
v-model="selectedStatus"
emit-value
map-options
:options="options"
option-value="val"
label="ค้นหาสถานะ"
style="width: 35vw"
@update:model-value="fetchEvaluteList"
use-input
@filter="(inputValue:string,doneFn:Function) => filterOption(inputValue, doneFn) "
>
<template v-slot:selected>
<div>
{{ label }}
</div>
</template>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey"> ไม่มีข้อมูล </q-item-section>
</q-item>
</template>
</q-select>
<q-space />
<q-input
class="col-xs-12 col-sm-3 col-md-2"
id="filterTable"
for="filterTable"
dense
outlined
v-model="filter"
label="ค้นหา"
debounce="300"
@keydown.enter.prevent="filterFn"
>
<template v-slot:append>
<q-icon v-if="filter == ''" name="search" />
<q-icon
v-if="filter !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
</template>
</q-input>
<q-select
id="visibleColumns"
for="visibleColumns"
v-model="store.visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="store.columns"
option-value="name"
options-cover
class="col-xs-12 col-sm-3 col-md-2"
/>
</div>
<div>
<d-table
ref="table"
:columns="store.columns"
:rows="store.rows"
row-key="interrogated"
flat
bordered
:paging="false"
dense
class="custom-header-table"
:visible-columns="store.visibleColumns"
v-model:pagination="initialPagination"
: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 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.stop.prevent="Detailpage(props.row.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'">
{{ (page - 1) * pageSize + props.rowIndex + 1 }}
</div>
<div v-else-if="col.name === 'agency'">
<div class="table_ellipsis">{{ props.row.agency }}</div>
</div>
<div v-else>
{{ col.value ?? "-" }}
</div>
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
ทั้งหมด {{ total }} รายการ
<q-pagination
v-model="currentPage"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchEvaluteList"
></q-pagination>
</template>
</d-table>
</div>
</q-card>
</template>
<style></style>