fix(disciplinary):sort

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-10-09 10:38:28 +07:00
parent b1532ada56
commit 49dcf013ae
3 changed files with 207 additions and 291 deletions

View file

@ -2,25 +2,16 @@
import { onMounted, ref, watch } from "vue"; import { onMounted, ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore"; import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore";
import { useDisciplineMainStore } from "@/modules/11_discipline/store/Main"; import { useDisciplineMainStore } from "@/modules/11_discipline/store/Main";
import { usePagination } from "@/composables/usePagination";
import http from "@/plugins/http";
import config from "@/app.config";
import Table from "@/modules/11_discipline/components/3_InvestigateDisciplinary/Table.vue"; import Table from "@/modules/11_discipline/components/3_InvestigateDisciplinary/Table.vue";
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
const $q = useQuasar(); // noti quasar const $q = useQuasar(); // noti quasar
const router = useRouter(); const router = useRouter();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
@ -28,14 +19,18 @@ const store = useDisciplineMainStore();
const dataInvestigateDis = useInvestigateDisStore(); const dataInvestigateDis = useInvestigateDisStore();
const { showLoader, hideLoader, messageError, convertDateToAPI } = mixin; const { showLoader, hideLoader, messageError, convertDateToAPI } = mixin;
const { fetchList } = dataInvestigateDis; const { fetchList } = dataInvestigateDis;
const { pagination, params, onRequest } = usePagination(
"",
fetchListDisciplinary
);
const filter = ref<string>(""); //search data table const filter = ref<string>(""); //search data table
const status = ref<string>("NEW"); const status = ref<string>("NEW");
async function fetchListDisciplinary(page?: number) {
async function fetchListDisciplinary() {
const body = { const body = {
page: page ? page : pagination.value.page, ...params.value,
pageSize: pagination.value.rowsPerPage,
keyword: filter.value.trim(), keyword: filter.value.trim(),
status: status.value, status: status.value,
...(store.formInvestigateDisciplinary.respondentType && { ...(store.formInvestigateDisciplinary.respondentType && {
@ -77,12 +72,9 @@ async function fetchListDisciplinary(page?: number) {
await http await http
.post(config.API.disciplineDisciplinary(), body) .post(config.API.disciplineDisciplinary(), body)
.then(async (res) => { .then(async (res) => {
const data = res.data.result.data; const result = res.data.result;
totalList.value = Math.ceil( pagination.value.rowsNumber = result.total;
res.data.result.total / pagination.value.rowsPerPage await fetchList(result.data);
);
total.value = res.data.result.total;
await fetchList(data);
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
@ -112,18 +104,11 @@ function filterStatus(statusReturn: string) {
getSearch(); getSearch();
} }
function getSearch(page?: number) { function getSearch() {
pagination.value.page = 1; pagination.value.page = 1;
fetchListDisciplinary(page); fetchListDisciplinary();
} }
watch(
() => pagination.value.rowsPerPage,
async () => {
getSearch();
}
);
/** /**
* งขอมลจำลองไปย store * งขอมลจำลองไปย store
*/ */
@ -136,29 +121,26 @@ onMounted(async () => {
<div class="toptitle text-dark col-12 row items-center"> <div class="toptitle text-dark col-12 row items-center">
รายการสอบสวนความผดทางว รายการสอบสวนความผดทางว
</div> </div>
<q-card flat bordered class="col-12 q-mt-sm q-pt-sm q-pa-md"> <q-card flat bordered>
<div> <Table
<Table style="max-height: 80vh"
style="max-height: 80vh" :rows="dataInvestigateDis.rows"
:rows="dataInvestigateDis.rows" :columns="dataInvestigateDis.columns"
:columns="dataInvestigateDis.columns" :visible-columns="dataInvestigateDis.visibleColumns"
:visible-columns="dataInvestigateDis.visibleColumns" v-model:inputfilter="filter"
v-model:inputfilter="filter" v-model:inputvisible="dataInvestigateDis.visibleColumns"
v-model:inputvisible="dataInvestigateDis.visibleColumns" :nornmalData="true"
:nornmalData="true" :paging="true"
:paging="true" :titleText="''"
:titleText="''" v-model:pagination="pagination"
v-model:pagination="pagination" :fetchListDisciplinary="fetchListDisciplinary"
v-model:total="total" v-model:open-edit="openEdit"
v-model:total-list="totalList" :open-detail="openDetail"
:fetchListDisciplinary="fetchListDisciplinary" :filterStatus="filterStatus"
v-model:open-edit="openEdit" :get-search="getSearch"
:open-detail="openDetail" :on-request="onRequest"
:filterStatus="filterStatus" >
:get-search="getSearch" </Table>
>
</Table>
</div>
</q-card> </q-card>
</template> </template>

View file

@ -1,23 +1,22 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, useAttrs, watch } from "vue"; import { ref, useAttrs } from "vue";
import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore"; import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
import DialogSearchAdvanced from "@/modules/11_discipline/components/DialogSearchAdvanced.vue"; import DialogSearchAdvanced from "@/modules/11_discipline/components/DialogSearchAdvanced.vue";
const total = defineModel<number>("total", { required: true }); import type { PropsTable } from "@/interface/index/PropsTable";
const totalList = defineModel<number>("totalList", { required: true }); import type { DataOption } from "@/modules/11_discipline/interface/index/Main";
const pagination = defineModel<any>("pagination", { required: true });
const pagination = defineModel<PropsTable.Pagination>("pagination", {
required: true,
});
const dataInvestigateDis = useInvestigateDisStore(); const dataInvestigateDis = useInvestigateDisStore();
const table = ref<any>(null);
const filterRef = ref<any>(null);
const attrs = ref<any>(useAttrs()); const attrs = ref<any>(useAttrs());
const paging = ref<boolean>(true);
const currentPage = ref<number>(1);
const statusFilter = ref<string>("NEW"); const statusFilter = ref<string>("NEW");
const option = ref<any[]>(dataInvestigateDis.statusOptions); const option = ref<DataOption[]>(dataInvestigateDis.statusOptions);
/** รับ props มาจากหน้าหลัก */ /** รับ props มาจากหน้าหลัก */
const props = defineProps({ const props = defineProps({
count: Number, count: Number,
@ -77,6 +76,10 @@ const props = defineProps({
type: Number, type: Number,
require: true, require: true,
}, },
onRequest: {
type: Function,
require: true,
},
}); });
const emit = defineEmits([ const emit = defineEmits([
@ -94,18 +97,6 @@ function updateVisible(value: []) {
emit("update:inputvisible", value); emit("update:inputvisible", value);
} }
function resetFilter() {
// reset X
emit("update:inputfilter", "");
filterRef.value.focus();
props.fetchListDisciplinary?.();
}
function updateProp(newPagination: any, page: number) {
// event parent component props
emit("update:pagination", newPagination, page);
}
function dataUpdate() { function dataUpdate() {
props.filterStatus(statusFilter.value); props.filterStatus(statusFilter.value);
} }
@ -126,215 +117,166 @@ function filterOptionFn(val: string, update: Function) {
); );
}); });
} }
function updatePagination(newPagination: any) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
</script> </script>
<template> <template>
<div class="q-pb-sm row q-col-gutter-sm items-center"> <div class="row q-col-gutter-sm q-pa-md">
<q-select <div class="col-12">
v-model="statusFilter" <div class="row q-col-gutter-sm">
label="สถานะ" <div class="col-xs-12 col-sm-3 col-md-4 col-lg-2">
dense <q-select
outlined v-model="statusFilter"
emit-value label="สถานะ"
hide-selected dense
fill-input outlined
map-options emit-value
option-label="name" hide-selected
option-value="id" fill-input
:options="option" map-options
@update:model-value="dataUpdate" option-label="name"
use-input option-value="id"
@filter="filterOptionFn" :options="option"
> @update:model-value="dataUpdate"
<template v-slot:no-option> use-input
<q-item> @filter="filterOptionFn"
<q-item-section class="text-grey"> ไมอม </q-item-section> >
</q-item> <template v-slot:no-option>
</template> <q-item>
<template v-if="statusFilter !== 'ALL'" v-slot:append> <q-item-section class="text-grey"> ไมอม </q-item-section>
<q-icon </q-item>
name="cancel" </template>
@click.stop.prevent=" <template v-if="statusFilter !== 'ALL'" v-slot:append>
(option = dataInvestigateDis.statusOptions), <q-icon
(statusFilter = 'ALL'), name="cancel"
dataUpdate() @click.stop.prevent="
" (option = dataInvestigateDis.statusOptions),
class="cursor-pointer" (statusFilter = 'ALL'),
/> dataUpdate()
</template> "
</q-select> class="cursor-pointer"
/>
<q-space /> </template>
<!-- นหาขอความใน table --> </q-select>
<DialogSearchAdvanced :get-data="(value:number)=> props.getSearch?.(value)" /> </div>
<q-input <q-space />
standout <div class="col-xs-12 col-sm-8 col-md-6 col-lg-4">
dense <div class="row q-col-gutter-sm items-center">
:model-value="inputfilter" <!-- นหาขอความใน table -->
ref="filterRef" <div class="col">
@update:model-value="updateInput" <DialogSearchAdvanced :get-data="() => props.getSearch?.()" />
outlined </div>
placeholder="ค้นหา" <div class="col-7">
style="max-width: 200px" <q-input
@keydown.enter.prevent="filterFn" standout
> dense
<template v-slot:append> :model-value="inputfilter"
<q-icon name="search" /> ref="filterRef"
</template> @update:model-value="updateInput"
<q-tooltip outlined
transition-show="scale" placeholder="ค้นหา"
transition-hide="scale" @keydown.enter.prevent="filterFn"
class="text-body2" >
>หมายเหต: นหาจากเรองรองเรยน <template v-slot:append>
ระดบโทษความผดหรอกรณความผ</q-tooltip <q-icon name="search" />
</template>
<q-tooltip
transition-show="scale"
transition-hide="scale"
class="text-body2"
>หมายเหต: นหาจากเรองรองเรยน
ระดบโทษความผดหรอกรณความผ</q-tooltip
>
</q-input>
</div>
<div class="col-4">
<q-select
:model-value="inputvisible"
@update:model-value="updateVisible"
:display-value="$q.lang.table.columns"
multiple
outlined
dense
:options="attrs.columns"
options-dense
option-value="name"
map-options
emit-value
/>
</div>
</div>
</div>
</div>
</div>
<div class="col-12">
<p-table
ref="table"
flat
v-bind="attrs"
virtual-scroll
:virtual-scroll-sticky-size-start="48"
dense
:rows-per-page-options="[10, 25, 50, 100]"
v-model:pagination="pagination"
@request="props.onRequest"
> >
</q-input> <template v-slot:header="props">
<!-- แสดงคอลมนใน table --> <q-tr :props="props">
<q-select <q-th auto-width></q-th>
:model-value="inputvisible" <q-th v-for="col in props.cols" :key="col.name" :props="props">
@update:model-value="updateVisible" <span class="text-weight-medium" v-html="col.label" />
:display-value="$q.lang.table.columns" </q-th>
multiple </q-tr>
outlined </template>
dense <template v-slot:body="props">
:options="attrs.columns" <q-tr :props="props">
options-dense <q-td auto-width>
option-value="name" <q-btn
map-options v-if="checkPermission($route)?.attrIsGet"
emit-value flat
style="min-width: 140px" dense
> round
</q-select> icon="mdi-eye"
color="info"
@click="openDetail(props.row.id)"
>
<q-tooltip>รายละเอยด</q-tooltip>
</q-btn>
<q-btn
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
flat
dense
round
icon="edit"
color="edit"
@click="openEdit(props.row.id)"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div
v-else
:class="
col.name === 'title' || col.name === 'disciplinaryCaseFault'
? 'table_ellipsis'
: ''
"
>
{{ col.value ?? "-" }}
</div>
</q-td>
</q-tr>
</template>
</p-table>
</div>
</div> </div>
<d-table
ref="table"
flat
v-bind="attrs"
virtual-scroll
:virtual-scroll-sticky-size-start="48"
dense
:rows-per-page-options="[10, 25, 50, 100]"
@update:pagination="updatePagination"
>
<template v-slot:pagination="scope">
งหมด {{ total }} รายการ
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="Number(totalList)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="props.fetchListDisciplinary?.()"
></q-pagination>
</template>
<template v-slot:header="props">
<q-tr :props="props">
<q-th auto-width></q-th>
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium" v-html="col.label" />
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td auto-width>
<q-btn
v-if="checkPermission($route)?.attrIsGet"
flat
dense
round
icon="mdi-eye"
color="info"
@click="openDetail(props.row.id)"
>
<q-tooltip>รายละเอยด</q-tooltip>
</q-btn>
<q-btn
v-if="
checkPermission($route)?.attrIsUpdate &&
checkPermission($route)?.attrIsGet
"
flat
dense
round
icon="edit"
color="edit"
@click="openEdit(props.row.id)"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
</q-td>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'">
{{
(currentPage - 1) * Number(pagination.rowsPerPage) +
props.rowIndex +
1
}}
</div>
<div v-else-if="col.name === 'title'" class="table_ellipsis">
{{ props.row.title }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</template> </template>
<style lang="scss"> <style lang="scss"></style>
.icon-color {
color: #4154b3;
}
.custom-table2 {
max-height: 64vh;
.q-table tr:nth-child(odd) td {
background: white;
}
.q-table tr:nth-child(even) td {
background: #f8f8f8;
}
.q-table thead tr {
background: #ecebeb;
}
.q-table thead tr th {
position: sticky;
}
.q-table td:nth-of-type(2) {
z-index: 3 !important;
}
.q-table th:nth-of-type(2),
.q-table td:nth-of-type(2) {
position: sticky;
left: 0;
z-index: 1;
}
/* this will be the loading indicator */
.q-table thead tr:last-child th {
/* height of all previous header rows */
top: 48px;
}
.q-table thead tr:first-child th {
top: 0;
}
}
</style>

View file

@ -4,7 +4,7 @@ import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import type { Persons } from "@/modules/11_discipline/interface/request/Disciplinary"; import type { Persons } from "@/modules/11_discipline/interface/request/disciplinary";
import type { import type {
investigateDisDataRowType, investigateDisDataRowType,
DataOption, DataOption,
@ -81,7 +81,7 @@ export const useInvestigateDisStore = defineStore(
"offenseDetails", "offenseDetails",
"disciplinaryFaultLevel", "disciplinaryFaultLevel",
"disciplinaryCaseFault", "disciplinaryCaseFault",
"disciplinaryDate", "disciplinaryDateStart",
"dateReceived", "dateReceived",
"status", "status",
]); ]);
@ -113,8 +113,6 @@ export const useInvestigateDisStore = defineStore(
field: "respondentType", field: "respondentType",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "offenseDetails", name: "offenseDetails",
@ -124,8 +122,6 @@ export const useInvestigateDisStore = defineStore(
field: "offenseDetails", field: "offenseDetails",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "disciplinaryFaultLevel", name: "disciplinaryFaultLevel",
@ -135,8 +131,6 @@ export const useInvestigateDisStore = defineStore(
field: "disciplinaryFaultLevel", field: "disciplinaryFaultLevel",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "disciplinaryCaseFault", name: "disciplinaryCaseFault",
@ -146,11 +140,9 @@ export const useInvestigateDisStore = defineStore(
field: "disciplinaryCaseFault", field: "disciplinaryCaseFault",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
}, },
{ {
name: "disciplinaryDate", name: "disciplinaryDateStart",
align: "left", align: "left",
label: "วันที่สอบสวน", label: "วันที่สอบสวน",
sortable: true, sortable: true,
@ -171,7 +163,7 @@ export const useInvestigateDisStore = defineStore(
name: "status", name: "status",
align: "left", align: "left",
label: "สถานะ", label: "สถานะ",
sortable: true, sortable: false,
field: "status", field: "status",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",