hrms-mgt/src/modules/09_leave/components/2_Leave/ToolBarLeave.vue

270 lines
7 KiB
Vue
Raw Normal View History

2023-10-20 16:57:32 +07:00
<script setup lang="ts">
2023-11-17 15:28:03 +07:00
import { ref, reactive, onMounted } from "vue";
import type { DateFilter } from "@/modules/09_leave/interface/request/leave";
import type {
DataOption,
DataOption2,
} from "@/modules/09_leave/interface/index/Main";
/** importStores*/
2023-10-20 16:57:32 +07:00
import { useLeavelistDataStore } from "@/modules/09_leave/stores/LeaveStore";
const leaveStore = useLeavelistDataStore();
2023-11-17 15:28:03 +07:00
const props = defineProps({
rowsPerPage: {
type: Number,
require: true,
},
});
2023-11-17 15:28:03 +07:00
const emit = defineEmits(["update:querySting"]);
/** formFilter*/
const filter = reactive<DateFilter>({
year: new Date().getFullYear(), //*ปีในการยื่นขอใบลา(ใช้เป็น คศ.)
2023-11-17 15:28:03 +07:00
type: "00000000-0000-0000-0000-000000000000", //*Id ประเภทการลา
status: "ALL", //*สถานะการของลา
keyword: "", //keyword ค้นหา
});
/**
* function update อมลการคนหา (QuerySting)
* @param newPage หน
* @param pageSize อมลตอแถว
* @param dateFilter อม Filter
*/
function updateQuerySting(
newPage: number,
pageSize: number,
dateFilter: DateFilter
) {
// ส่ง event ไปยัง parent component เพื่ออัพเดทค่า props
emit("update:querySting", newPage, pageSize, dateFilter);
}
/** function ค้นหาข้อมูลใน Table*/
async function filterListLeave() {
console.log("test");
// filter.status &&
// filter.type &&
// (await updateQuerySting(1, Number(props.rowsPerPage), filter));
2023-11-17 15:28:03 +07:00
}
/** Option*/
const optionType = ref<DataOption[]>([
{
id: "00000000-0000-0000-0000-000000000000",
name: "ทั้งหมด",
},
]);
const optionStatus = ref<DataOption[]>([
{
id: "ALL",
name: "ทั้งหมด",
},
{
id: "NEW",
name: "ใหม่",
},
{
id: "PENDING ",
name: "กำลังดำเนินการ",
},
{
id: "APPROVE ",
name: "อนุมัติ",
},
{
id: "REJECT ",
name: "ไม่อนุมัติ",
},
]);
const optionStatus2 = ref<DataOption[]>([
{
id: "ALL",
name: "ทั้งหมด",
},
{
id: "NEW",
name: "ขอยกเลิก",
},
{
id: "PENDING ",
name: "อนุมัติ",
},
{
id: "APPROVE ",
name: "ไม่อนุมัติ",
},
]);
2023-11-17 15:28:03 +07:00
const optionTypeMain = ref<DataOption[]>(optionType.value);
const optionStatusMain = ref<DataOption[]>(
leaveStore.tabMenu == "1" ? optionStatus.value : optionStatus2.value
);
2023-11-17 15:28:03 +07:00
async function fetchOption() {
console.log("loadOption รอ API");
}
/**
* งกนคนหาขอมลของ Option Filter
* @param val คำทนหา
* @param update Function
* @param name ประเภทของ Select
*/
function filterOption(val: string, update: any, name: string) {
update(() => {
const needle = val.toLowerCase();
if (name === "type") {
optionType.value = optionTypeMain.value.filter(
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
} else if (name === "status") {
optionStatus.value = optionStatusMain.value.filter(
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
}
});
}
onMounted(async () => {
await fetchOption();
// optionTypeMain.value =
// leaveStore.tabMenu == "1" ? optionStatus.value : optionStatus2.value;
2023-11-17 15:28:03 +07:00
});
2023-10-20 16:57:32 +07:00
</script>
<template>
<div class="row col-12 q-col-gutter-sm q-mb-sm">
<div class="col-xs-12 col-sm-3 col-md-2">
<datepicker
menu-class-name="modalfix"
v-model="filter.year"
class="col-2"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
@update:model-value="filterListLeave"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
:model-value="Number(filter.year) + 543"
:label="`${'ปีงบประมาณ'}`"
>
<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
for="selectYear"
2023-10-20 16:57:32 +07:00
emit-value
map-options
outlined
dense
2023-11-17 15:28:03 +07:00
v-model="filter.year"
:options="optionStatus"
2023-10-20 16:57:32 +07:00
option-value="id"
option-label="name"
label="ปีงบประมาณ"
2023-11-17 15:28:03 +07:00
@update:model-value="filterListLeave"
/> -->
2023-10-20 16:57:32 +07:00
</div>
<div class="col-xs-12 col-sm-3 col-md-2">
2023-10-20 16:57:32 +07:00
<q-select
for="selectType"
2023-10-20 16:57:32 +07:00
emit-value
map-options
outlined
dense
2023-11-17 15:28:03 +07:00
v-model="filter.type"
:options="optionType"
2023-10-20 16:57:32 +07:00
option-value="id"
option-label="name"
label="ประเภทการลา"
2023-11-17 15:28:03 +07:00
@update:model-value="filterListLeave"
2023-10-20 16:57:32 +07:00
use-input
@filter="
(inputValue:any, doneFn:Function) =>
filterOption(inputValue, doneFn, 'type')
"
>
<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-3 col-md-2">
2023-10-20 16:57:32 +07:00
<q-select
for="selectStatus"
2023-10-20 16:57:32 +07:00
emit-value
map-options
outlined
dense
2023-11-17 15:28:03 +07:00
v-model="filter.status"
:options="optionStatus"
2023-10-20 16:57:32 +07:00
option-value="id"
option-label="name"
label="สถานะ"
2023-11-17 15:28:03 +07:00
@update:model-value="filterListLeave"
2023-10-20 16:57:32 +07:00
use-input
@filter="
(inputValue:any, doneFn:Function) =>
filterOption(inputValue, doneFn, 'status')
"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey"> ไมอม </q-item-section>
</q-item>
</template></q-select
>
2023-10-20 16:57:32 +07:00
</div>
<q-space />
<div class="col-xs-12 col-sm-3 col-md-2">
<q-input
for="filterTable"
dense
outlined
2023-11-17 15:28:03 +07:00
v-model="filter.keyword"
label="ค้นหา"
2023-11-17 15:28:03 +07:00
@keydown.enter.prevent="filterListLeave"
/>
2023-10-20 16:57:32 +07:00
</div>
<div class="col-xs-12 col-sm-3 col-md-2">
2023-10-20 16:57:32 +07:00
<q-select
for="visibleColumns"
2023-10-20 16:57:32 +07:00
v-model="leaveStore.visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="leaveStore.columns"
option-value="name"
options-cover
/>
</div>
</div>
</template>