hrms-user/src/modules/03_retire/views/main.vue

279 lines
8.2 KiB
Vue
Raw Normal View History

2023-07-21 16:34:06 +07:00
<script setup lang="ts">
2024-04-29 14:46:11 +07:00
import type { QTableProps } from "quasar";
2024-09-03 11:48:07 +07:00
import { ref, onMounted, onBeforeMount } from "vue";
2024-04-29 14:46:11 +07:00
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
2024-09-03 11:48:07 +07:00
2024-04-29 14:46:11 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-03 11:48:07 +07:00
import { useCounterMixin } from "@/stores/mixin";
2024-04-29 14:46:11 +07:00
import { useRestDataStore } from "@/modules/03_retire/store";
2023-07-21 16:34:06 +07:00
2024-09-03 11:48:07 +07:00
import type {
MainList,
MainListResponse,
} from "@/modules/03_retire/interface/Main";
2024-04-29 14:46:11 +07:00
const $q = useQuasar();
2024-09-03 11:48:07 +07:00
const router = useRouter();
2024-04-29 14:46:11 +07:00
const mixin = useCounterMixin();
const { date2Thai, messageError, showLoader, hideLoader } = mixin;
2024-09-03 11:48:07 +07:00
const RestData = useRestDataStore();
const { statusText } = RestData; //Func แปลง status to text
2024-04-29 14:46:11 +07:00
2024-09-03 11:48:07 +07:00
const rows = ref<MainList[]>([]);
const filter = ref<string>("");
2024-04-29 14:46:11 +07:00
const pagination = ref({
sortBy: "desc",
descending: false,
page: 1,
rowsPerPage: 10,
});
2023-07-21 16:34:06 +07:00
2024-04-29 14:46:11 +07:00
const visibleColumns = ref<String[]>([
"no",
"placeLeave",
"dateStartLeave",
"dateLeave",
"statustext",
]);
2024-09-03 11:48:07 +07:00
2023-08-09 10:23:41 +07:00
const columns = ref<QTableProps["columns"]>([
2024-04-29 14:46:11 +07:00
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:5%;",
},
{
name: "placeLeave",
align: "left",
label: "สถานที่ยื่นขอลาออกจากราชการ",
sortable: true,
field: "placeLeave",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "dateStartLeave",
align: "left",
label: "วันที่ยื่นขอลาออกจากราชการ",
sortable: true,
field: "dateStartLeave",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "dateLeave",
align: "left",
label: "วันที่ขอลาออกจากราชการ",
sortable: true,
field: "dateLeave",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "statustext",
align: "left",
label: "สถานะ",
sortable: true,
field: "statustext",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:10%;",
},
]);
2024-09-03 11:48:07 +07:00
/** ดึงข้อมูล */
async function fectListleave() {
2024-04-29 14:46:11 +07:00
await http
.get(config.API.listUser())
2024-09-03 11:48:07 +07:00
.then(async (res) => {
let data = await res.data.result;
rows.value = data.map((e: MainListResponse) => ({
2024-04-29 14:46:11 +07:00
id: e.id,
placeLeave: e.location,
dateStartLeave: date2Thai(e.sendDate),
dateLeave: date2Thai(e.activeDate),
status: e.status,
statustext: statusText(e.status),
}));
})
.catch((e: any) => {
messageError($q, e);
})
2024-09-03 11:48:07 +07:00
.finally(() => {});
}
2023-07-21 16:34:06 +07:00
/**
* งกนกดเพมไปหนาเพมลาออก
*/
2024-09-03 11:48:07 +07:00
async function clickAdd() {
2024-04-29 14:46:11 +07:00
router.push(`/retire/add`);
2024-09-03 11:48:07 +07:00
}
/** ทำก่อน mounted */
onBeforeMount(() => {
showLoader();
});
/**
2024-09-03 11:48:07 +07:00
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
2024-09-03 11:48:07 +07:00
onMounted(async () => {
await fectListleave();
hideLoader();
});
2023-07-21 16:34:06 +07:00
</script>
<template>
2024-04-29 14:46:11 +07:00
<div class="col-12 row justify-center">
<div class="col-xs-12 col-sm-12 col-md-11">
2024-09-03 11:48:07 +07:00
<div class="toptitle text-white col-12 row items-center">ขอลาออก</div>
2024-04-29 14:46:11 +07:00
<div class="col-12">
<q-card bordered class="q-pa-md">
<div class="q-pb-sm row">
<div>
<q-btn
size="14px"
flat
dense
color="blue"
@click="clickAdd"
icon="mdi-plus"
>
<q-tooltip>เพมขอม</q-tooltip>
</q-btn>
</div>
<q-space />
<div class="items-center q-gutter-sm" style="display: flex">
<!-- นหาขอความใน table -->
<q-input
standout
dense
v-model="filter"
ref="filterRef"
outlined
debounce="300"
placeholder="ค้นหา"
style="max-width: 200px"
>
<template v-slot:append>
<q-icon v-if="filter == ''" name="search" />
<q-icon
v-if="filter !== ''"
name="clear"
class="cursor-pointer"
@click="filter = ''"
/>
</template>
</q-input>
<!-- แสดงคอลมนใน table -->
<q-select
v-model="visibleColumns"
:display-value="$q.lang.table.columns"
multiple
outlined
dense
:options="columns"
options-dense
option-value="name"
map-options
emit-value
style="min-width: 150px"
class="gt-xs"
>
<template> </template>
</q-select>
</div>
</div>
<div>
<d-table
2024-04-29 14:46:11 +07:00
flat
bordered
dense
row-key="id"
:rows="rows"
:columns="columns"
:visible-columns="visibleColumns"
:rows-per-page-options="[10, 25, 50, 100]"
v-model:pagination="pagination"
>
<template v-slot:pagination="scope">
งหมด {{ rows.length }} รายการ
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="scope.pagesNumber"
:max-pages="5"
size="sm"
boundary-links
direction-links
></q-pagination>
</template>
<template v-slot:header="props">
<q-tr :props="props">
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
style="color: #000000; font-weight: 500"
>
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
@click="router.push(`/retire/` + props.row.id)"
>
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else>
2024-04-29 14:46:11 +07:00
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
<template #item="props">
<div class="q-pa-xs col-xs-12 col-sm-6 col-md-4 col-lg-3">
<q-card
bordered
flat
@click="router.push(`/retire/` + props.row.id)"
>
<q-list>
<q-item
v-for="col in props.cols.filter((col:any) => col.name !== 'desc')"
:key="col.name"
>
<q-item-section>
<q-item-label caption>{{ col.label }}</q-item-label>
<q-item-label v-if="col.name === 'no'">
{{ props.rowIndex + 1 }}
</q-item-label>
<q-item-label v-else>{{ col.value }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-card>
</div>
</template>
</d-table>
2024-04-29 14:46:11 +07:00
</div>
</q-card>
</div>
</div>
</div>
2023-07-21 16:34:06 +07:00
</template>
<style scoped lang="scss"></style>