fix(leave-history):sort
This commit is contained in:
parent
df7d887309
commit
af7ac9e78b
3 changed files with 142 additions and 191 deletions
|
|
@ -1,18 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
import { reactive, ref, onMounted, watch } from "vue";
|
||||
import { reactive, ref, onMounted } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useQuasar } from "quasar";
|
||||
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
import { checkPermission } from "@/utils/permissions";
|
||||
import { updateCurrentPage } from "@/utils/function";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { useLeaveHistoryDataStore } from "@/modules/09_leave/stores/LeaveHistoryStore";
|
||||
import { calculateFiscalYear } from "@/utils/function";
|
||||
import { usePagination } from "@/composables/usePagination";
|
||||
|
||||
import type { QTableColumn } from "quasar";
|
||||
import type { DataPagination } from "@/modules/09_leave/interface/index/Main";
|
||||
import type {
|
||||
DataLeaveType,
|
||||
DataLeaveBeginning,
|
||||
|
|
@ -22,22 +21,21 @@ import DialogForm from "@/modules/09_leave/components/07_LeaveHistory/DialogForm
|
|||
|
||||
const $q = useQuasar();
|
||||
const { leaveTypeData } = storeToRefs(useLeaveHistoryDataStore());
|
||||
const { findYear } = useLeaveHistoryDataStore();
|
||||
const { showLoader, hideLoader, messageError, dialogRemove, success } =
|
||||
useCounterMixin();
|
||||
const { pagination, params, onRequest, checkAndUpdatePage } = usePagination(
|
||||
"",
|
||||
() => onSearchData(false)
|
||||
);
|
||||
|
||||
const formFilter = reactive({
|
||||
year: calculateFiscalYear(new Date()),
|
||||
type: "00000000-0000-0000-0000-000000000000",
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
keyword: "",
|
||||
});
|
||||
const leaveTypeOptions = ref<DataLeaveType[]>([]);
|
||||
|
||||
const rows = ref<DataLeaveBeginning[]>([]);
|
||||
const total = ref<number>(0);
|
||||
const maxPage = ref<number>(0);
|
||||
const columns = ref<QTableColumn[]>([
|
||||
{
|
||||
name: "fullName",
|
||||
|
|
@ -122,13 +120,13 @@ async function fetchDataLeaveBeginning() {
|
|||
await http
|
||||
.post(config.API.leaveBeginning + `/list`, {
|
||||
...formFilter,
|
||||
...params.value,
|
||||
keyword: formFilter.keyword.trim(),
|
||||
})
|
||||
.then((res) => {
|
||||
const data = res.data.result;
|
||||
rows.value = data.data;
|
||||
total.value = data.total;
|
||||
maxPage.value = Math.ceil(data.total / formFilter.pageSize);
|
||||
const result = res.data.result;
|
||||
pagination.value.rowsNumber = result.total;
|
||||
rows.value = result.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
@ -143,7 +141,7 @@ async function onSearchData(newSearch: boolean = true) {
|
|||
try {
|
||||
showLoader();
|
||||
if (newSearch) {
|
||||
formFilter.page = 1;
|
||||
pagination.value.page = 1;
|
||||
}
|
||||
await fetchDataLeaveBeginning();
|
||||
} finally {
|
||||
|
|
@ -188,11 +186,7 @@ function onDeleteLeaveBeginning(id: string) {
|
|||
await http
|
||||
.delete(config.API.leaveBeginning + `/${id}`)
|
||||
.then(async () => {
|
||||
formFilter.page = await updateCurrentPage(
|
||||
formFilter.page,
|
||||
maxPage.value,
|
||||
rows.value.length
|
||||
);
|
||||
await checkAndUpdatePage(rows.value.length);
|
||||
await fetchDataLeaveBeginning();
|
||||
success($q, "ลบข้อมูลสำเร็จ");
|
||||
})
|
||||
|
|
@ -205,29 +199,11 @@ function onDeleteLeaveBeginning(id: string) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันอัปเดทรายการแถวต่อหน้า
|
||||
* @param newPagination ข้อมูล Pagination ใหม่
|
||||
*/
|
||||
function updatePagination(newPagination: DataPagination) {
|
||||
formFilter.pageSize = newPagination.rowsPerPage;
|
||||
}
|
||||
|
||||
/** Hook*/
|
||||
watch(
|
||||
() => formFilter.pageSize,
|
||||
() => {
|
||||
onSearchData(true);
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
showLoader();
|
||||
await fetchLeaveType();
|
||||
await fetchDataLeaveBeginning();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
hideLoader();
|
||||
}
|
||||
|
|
@ -242,67 +218,69 @@ onMounted(async () => {
|
|||
<q-card flat bordered class="q-pa-md">
|
||||
<div class="row q-col-gutter-sm">
|
||||
<div class="col-12">
|
||||
<div class="row q-col-gutter-y-sm">
|
||||
<div class="row q-col-gutter-sm items-center">
|
||||
<datepicker
|
||||
v-model="formFilter.year"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
year-picker
|
||||
:enableTimePicker="false"
|
||||
style="width: 150px"
|
||||
@update:model-value="onSearchData()"
|
||||
>
|
||||
<template #year="{ year }">{{ year + 543 }}</template>
|
||||
<template #year-overlay-value="{ value }">{{
|
||||
parseInt(value + 543)
|
||||
}}</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
dense
|
||||
outlined
|
||||
:model-value="Number(formFilter.year) + 543"
|
||||
:label="`${'ปีงบประมาณ'}`"
|
||||
bg-color="white"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
|
||||
<q-select
|
||||
emit-value
|
||||
map-options
|
||||
outlined
|
||||
dense
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
label="ประเภทการลา"
|
||||
use-input
|
||||
v-model="formFilter.type"
|
||||
hide-selected
|
||||
fill-input
|
||||
:options="leaveTypeOptions"
|
||||
@update:model-value="onSearchData()"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => filterOptionFn(inputValue,doneFn)"
|
||||
>
|
||||
<template v-slot:no-option>
|
||||
<q-item>
|
||||
<q-item-section class="text-grey">
|
||||
ไม่มีข้อมูล
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template>
|
||||
</q-select>
|
||||
<div>
|
||||
<div class="row q-col-gutter-sm">
|
||||
<div class="row q-col-gutter-sm col-xs-12 col-sm-6 col-md-6">
|
||||
<div class="col-xs-12 col-sm-4 col-md-4">
|
||||
<datepicker
|
||||
v-model="formFilter.year"
|
||||
:locale="'th'"
|
||||
autoApply
|
||||
year-picker
|
||||
:enableTimePicker="false"
|
||||
@update:model-value="onSearchData()"
|
||||
>
|
||||
<template #year="{ year }">{{ year + 543 }}</template>
|
||||
<template #year-overlay-value="{ value }">{{
|
||||
parseInt(value + 543)
|
||||
}}</template>
|
||||
<template #trigger>
|
||||
<q-input
|
||||
dense
|
||||
outlined
|
||||
:model-value="Number(formFilter.year) + 543"
|
||||
:label="`${'ปีงบประมาณ'}`"
|
||||
bg-color="white"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
style="color: var(--q-primary)"
|
||||
>
|
||||
</q-icon>
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
</datepicker>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-7 col-md-4">
|
||||
<q-select
|
||||
emit-value
|
||||
map-options
|
||||
outlined
|
||||
dense
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
label="ประเภทการลา"
|
||||
use-input
|
||||
v-model="formFilter.type"
|
||||
hide-selected
|
||||
fill-input
|
||||
:options="leaveTypeOptions"
|
||||
@update:model-value="onSearchData()"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => filterOptionFn(inputValue,doneFn)"
|
||||
>
|
||||
<template v-slot:no-option>
|
||||
<q-item>
|
||||
<q-item-section class="text-grey">
|
||||
ไม่มีข้อมูล
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template>
|
||||
</q-select>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-1 col-md-4 items-center">
|
||||
<q-btn
|
||||
v-if="checkPermission($route)?.attrIsCreate"
|
||||
dense
|
||||
|
|
@ -318,39 +296,42 @@ onMounted(async () => {
|
|||
</div>
|
||||
|
||||
<q-space />
|
||||
<div class="row q-col-gutter-sm">
|
||||
<q-input
|
||||
standout
|
||||
dense
|
||||
v-model="formFilter.keyword"
|
||||
outlined
|
||||
placeholder="ค้นหา"
|
||||
@keydown.enter.prevent="onSearchData()"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</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"
|
||||
style="min-width: 140px"
|
||||
/>
|
||||
<div class="row q-col-gutter-sm col-xs-12 col-sm-6 col-md-6">
|
||||
<div class="col-xs-12 col-sm-7 col-md-8">
|
||||
<q-input
|
||||
standout
|
||||
dense
|
||||
v-model="formFilter.keyword"
|
||||
outlined
|
||||
placeholder="ค้นหา"
|
||||
@keydown.enter.prevent="onSearchData()"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</q-input>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-5 col-md-4">
|
||||
<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"
|
||||
style="min-width: 140px"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<d-table
|
||||
<p-table
|
||||
ref="table"
|
||||
:columns="columns"
|
||||
:rows="rows"
|
||||
|
|
@ -360,7 +341,8 @@ onMounted(async () => {
|
|||
dense
|
||||
class="custom-header-table"
|
||||
:visible-columns="visibleColumns"
|
||||
@update:pagination="updatePagination"
|
||||
v-model:pagination="pagination"
|
||||
@request="onRequest"
|
||||
>
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
|
|
@ -409,21 +391,7 @@ onMounted(async () => {
|
|||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
<template v-slot:pagination="scope">
|
||||
ทั้งหมด {{ total.toLocaleString() }} รายการ
|
||||
<q-pagination
|
||||
v-model="formFilter.page"
|
||||
active-color="primary"
|
||||
color="dark"
|
||||
:max="Number(maxPage)"
|
||||
size="sm"
|
||||
boundary-links
|
||||
direction-links
|
||||
:max-pages="5"
|
||||
@update:model-value="onSearchData(false)"
|
||||
></q-pagination>
|
||||
</template>
|
||||
</d-table>
|
||||
</p-table>
|
||||
</div>
|
||||
</div>
|
||||
</q-card>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue