hrms-mgt/src/modules/12_evaluatePersonal/views/MainPage.vue

334 lines
9.9 KiB
Vue
Raw Normal View History

2023-12-14 10:43:13 +07:00
<script setup lang="ts">
import { onMounted, ref, watch, computed } from "vue";
2023-12-14 10:43:13 +07:00
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import type { OptionStatus } from "@/modules/12_evaluatePersonal/interface/index/Main";
/** importStore*/
2023-12-14 10:43:13 +07:00
import { useCounterMixin } from "@/stores/mixin";
2023-12-15 13:30:39 +07:00
import { useEvalutuonStore } from "@/modules/12_evaluatePersonal/store/Evaluate";
2023-12-14 10:43:13 +07:00
/** use*/
const $q = useQuasar();
2023-12-14 10:43:13 +07:00
const router = useRouter();
const mixin = useCounterMixin();
const store = useEvalutuonStore();
2023-12-14 10:43:13 +07:00
const { showLoader, hideLoader, messageError } = mixin;
2023-12-20 12:43:08 +07:00
const currentPage = ref<number>(1);
const maxPage = ref<number>(0);
2023-12-20 12:43:08 +07:00
const page = ref<number>(1);
const total = ref<number>(0);
2023-12-14 10:43:13 +07:00
const filter = ref<string>("");
const pageSize = ref<number>(10);
/** pagination ของตาราง*/
const initialPagination = ref<any>({
sortBy: null,
2023-12-20 12:43:08 +07:00
descending: false,
page: 1,
rowsPerPage: pageSize,
2023-12-20 12:43:08 +07:00
});
/**
* function ปเดท paging
* @param initialPagination อม pagination
*/
async function updatePagination(initialPagination: any) {
currentPage.value = 1;
pageSize.value = initialPagination.rowsPerPage;
page.value = 1; // set current page เป็น 1 เสมอเมื่อเปลี่ยน per row
}
/** function callback เมื่อมีการเปลี่ยนหน้า*/
2023-12-20 12:43:08 +07:00
watch(
[
() => currentPage.value,
() => (pageSize.value = initialPagination.value.rowsPerPage),
],
async () => {
fetchEvaluteList();
2023-12-20 12:43:08 +07:00
}
);
/** function callback เมื่อมีการเปลี่ยนหน้า*/
2023-12-20 12:43:08 +07:00
watch(
[() => currentPage.value, () => initialPagination.value.rowsPerPage],
async () => {
page.value = currentPage.value;
await fetchEvaluteList();
}
);
/** function callback เมื่อมีการเปลี่ยนจำนวนแถว*/
watch(
() => initialPagination.value.rowsPerPage,
2023-12-20 12:43:08 +07:00
() => {
pageSize.value = initialPagination.value.rowsPerPage;
2023-12-20 12:43:08 +07:00
currentPage.value = 1;
fetchEvaluteList();
2023-12-20 12:43:08 +07:00
}
);
const filterRef = ref<HTMLInputElement | null>(null);
/** function ค้นหาตาม keyword*/
function filterFn() {
updatePagination(filter.value);
pageSize.value = initialPagination.value.rowsPerPage;
fetchEvaluteList();
}
/** functrion ล้างค้นหา*/
function resetFilter() {
filter.value = "";
fetchEvaluteList();
if (filterRef.value) {
filterRef.value.focus();
}
}
/** function เรียกรายการคำขอประเมิน*/
async function fetchEvaluteList() {
const body = {
page: currentPage.value,
pageSize: pageSize.value,
keyword: filter.value,
status: selectedStatus.value,
};
2023-12-20 12:43:08 +07:00
showLoader();
await http
.put(config.API.evaluationMain(), body)
.then(async (res) => {
const data = res.data.result.data;
total.value = res.data.result.total;
maxPage.value = await Math.ceil(total.value / pageSize.value);
maxPage.value = maxPage.value < 1 ? 1 : maxPage.value;
2023-12-20 12:43:08 +07:00
store.fetchData(data);
})
.catch((e) => {
// messageError($q, e);
2023-12-20 12:43:08 +07:00
})
.finally(() => {
hideLoader();
});
}
2023-12-14 10:43:13 +07:00
/**
* funcition redirectToDetail
* @param id รายการคำขอประเม
2023-12-14 10:43:13 +07:00
*/
function Detailpage(id: string) {
router.push(`/evaluate/detail/${id}`);
}
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 options = ref<OptionStatus[]>([]);
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: "รอพิจารณาผลการประเมิน" },
{ val: "CHECK_DOC_V2", label: "ตรวจสอบความถูกต้องของเอกสารเล่ม" },
{ val: "DONE", label: "เสร็จสิ้น" },
]);
/** ชื่อค่าที่ค้นหาสภานะ*/
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: any, update: Function) {
update(() => {
options.value = optionsMain.value.filter(
(v: any) => v.label.indexOf(val) > -1
);
});
}
/** HookLifecycle */
onMounted(async () => {
await fetchEvaluteList(); // เรียกข้อมูลรายการปรัเมิน
});
2023-12-14 10:43:13 +07:00
</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: 28vw"
@update:model-value="fetchEvaluteList"
use-input
@filter="(inputValue:any,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>
2023-12-14 10:43:13 +07:00
<div>
<d-table
ref="table"
2023-12-14 10:43:13 +07:00
: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"
2023-12-14 10:43:13 +07:00
>
<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
></q-pagination>
</template>
<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-th auto-width></q-th>
</q-tr>
</template>
<template v-slot:body="props">
2023-12-14 10:43:13 +07:00
<q-tr :props="props" class="cursor-pointer">
2023-12-26 09:18:03 +07:00
<!-- <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'">
{{ (page - 1) * rowsPerPage + props.rowIndex + 1 }}
</div>
<div v-else>
{{ col.value }}
</div>
2023-12-26 09:18:03 +07:00
</q-td> -->
<q-td auto-width>
<q-icon
v-if="props.row.isDefault === true"
name="mdi-bookmark"
size="xs"
color="primary"
>
<q-tooltip>เวลา Default</q-tooltip>
</q-icon>
</q-td>
2023-12-20 12:43:08 +07:00
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
@click="Detailpage(props.row.id)"
>
2023-12-14 10:43:13 +07:00
<div v-if="col.name == 'no'">
{{ (page - 1) * pageSize + props.rowIndex + 1 }}
2023-12-14 10:43:13 +07:00
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
2023-12-14 10:43:13 +07:00
</div>
</q-card>
</template>
<style></style>