hrms-mgt/src/modules/12_evaluatePersonal/components/Director/MainPage.vue

333 lines
8.8 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, useAttrs, onMounted, watch } from "vue";
import type { QTableProps } from "quasar";
import router from "@/router";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
2023-12-19 15:05:48 +07:00
import { useEvaluateDirectorDataStore } from "@/modules/12_evaluatePersonal/store/DirectorStore";
import http from "@/plugins/http";
import config from "@/app.config";
const $q = useQuasar();
2023-12-19 15:05:48 +07:00
const dataStore = useEvaluateDirectorDataStore();
const mixin = useCounterMixin();
const {
messageError,
showLoader,
hideLoader,
dialogConfirm,
dialogRemove,
success,
} = mixin;
const currentPage = ref<number>(1);
const maxPage = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
/**
*pagination ของตาราง
*/
const pagination = ref({
descending: false,
page: page.value,
rowsPerPage: rowsPerPage.value,
});
2023-12-19 15:05:48 +07:00
watch(
() => currentPage.value,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
getList();
}
);
2023-12-19 15:05:48 +07:00
watch(
() => pagination.value.rowsPerPage,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
currentPage.value = 1;
getList();
}
);
function getList() {
// showLoader();
// http
// .get(
// config.API.evaluateDirectorMain(
// currentPage.value,
// rowsPerPage.value,
// filterKeyword.value
// )
// )
// .then((res) => {
// maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value);
// const data = res.data.result.data
// dataStore.fetchData(data);
// })
// .catch((e) => {
// messageError($q, e);
// })
// .finally(() => {
// hideLoader();
// });
// {
// "Id": "0a185476-c764-42d7-a6f9-2c3824a401ed",
// "CreatedAt": "2023-12-19T02:40:59.898Z",
// "CreatedUserId": "59134ef9-9e62-41d0-aac5-339be727f2b0",
// "LastUpdatedAt": "2023-12-19T02:40:59.898Z",
// "LastUpdateUserId": "59134ef9-9e62-41d0-aac5-339be727f2b0",
// "CreatedFullName": "สาวิตรี ศรีสมัย",
// "LastUpdateFullName": "สาวิตรี ศรีสมัย",
// "Prefix": "นาย",
// "FirstName": "เทสดี",
// "LastName": "ลองแอด",
// "Phone": "0999998767",
// "Email": "email@gmail.com",
// "Position": "frontEnd"
// }
const data = [
{
Id: "xx1",
CreatedAt: "2023-12-19T02:40:59.898Z",
CreatedUserId: "cc1",
LastUpdatedAt: "2023-12-19T02:40:59.898Z",
LastUpdateUserId: "ll1",
CreatedFullName: "สาวิตรี ศรีสมัย",
LastUpdateFullName: "สาวิตรี ศรีสมัย",
Prefix: "นาย",
FirstName: "เทสดี",
LastName: "ลองแอด",
Phone: "0999998767",
Email: "email@gmail.com",
Position: "frontEnd",
},
{
Id: "xx2",
CreatedAt: "2023-12-19T02:40:59.898Z",
CreatedUserId: "cc2",
LastUpdatedAt: "2023-12-19T02:40:59.898Z",
LastUpdateUserId: "ll2",
CreatedFullName: "สาวิตรี ศรีสมัย",
LastUpdateFullName: "สาวิตรี ศรีสมัย",
Prefix: "นาย",
FirstName: "เทสดี",
LastName: "ลองแอด",
Phone: "0999998767",
Email: "email@gmail.com",
Position: "frontEnd",
},
{
Id: "xx3",
CreatedAt: "2023-12-19T02:40:59.898Z",
CreatedUserId: "cc3",
LastUpdatedAt: "2023-12-19T02:40:59.898Z",
LastUpdateUserId: "ll3",
CreatedFullName: "สาวิตรี ศรีสมัย",
LastUpdateFullName: "สาวิตรี ศรีสมัย",
Prefix: "นาย",
FirstName: "เทสดี",
LastName: "ลองแอด",
Phone: "0999998767",
Email: "email@gmail.com",
Position: "frontEnd",
},
{
Id: "xx4",
CreatedAt: "2023-12-19T02:40:59.898Z",
CreatedUserId: "cc5",
LastUpdatedAt: "2023-12-19T02:40:59.898Z",
LastUpdateUserId: "ll5",
CreatedFullName: "สาวิตรี ศรีสมัย",
LastUpdateFullName: "สาวิตรี ศรีสมัย",
Prefix: "นาย",
FirstName: "เทสดี",
LastName: "ลองแอด",
Phone: "0999998767",
Email: "email@gmail.com",
Position: "frontEnd",
},
];
dataStore.fetchData(data);
}
/**
* ลบขอม
* @param id ไอดของขอม
*/
function clickDelete(id: string) {
dialogRemove($q, async () => deleteData(id), `ลบข้อมูล`);
}
/**
* ลบขอม
* @param id type
*/
async function deleteData(id: string) {
showLoader();
await http
2023-12-19 15:05:48 +07:00
.delete(config.API.evaluateDirectorById(id))
.then((res) => {
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await getList();
});
}
/**
* นหาในตาราง
*/
const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null);
2023-12-19 15:05:48 +07:00
function resetFilter() {
filterKeyword.value = "";
if (filterRef.value) {
filterRef.value.focus();
}
}
2023-12-19 15:05:48 +07:00
function filterFn() {
getList();
console.log("enter", filterKeyword.value);
}
2023-12-19 15:05:48 +07:00
onMounted(() => {
getList();
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
รายการชอกรรมการ
</div>
<q-card flat bordered class="col-12 q-mt-sm q-pa-md">
<div class="row col-12 q-col-gutter-sm q-mb-sm">
<div>
<q-btn
@click="router.push(`/evaluate/director/add`)"
size="12px"
flat
round
color="add"
icon="mdi-plus"
>
<q-tooltip>เพมรายชอกรรมการ</q-tooltip>
</q-btn>
</div>
<q-space />
<q-input
class="col-xs-12 col-sm-3 col-md-2"
standout
dense
v-model="filterKeyword"
ref="filterRef"
outlined
debounce="300"
placeholder="ค้นหา"
@keydown.enter.prevent="filterFn"
>
<template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" />
<q-icon
v-if="filterKeyword !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
</template>
</q-input>
<q-select
v-model="dataStore.visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="dataStore.columns"
option-value="name"
options-cover
style="min-width: 150px"
class="col-xs-12 col-sm-3 col-md-2"
/>
</div>
<div class="col-12">
<d-table
:columns="dataStore.columns"
:rows="dataStore.rows"
:filter="filterKeyword"
row-key="tb-list"
flat
bordered
:paging="true"
dense
v-model:pagination="pagination"
:visible-columns="dataStore.visibleColumns"
>
<template v-slot:pagination="scope">
<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 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-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(`/evaluate/director/${props.row.id}`)"
>
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
<q-td auto-width>
<q-btn
dense
size="12px"
flat
round
color="red"
@click="clickDelete(props.row.id)"
icon="mdi-delete"
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
</div>
</q-card>
</template>