update filter รอ api
This commit is contained in:
parent
d642cf39bf
commit
2920faf584
1 changed files with 234 additions and 192 deletions
|
|
@ -1,225 +1,267 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="q-py-sm row">
|
<div class="q-py-sm row">
|
||||||
<q-card bordered flat class="q-py-sm q-pl-sm col-12 row bg-grey-1 shadow-0">
|
<q-card bordered flat class="q-py-sm q-pl-sm col-12 row bg-grey-1 shadow-0">
|
||||||
<div class="items-center col-12 row q-col-gutter-sm">
|
<div class="items-center col-12 row q-col-gutter-sm">
|
||||||
<!-- ค้นหาข้อความใน table -->
|
<!-- ค้นหาข้อความใน table -->
|
||||||
<q-select
|
<q-select
|
||||||
outlined
|
outlined
|
||||||
dense
|
dense
|
||||||
lazy-rules
|
lazy-rules
|
||||||
v-model="type"
|
v-model="type"
|
||||||
:rules="[(val) => !!val || `${'กรุณาเลือกประเภทใบลา'}`]"
|
:rules="[val => !!val || `${'กรุณาเลือกประเภทใบลา'}`]"
|
||||||
:label="`${'ประเภทใบลา'}`"
|
:label="`${'ประเภทใบลา'}`"
|
||||||
emit-value
|
emit-value
|
||||||
map-options
|
map-options
|
||||||
option-label="name"
|
option-label="name"
|
||||||
:options="typeOptions"
|
:options="LeaveData.typeOptions"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
style="min-width: 150px;"
|
style="min-width: 150px"
|
||||||
class="col-xs-12 col-sm-auto"
|
class="col-xs-12 col-sm-auto"
|
||||||
/>
|
@update:model-value="searchFilterTable"
|
||||||
<q-select
|
@filter="(inputValue:any,
|
||||||
outlined
|
doneFn:Function) => filterSelector(inputValue, doneFn,'typeOptions'
|
||||||
dense
|
) "
|
||||||
lazy-rules
|
/>
|
||||||
v-model="status"
|
<q-select
|
||||||
:rules="[(val) => !!val || `${'กรุณาเลือกสถานะ'}`]"
|
outlined
|
||||||
:label="`${'สถานะ'}`"
|
dense
|
||||||
emit-value
|
lazy-rules
|
||||||
map-options
|
v-model="status"
|
||||||
option-label="name"
|
:rules="[val => !!val || `${'กรุณาเลือกสถานะ'}`]"
|
||||||
:options="statusOptions"
|
:label="`${'สถานะ'}`"
|
||||||
option-value="id"
|
emit-value
|
||||||
hide-bottom-space
|
map-options
|
||||||
style="min-width: 150px;"
|
option-label="name"
|
||||||
class="col-xs-12 col-sm-auto"
|
:options="LeaveData.statusOptions"
|
||||||
/>
|
option-value="id"
|
||||||
<q-space/>
|
hide-bottom-space
|
||||||
<q-input
|
style="min-width: 150px"
|
||||||
standout
|
class="col-xs-12 col-sm-auto"
|
||||||
dense
|
@update:model-value="searchFilterTable"
|
||||||
:model-value="inputfilter"
|
@filter="(inputValue:any,
|
||||||
ref="filterRef"
|
doneFn:Function) => filterSelector(inputValue, doneFn,'statusOptions'
|
||||||
@update:model-value="updateInput"
|
) "
|
||||||
outlined
|
/>
|
||||||
debounce="300"
|
<q-space />
|
||||||
placeholder="ค้นหา"
|
<q-input standout dense :model-value="inputfilter" ref="filterRef" @update:model-value="updateInput" outlined debounce="300" placeholder="ค้นหา" class="gt-xs" style="max-width: 150px">
|
||||||
class="gt-xs"
|
<template v-slot:append>
|
||||||
style="max-width: 150px"
|
<q-icon v-if="inputfilter == ''" name="search" />
|
||||||
>
|
<q-icon v-if="inputfilter !== ''" name="clear" class="cursor-pointer" @click="resetFilter" />
|
||||||
<template v-slot:append>
|
</template>
|
||||||
<q-icon v-if="inputfilter == ''" name="search" />
|
</q-input>
|
||||||
<q-icon
|
<!-- แสดงคอลัมน์ใน table -->
|
||||||
v-if="inputfilter !== ''"
|
<q-select
|
||||||
name="clear"
|
:model-value="inputvisible"
|
||||||
class="cursor-pointer"
|
@update:model-value="updateVisible"
|
||||||
@click="resetFilter"
|
:display-value="$q.lang.table.columns"
|
||||||
/>
|
multiple
|
||||||
</template>
|
outlined
|
||||||
</q-input>
|
dense
|
||||||
<!-- แสดงคอลัมน์ใน table -->
|
:options="attrs.columns"
|
||||||
<q-select
|
options-dense
|
||||||
:model-value="inputvisible"
|
option-value="name"
|
||||||
@update:model-value="updateVisible"
|
map-options
|
||||||
:display-value="$q.lang.table.columns"
|
emit-value
|
||||||
multiple
|
style="min-width: 150px"
|
||||||
outlined
|
class="gt-xs"
|
||||||
dense
|
>
|
||||||
:options="attrs.columns"
|
<template> </template>
|
||||||
options-dense
|
</q-select>
|
||||||
option-value="name"
|
</div>
|
||||||
map-options
|
</q-card>
|
||||||
emit-value
|
</div>
|
||||||
style="min-width: 150px"
|
<div>
|
||||||
class="gt-xs"
|
<q-table
|
||||||
>
|
ref="table"
|
||||||
<template> </template>
|
flat
|
||||||
</q-select>
|
bordered
|
||||||
</div>
|
class="custom-table2"
|
||||||
</q-card>
|
v-bind="attrs"
|
||||||
</div>
|
virtual-scroll
|
||||||
<div>
|
:virtual-scroll-sticky-size-start="48"
|
||||||
<q-table
|
dense
|
||||||
ref="table"
|
:pagination-label="paginationLabel"
|
||||||
flat
|
:pagination="initialPagination"
|
||||||
bordered
|
:rows-per-page-options="[0]"
|
||||||
class="custom-table2"
|
>
|
||||||
v-bind="attrs"
|
<template v-slot:header="props">
|
||||||
virtual-scroll
|
<q-tr :props="props">
|
||||||
:virtual-scroll-sticky-size-start="48"
|
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
dense
|
<span class="text-weight-medium" v-html="col.label" />
|
||||||
:pagination-label="paginationLabel"
|
</q-th>
|
||||||
:pagination="initialPagination"
|
</q-tr>
|
||||||
:rows-per-page-options="[0]"
|
</template>
|
||||||
>
|
<template #body="props">
|
||||||
<template v-slot:header="props">
|
<slot v-bind="props" name="columns"></slot>
|
||||||
<q-tr :props="props">
|
</template>
|
||||||
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
</q-table>
|
||||||
<span class="text-weight-medium" v-html="col.label" />
|
</div>
|
||||||
</q-th>
|
|
||||||
|
|
||||||
</q-tr>
|
|
||||||
</template>
|
|
||||||
<template #body="props">
|
|
||||||
<slot v-bind="props" name="columns"></slot>
|
|
||||||
</template>
|
|
||||||
</q-table>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, useAttrs } from "vue";
|
import { ref, useAttrs } from "vue"
|
||||||
const attrs = ref<any>(useAttrs());
|
import { useLeaveStore } from "@/modules/05_leave/store"
|
||||||
const table = ref<any>(null);
|
import type { an } from "@fullcalendar/core/internal-common"
|
||||||
const filterRef = ref<any>(null);
|
|
||||||
|
|
||||||
const type = ref('ทั้งหมด');
|
const DataStore = useLeaveStore()
|
||||||
const typeOptions = ref([
|
const LeaveData = useLeaveStore()
|
||||||
'ทั้งหมด',
|
const attrs = ref<any>(useAttrs())
|
||||||
'ลาป่วย',
|
const table = ref<any>(null)
|
||||||
'ลากิจส่วนตัว',
|
const filterRef = ref<any>(null)
|
||||||
'ลาคลอดบุตร',
|
const rows = ref<any[]>([])
|
||||||
'ลาช่วยเหลือภริยาที่คลอดบุตร',
|
const type = ref("ทั้งหมด")
|
||||||
'ลาพักผ่อน',
|
const status = ref("ทั้งหมด")
|
||||||
'ลาอุปสมบทหรือการลาประกอบพิธีฮัจย์ฯ',
|
|
||||||
'ลาเข้ารับการตรวจเลือกหรือเข้ารับการเตรียมพล',
|
|
||||||
'ลาไปศึกษา ฝึกอบรม ปฏิบัติการวิจัย หรือดูงาน',
|
|
||||||
'ลาไปปฏิบัติงานในองค์การระหว่างประเทศ',
|
|
||||||
'ลาติดตามคู่สมรส',
|
|
||||||
'ลาฟื้นฟูสมรรถภาพด้านอาชีพ'
|
|
||||||
])
|
|
||||||
const status = ref('ทั้งหมด');
|
|
||||||
const statusOptions = ref([
|
|
||||||
'อนุมัติ',
|
|
||||||
'ไม่อนุมัติ',
|
|
||||||
'อยู่ระหว่างดำเนินการ',
|
|
||||||
'ใหม่',
|
|
||||||
])
|
|
||||||
|
|
||||||
const initialPagination = ref({
|
const initialPagination = ref({
|
||||||
rowsPerPage: 0,
|
rowsPerPage: 0,
|
||||||
});
|
})
|
||||||
const yearly = ref<number>(new Date().getFullYear());
|
const yearly = ref<number>(new Date().getFullYear())
|
||||||
|
let OriginalData = ref<any[]>([])
|
||||||
|
let UpdataData = ref<any[]>([])
|
||||||
|
|
||||||
|
const OriginalDataFetch = async () => {
|
||||||
|
await DataStore.DataMain(rows.value)
|
||||||
|
OriginalData.value = await DataStore.DataMainOrig
|
||||||
|
UpdataData.value = OriginalData.value
|
||||||
|
}
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
count: Number,
|
count: Number,
|
||||||
pass: Number,
|
pass: Number,
|
||||||
notpass: Number,
|
notpass: Number,
|
||||||
|
|
||||||
inputfilter: String,
|
inputfilter: String,
|
||||||
name: String,
|
name: String,
|
||||||
icon: String,
|
icon: String,
|
||||||
inputvisible: Array,
|
inputvisible: Array,
|
||||||
editvisible: Boolean,
|
editvisible: Boolean,
|
||||||
grid: Boolean,
|
grid: Boolean,
|
||||||
|
|
||||||
inputShow: Boolean,
|
inputShow: Boolean,
|
||||||
});
|
})
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits(["update:inputfilter", "update:inputvisible", "update:editvisible"])
|
||||||
"update:inputfilter",
|
|
||||||
"update:inputvisible",
|
|
||||||
"update:editvisible",
|
|
||||||
]);
|
|
||||||
const updateInput = (value: string | number | null) => {
|
const updateInput = (value: string | number | null) => {
|
||||||
emit("update:inputfilter", value);
|
emit("update:inputfilter", value)
|
||||||
};
|
}
|
||||||
const updateVisible = (value: []) => {
|
const updateVisible = (value: []) => {
|
||||||
emit("update:inputvisible", value);
|
emit("update:inputvisible", value)
|
||||||
};
|
}
|
||||||
|
|
||||||
const paginationLabel = (start: string, end: string, total: string) => {
|
const paginationLabel = (start: string, end: string, total: string) => {
|
||||||
return start + "-" + end + " ใน " + total;
|
return start + "-" + end + " ใน " + total
|
||||||
};
|
}
|
||||||
|
|
||||||
const resetFilter = () => {
|
const resetFilter = () => {
|
||||||
// reset ค่าที่ค้นหาเมื่อกดปุ่ม X ในกล่องค้นหา
|
// reset ค่าที่ค้นหาเมื่อกดปุ่ม X ในกล่องค้นหา
|
||||||
emit("update:inputfilter", "");
|
emit("update:inputfilter", "")
|
||||||
filterRef.value.focus();
|
filterRef.value.focus()
|
||||||
};
|
}
|
||||||
|
|
||||||
|
const searchFilterTable = async () => {
|
||||||
|
// ส่งไป filter รายการข้อมูลตามเงื่อนไข
|
||||||
|
await DataStore.DataUpdate(typeOptions.value, statusOptions.value)
|
||||||
|
UpdataData.value = DataStore.DataMainUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
// รายการข้อมูลประเภท
|
||||||
|
const typeOptions = ref<string>("")
|
||||||
|
const typeOptionsFilter1 = ref<any>([])
|
||||||
|
const typeOptionsOption = ref<any[]>([{ id: "", name: "ทั้งหมด" }])
|
||||||
|
|
||||||
|
const TypeFilter = async () => {
|
||||||
|
// await http
|
||||||
|
// .get(config.API.typeOrder())
|
||||||
|
// .then((res) => {
|
||||||
|
// const response = res.data.result;
|
||||||
|
// LeaveData.typeOptions = [{ id: "", name: "ทั้งหมด" }];
|
||||||
|
// TypeOption.value.push(...response);
|
||||||
|
// typeOptionsFilter1.value = [{ id: "", name: "ทั้งหมด" }];
|
||||||
|
// typeOptionsFilter1.value.push(...response);
|
||||||
|
// })
|
||||||
|
// .catch((e) => {
|
||||||
|
// messageError($q, e);
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
// รายการข้อมูลประเภท
|
||||||
|
const statusOptions = ref<string>("")
|
||||||
|
const statusOptionsFilter1 = ref<any>([])
|
||||||
|
const statusOptionsOption = ref<any[]>([{ id: "", name: "ทั้งหมด" }])
|
||||||
|
|
||||||
|
const statusOptionsFilter = async () => {
|
||||||
|
// await http
|
||||||
|
// .get(config.API.typeOrder())
|
||||||
|
// .then((res) => {
|
||||||
|
// const response = res.data.result;
|
||||||
|
// LeaveData.typeOptions = [{ id: "", name: "ทั้งหมด" }];
|
||||||
|
// TypeOption.value.push(...response);
|
||||||
|
// typeOptionsFilter1.value = [{ id: "", name: "ทั้งหมด" }];
|
||||||
|
// typeOptionsFilter1.value.push(...response);
|
||||||
|
// })
|
||||||
|
// .catch((e) => {
|
||||||
|
// messageError($q, e);
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSelector = (val: any, update: Function, refData: string) => {
|
||||||
|
switch (refData) {
|
||||||
|
case "typeOptions":
|
||||||
|
update(() => {
|
||||||
|
LeaveData.typeOptions.values = typeOptionsFilter1.value.filter((v: any) => v.name.indexOf(val) > -1)
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case "statusOptions":
|
||||||
|
update(() => {
|
||||||
|
LeaveData.statusOptions.values = statusOptionsFilter1.value.filter((v: any) => v.name.indexOf(val) > -1)
|
||||||
|
})
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.icon-color {
|
.icon-color {
|
||||||
color: #4154b3;
|
color: #4154b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-table2 {
|
.custom-table2 {
|
||||||
.q-table tr:nth-child(odd) td {
|
.q-table tr:nth-child(odd) td {
|
||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.q-table tr:nth-child(even) td {
|
.q-table tr:nth-child(even) td {
|
||||||
background: #f8f8f8;
|
background: #f8f8f8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.q-table thead tr {
|
.q-table thead tr {
|
||||||
background: #ecebeb;
|
background: #ecebeb;
|
||||||
}
|
}
|
||||||
|
|
||||||
.q-table thead tr th {
|
.q-table thead tr th {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
}
|
}
|
||||||
|
|
||||||
.q-table td:nth-of-type(2) {
|
.q-table td:nth-of-type(2) {
|
||||||
z-index: 3 !important;
|
z-index: 3 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.q-table th:nth-of-type(2),
|
.q-table th:nth-of-type(2),
|
||||||
.q-table td:nth-of-type(2) {
|
.q-table td:nth-of-type(2) {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this will be the loading indicator */
|
/* this will be the loading indicator */
|
||||||
.q-table thead tr:last-child th {
|
.q-table thead tr:last-child th {
|
||||||
/* height of all previous header rows */
|
/* height of all previous header rows */
|
||||||
top: 48px;
|
top: 48px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.q-table thead tr:first-child th {
|
.q-table thead tr:first-child th {
|
||||||
top: 0;
|
top: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue