hrms-mgt/src/modules/04_registryPerson/components/requestEdit/01_TabInformation.vue

325 lines
9.2 KiB
Vue
Raw Normal View History

2024-09-26 13:46:04 +07:00
<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { useQuasar } from "quasar";
import { useRequestEditStore } from "@/modules/04_registryPerson/stores/RequestEdit";
import { useCounterMixin } from "@/stores/mixin";
2024-11-06 17:54:50 +07:00
import { useRouter, useRoute } from "vue-router";
2024-10-01 10:43:52 +07:00
import config from "@/app.config";
import http from "@/plugins/http";
2024-09-26 13:46:04 +07:00
2024-10-01 10:43:52 +07:00
/** importType*/
2024-09-26 13:46:04 +07:00
import type { QTableProps } from "quasar";
import type {
DataOption,
Pagination,
2024-10-18 12:06:01 +07:00
Request,
2024-09-26 13:46:04 +07:00
} from "@/modules/04_registryPerson/interface/index/Main";
2024-10-18 12:06:01 +07:00
import type { DataRequest } from "@/modules/04_registryPerson/interface/response/Main";
2024-09-26 13:46:04 +07:00
const $q = useQuasar();
2024-10-18 12:06:01 +07:00
const router = useRouter();
2024-11-06 17:54:50 +07:00
const route = useRoute();
2024-09-26 13:46:04 +07:00
const store = useRequestEditStore();
const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin();
2024-11-06 17:54:50 +07:00
const routerName = ref<string>(route.name as string);
2024-10-01 10:43:52 +07:00
//Table
2024-10-18 12:06:01 +07:00
const rows = ref<DataRequest[]>([]); //รายการข้อมูลคำร้องขอแก้ไขทะเบียนประวัติ
2024-09-26 13:46:04 +07:00
const page = ref<number>(1); //หน้า
const pageSize = ref<number>(10); //จำนวนต่อหน้า
const rowsTotal = ref<number>(0); //จำนวนรายการ
const maxPage = ref<number>(0); //จำนวนหน้า
const columns = ref<QTableProps["columns"]>([
{
name: "createdAt",
align: "left",
label: "วันที่ยื่นขอ",
sortable: false,
2024-09-26 13:46:04 +07:00
field: "createdAt",
format: (v) => (v ? date2Thai(v, false, true) : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "fullname",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: false,
field: "fullname",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "topic",
align: "left",
label: "ชื่อเรื่อง",
sortable: false,
2024-09-26 13:46:04 +07:00
field: "topic",
format: (v) => (v ? v : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "detail",
align: "left",
label: "รายละเอียด",
sortable: false,
2024-09-26 13:46:04 +07:00
field: "detail",
format: (v) => (v ? v : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "status",
align: "left",
label: "สถานะคำร้อง",
sortable: false,
2024-09-26 13:46:04 +07:00
field: "status",
format: (v) => store.convertStatus(v),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "remark",
align: "left",
label: "หมายเหตุ",
sortable: false,
2024-09-26 13:46:04 +07:00
field: "remark",
format: (v) => (v ? v : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const visibleColumns = ref<string[]>([
"createdAt",
"fullname",
"topic",
"detail",
"status",
"remark",
]);
2024-10-01 10:43:52 +07:00
//ตัวแปร
2024-09-26 13:46:04 +07:00
const status = ref<string>("PENDING"); //ค้นหาตามสถานะ
const keyword = ref<string>(""); //คำค้นหา
const statusOption = ref<DataOption[]>(store.optionStatus); //รายการสถานะ
const requestId = ref<string>(""); //id รายการแก้ไข
2024-10-01 10:43:52 +07:00
/** function fetch รายการคำร้องขอแก้ไขทะเบียนประวัติ*/
async function fetchListRequset() {
2024-09-26 13:46:04 +07:00
showLoader();
await http
2024-11-06 17:54:50 +07:00
.get(
config.API.requestEditByType(
routerName.value == "registryNewRequestEditEMP" ? "-employee" : ""
) + `admin`,
{
params: {
page: page.value,
pageSize: pageSize.value,
status: status.value,
keyword: keyword.value.trim(),
2024-11-06 17:54:50 +07:00
},
}
)
2024-09-26 13:46:04 +07:00
.then((res) => {
const data = res.data.result;
maxPage.value = Math.ceil(data.total / pageSize.value);
rowsTotal.value = data.total;
rows.value = data.data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
2024-10-01 10:43:52 +07:00
/** function เลือกสถานะคำร้อง*/
2024-09-26 13:46:04 +07:00
function updateStatusValue() {
page.value = 1;
// fetch รายการคำร้องขอแก้ไขทะเบียนประวัติ
fetchListRequset();
}
2024-10-01 10:43:52 +07:00
/** function เคลียร์ สถานะคำร้อง*/
2024-09-26 13:46:04 +07:00
function clearStatus() {
status.value = "";
statusOption.value = store.optionStatus;
}
/**
* function นหาคำใน select สถานะคำรอง
* @param val คำค
* @param update Function
*/
function filterOption(val: string, update: Function) {
update(() => {
statusOption.value = store.optionStatus.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
}
/**
* funciton แกไขคำรอง
* @param id รายการคำรอง
*/
2024-10-18 12:06:01 +07:00
function onclickEdit(data: Request) {
requestId.value = data.id;
2024-11-01 17:25:19 +07:00
store.profileId = data.profileId;
2024-11-06 17:54:50 +07:00
if (routerName.value === "registryNewRequestEditEMP") {
router.push(`/registry-employee/request-edit/personal/${data.id}`);
} else {
router.push(`/registry-officer/request-edit/personal/${data.id}`);
}
2024-09-26 13:46:04 +07:00
}
/**
* function เลอกแถวตอหน
* @param newPagination
*/
function updatePageSizePagination(newPagination: Pagination) {
page.value = 1;
pageSize.value = newPagination.rowsPerPage;
}
/**
* การเปลยนแปลงของ pageSize
* เมอมการเปลยนแปลงจำทำการ งชอมลรายการคำรองขอแกไขทะเบยนประวตามจำนวน pageSize
*/
watch(
() => pageSize.value,
() => {
fetchListRequset();
}
);
2024-10-04 16:44:30 +07:00
/** HooK lifecycle ทำงานเมื่อมีการเรียกใช้งาน Componenets */
2024-09-26 13:46:04 +07:00
onMounted(() => {
fetchListRequset();
});
</script>
<template>
<q-card class="q-pa-md">
<div class="row q-mb-sm q-col-gutter-sm">
2024-11-05 16:33:46 +07:00
<div class="col-xs-12 col-sm-3 col-md-3">
2024-09-26 13:46:04 +07:00
<q-select
2024-11-05 16:33:46 +07:00
style="min-width: 250px"
2024-09-26 13:46:04 +07:00
v-model="status"
label="สถานะคำร้อง"
dense
outlined
emit-value
map-options
option-label="name"
option-value="id"
hide-selected
fill-input
2024-09-26 13:46:04 +07:00
:options="statusOption"
@update:model-value="updateStatusValue"
:clearable="status !== ''"
@clear="clearStatus"
use-input
@filter="(inputValue:string,
doneFn:Function) => filterOption(inputValue, doneFn
) "
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey"> ไมอม </q-item-section>
</q-item>
</template>
</q-select>
</div>
<q-space />
<q-input
v-model="keyword"
outlined
dense
label="ค้นหา"
2024-11-05 16:33:46 +07:00
style="min-width: 250px"
2025-05-23 11:47:17 +07:00
@keydown.enter.prevent="updateStatusValue()"
2024-09-26 13:46:04 +07:00
>
<template v-slot:append>
<q-icon name="search" />
</template>
2024-09-26 13:46:04 +07:00
</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"
2024-11-05 16:33:46 +07:00
style="min-width: 140px"
2024-09-26 13:46:04 +07:00
/>
</div>
<div class="col-12">
<d-table
:columns="columns"
:rows="rows"
row-key="id"
:rows-per-page-options="[10, 25, 50, 100]"
:paging="true"
:visible-columns="visibleColumns"
@update:pagination="updatePageSizePagination"
>
<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
2024-10-21 16:04:31 +07:00
icon="edit"
2024-09-26 13:46:04 +07:00
round
dense
flat
2024-10-21 16:04:31 +07:00
color="edit
"
2025-07-09 10:38:40 +07:00
@click.prevent="onclickEdit(props.row)"
2024-09-26 13:46:04 +07:00
>
2024-10-21 16:04:31 +07:00
<q-tooltip>แกไขสถานะคำรอง</q-tooltip>
2024-09-26 13:46:04 +07:00
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
2024-10-25 16:25:22 +07:00
{{ col.value ? col.value : "-" }}
2024-09-26 13:46:04 +07:00
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
2025-04-25 17:01:48 +07:00
งหมด {{ rowsTotal.toLocaleString() }} รายการ
2024-09-26 13:46:04 +07:00
<q-pagination
v-model="page"
active-color="primary"
color="dark"
:max="Number(maxPage)"
:max-pages="5"
size="sm"
boundary-links
direction-links
@update:model-value="fetchListRequset()"
></q-pagination>
</template>
</d-table>
</div>
</q-card>
</template>
<style scoped></style>