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

319 lines
8.4 KiB
Vue
Raw Normal View History

2023-10-20 16:57:32 +07:00
<script setup lang="ts">
2024-09-18 17:26:53 +07:00
import { ref, watch } from "vue";
2024-01-11 15:50:34 +07:00
import { useQuasar } from "quasar";
2023-11-17 15:28:03 +07:00
2024-10-31 11:00:25 +07:00
import type {
DateFilter,
QuerySting,
} from "@/modules/09_leave/interface/request/leave";
2024-01-11 15:50:34 +07:00
import type { DataOption } from "@/modules/09_leave/interface/index/Main";
/** importStores*/
2023-10-20 16:57:32 +07:00
import { useLeavelistDataStore } from "@/modules/09_leave/stores/LeaveStore";
2024-10-31 11:00:25 +07:00
const querySting = defineModel<QuerySting>("querySting", { required: true });
2024-01-11 15:50:34 +07:00
const $q = useQuasar();
2024-09-18 17:26:53 +07:00
const leaveStore = useLeavelistDataStore();
2023-11-17 15:28:03 +07:00
const props = defineProps({
2024-07-30 16:50:08 +07:00
dataToobar: Array,
2024-10-31 11:00:25 +07:00
getSearch: Function,
getList: Function,
});
2023-11-17 15:28:03 +07:00
/** Option*/
const roleMainOp = ref<DataOption[]>([
{ id: "OFFICER", name: "ข้าราชการ กทม. สามัญ" },
{ id: "EMPLOYEE", name: "ลูกจ้างประจำ กทม." },
]);
const roleOp = ref<DataOption[]>();
const optionTypeMain = ref<DataOption[]>([]);
const optionType = ref<DataOption[]>([]);
2023-11-17 15:28:03 +07:00
const optionStatus = ref<DataOption[]>([
{
id: "ALL",
name: "ทั้งหมด",
},
{
id: "NEW",
name: "ใหม่",
},
{
2023-12-14 15:31:19 +07:00
id: "PENDING",
2023-11-17 15:28:03 +07:00
name: "กำลังดำเนินการ",
},
{
2023-12-14 15:31:19 +07:00
id: "APPROVE",
2023-11-17 15:28:03 +07:00
name: "อนุมัติ",
},
{
2023-12-14 15:31:19 +07:00
id: "REJECT",
2023-11-17 15:28:03 +07:00
name: "ไม่อนุมัติ",
},
]);
const optionStatus2 = ref<DataOption[]>([
{
id: "ALL",
name: "ทั้งหมด",
},
{
id: "NEW",
name: "ใหม่",
},
{
id: "APPROVE",
name: "อนุมัติ",
},
{
id: "REJECT",
name: "ไม่อนุมัติ",
},
]);
const optionStatusMain = ref<DataOption[]>(
leaveStore.tabMenu == "1" ? optionStatus.value : optionStatus2.value
);
2023-11-17 15:28:03 +07:00
/**
* งกนคนหาขอมลของ 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
);
}
});
}
/**
* function นหาขอมลใน option
* @param val คำคนหา
* @param update function
*/
function filterOptionFn(val: string, update: Function) {
update(() => {
const data = roleMainOp.value;
roleOp.value = data.filter((e: any) => e.name.search(val) !== -1);
});
}
2024-07-30 16:50:08 +07:00
watch(
async () => props.dataToobar,
() => {
if (props.dataToobar) {
const data = props.dataToobar;
leaveStore.leaveType = data;
optionTypeMain.value = [
{ id: "00000000-0000-0000-0000-000000000000", name: "ทั้งหมด" },
];
const option = data.map((e: any) => ({
id: e.id,
name: e.name,
}));
2024-09-03 11:28:01 +07:00
2024-07-30 16:50:08 +07:00
optionTypeMain.value.push(...option);
optionType.value = optionTypeMain.value;
}
}
);
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">
<q-select
emit-value
map-options
outlined
dense
option-value="id"
option-label="name"
label="ประเภทตำแหน่ง"
use-input
:model-value="
querySting.profileType == 'ALL' ? 'ทั้งหมด' : querySting.profileType
"
hide-selected
fill-input
:options="roleOp"
@update:model-value="(value:any)=>(querySting.profileType = value,props.getSearch?.())"
@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>
<template v-if="querySting.profileType !== 'ALL'" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="
(querySting.profileType = 'ALL'), props.getSearch?.()
"
class="cursor-pointer"
/>
</template>
</q-select>
</div>
<div class="col-xs-12 col-sm-3 col-md-1">
<datepicker
menu-class-name="modalfix"
2024-10-31 11:00:25 +07:00
v-model="querySting.year"
class="col-2"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
2024-10-31 11:00:25 +07:00
@update:model-value="props.getSearch?.()"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
outlined
2024-10-31 11:00:25 +07:00
:model-value="Number(querySting.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>
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
hide-selected
fill-input
2023-10-20 16:57:32 +07:00
dense
2024-10-31 11:00:25 +07:00
v-model="querySting.type"
2023-11-17 15:28:03 +07:00
:options="optionType"
2023-10-20 16:57:32 +07:00
option-value="id"
option-label="name"
label="ประเภทการลา"
2024-10-31 11:00:25 +07:00
@update:model-value="props.getSearch?.()"
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>
2024-07-30 16:50:08 +07:00
<template
v-if="querySting.type !== '00000000-0000-0000-0000-000000000000'"
2024-07-30 16:50:08 +07:00
v-slot:append
>
<q-icon
name="cancel"
@click.stop.prevent="
2024-07-30 16:50:08 +07:00
(optionType = optionTypeMain),
(querySting.type = '00000000-0000-0000-0000-000000000000'),
props.getSearch?.()
"
class="cursor-pointer"
/>
</template>
</q-select>
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="selectStatus"
2023-10-20 16:57:32 +07:00
emit-value
map-options
outlined
hide-selected
fill-input
2023-10-20 16:57:32 +07:00
dense
2024-10-31 11:00:25 +07:00
v-model="querySting.status"
2023-11-17 15:28:03 +07:00
:options="optionStatus"
2023-10-20 16:57:32 +07:00
option-value="id"
option-label="name"
label="สถานะ"
2024-10-31 11:00:25 +07:00
@update:model-value="props.getSearch?.()"
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>
2024-10-31 11:00:25 +07:00
<template v-if="querySting.status !== 'ALL'" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="
2024-07-30 16:50:08 +07:00
(optionStatus = optionStatusMain),
2024-10-31 11:00:25 +07:00
(querySting.status = 'ALL'),
props.getSearch?.()
"
class="cursor-pointer"
/>
</template>
2024-07-30 16:50:08 +07:00
</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
2024-10-31 11:00:25 +07:00
v-model="querySting.keyword"
label="ค้นหา"
2024-10-31 11:00:25 +07:00
@keydown.enter.prevent="props.getSearch?.()"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
2023-10-20 16:57:32 +07:00
</div>
<div class="col-xs-12 col-sm-3 col-md-1">
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"
/>
</div>
</div>
</template>