hrms-mgt/src/modules/11_discipline/components/2_InvestigateFacts/MainPage.vue

320 lines
9.1 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { useQuasar } from "quasar";
2024-09-19 16:37:16 +07:00
import { ref, useAttrs, onMounted, watch } from "vue";
import config from "@/app.config";
import http from "@/plugins/http";
2024-09-19 16:37:16 +07:00
import router from "@/router";
import { useCounterMixin } from "@/stores/mixin";
2023-10-19 14:36:12 +07:00
import { useInvestigateFactStore } from "@/modules/11_discipline/store/InvestigateFactStore";
import { checkPermission } from "@/utils/permissions";
import DialogSearchAdvanced from "@/modules/11_discipline/components/DialogSearchAdvanced.vue";
2024-09-19 16:37:16 +07:00
const $q = useQuasar(); //ใช้ noti quasar
const mixin = useCounterMixin();
2024-09-19 16:37:16 +07:00
const dataInvestigate = useInvestigateFactStore();
2023-11-30 21:06:50 +07:00
const { messageError, showLoader, hideLoader } = mixin;
2024-09-19 16:37:16 +07:00
const option = ref<any[]>(dataInvestigate.statusOptions);
/** ค้นหาข้อมูลในตาราง */
const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null);
2024-01-10 17:13:23 +07:00
const statusFilter = ref<string>("NEW");
const toptitle = ref<number>(0);
2024-10-29 17:04:33 +07:00
const total = ref<number>(0);
const totalList = ref<number>(1);
const pagination = ref({
2024-10-29 17:04:33 +07:00
sortBy: "createdAt",
descending: true,
page: 1,
rowsPerPage: 10,
});
2024-09-19 16:37:16 +07:00
const attrs = ref<any>(useAttrs());
2024-09-19 16:37:16 +07:00
/** ดึงข้อมูลบสวน */
async function getList(data?: any) {
const body = {
page: pagination.value.page,
pageSize: pagination.value.rowsPerPage,
keyword: filterKeyword.value.trim(),
status: statusFilter.value,
...(data && data.respondentType
? { respondentType: data.respondentType }
: {}),
...(data && data.offenseDetails
? { offenseDetails: data.offenseDetails }
: {}),
...(data && data.investigationDetail
? { investigationDetail: data.investigationDetail }
: {}),
...(data && data.investigationDateStart
? { investigationDateStart: data.investigationDateStart }
: {}),
...(data && data.investigationDateEnd
? { investigationDateEnd: data.investigationDateEnd }
: {}),
...(data && data.dateReceivedStart
? { dateReceivedStart: data.dateReceivedStart }
: {}),
...(data && data.dateReceivedEnd
? { dateReceivedEnd: data.dateReceivedEnd }
: {}),
...(data && data.investigationStatusResult
? { investigationStatusResult: data.investigationStatusResult }
: {}),
};
showLoader();
await http
.post(config.API.investigateMain(), body)
2024-12-10 11:11:57 +07:00
.then(async (res) => {
2024-10-29 17:04:33 +07:00
totalList.value = Math.ceil(
res.data.result.total / pagination.value.rowsPerPage
);
total.value = res.data.result.total;
toptitle.value = res.data.result.total;
const data = res.data.result.data;
2024-12-10 11:11:57 +07:00
await dataInvestigate.fecthList(data);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/**
* ไปหนาแกไข
* @param id ไอดเฉพาะ รายบคคล
*/
async function editPage(id: string) {
dataInvestigate.tabMenu = await "investigatefacts";
router.push(`/discipline/investigatefacts/${id}`);
}
/**
* ไปหนาแกไข
* @param id ไอดเฉพาะ รายบคคล
*/
async function detailPage(id: string) {
dataInvestigate.tabMenu = await "investigatefacts";
router.push(`/discipline-detail/investigatefacts/${id}`);
}
/**
* function นหาขอมลใน option
* @param val คำคนหา
* @param update function
*/
function filterOptionFn(val: string, update: Function) {
update(() => {
option.value = dataInvestigate.statusOptions.filter(
(e: any) => e.name.search(val) !== -1
);
});
}
2024-10-29 17:04:33 +07:00
function updatePagination(newPagination: any) {
pagination.value.page = 1;
pagination.value.rowsPerPage = newPagination.rowsPerPage;
}
function getSerach() {
pagination.value.page = 1;
getList();
}
2024-09-19 16:37:16 +07:00
watch(
() => pagination.value.rowsPerPage,
2024-10-29 17:04:33 +07:00
async () => {
getSerach();
2024-09-19 16:37:16 +07:00
}
);
/**
* งขอมลจำลองไปย store
*/
onMounted(async () => {
getList();
2023-10-19 14:36:12 +07:00
});
</script>
2024-12-10 11:11:57 +07:00
<template>
<div class="toptitle text-dark col-12 row items-center">
รายการสบสวนขอเทจจร
</div>
<q-card flat bordered class="col-12 q-mt-sm q-pa-md">
<div class="row col-12 q-col-gutter-sm q-mb-sm">
2024-12-10 11:11:57 +07:00
<q-select
v-model="statusFilter"
label="สถานะ"
dense
outlined
emit-value
map-options
hide-selected
fill-input
option-label="name"
option-value="id"
:options="option"
@update:model-value="getSerach()"
use-input
@filter="filterOptionFn"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey"> ไมอม </q-item-section>
</q-item>
</template>
<template v-if="statusFilter !== 'ALL'" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="
(option = dataInvestigate.statusOptions),
(statusFilter = 'ALL'),
getSerach()
"
class="cursor-pointer"
/>
</template>
</q-select>
<q-space />
<DialogSearchAdvanced :get-data="(value:any)=> getList(value)" />
<q-input
for="#search"
standout
dense
v-model="filterKeyword"
ref="filterRef"
outlined
2025-07-11 14:28:03 +07:00
placeholder="ค้นหาเรื่องร้องเรียน"
2024-10-29 17:04:33 +07:00
@keydown.enter.prevent="getSerach()"
>
<template v-slot:append>
2024-12-10 11:11:57 +07:00
<q-icon name="search" />
</template>
</q-input>
<q-select
for="#select"
v-model="dataInvestigate.visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="dataInvestigate.columns"
option-value="name"
2024-11-05 16:33:46 +07:00
style="min-width: 140px"
/>
</div>
<div class="col-12">
<d-table
ref="table"
:columns="dataInvestigate.columns"
:rows="dataInvestigate.rows"
row-key="interrogated"
flat
bordered
:paging="true"
dense
class="custom-header-table"
v-bind="attrs"
:visible-columns="dataInvestigate.visibleColumns"
:rows-per-page-options="[10, 25, 50, 100]"
2024-10-29 17:04:33 +07:00
@update:pagination="updatePagination"
>
<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"
style="color: #000000; font-weight: 500"
>
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width />
</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
color="info"
icon="mdi-eye"
@click="detailPage(props.row.id)"
>
<q-tooltip>รายละเอยด</q-tooltip>
</q-btn>
<q-btn
v-if="
checkPermission($route)?.attrIsGet &&
checkPermission($route)?.attrIsUpdate
"
flat
dense
round
color="edit"
icon="edit"
@click="editPage(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'">
{{
2024-10-29 17:04:33 +07:00
(pagination.page - 1) * pagination.rowsPerPage +
2023-12-27 15:50:41 +07:00
props.rowIndex +
1
}}
</div>
2024-01-17 11:23:10 +07:00
<div v-else-if="col.name === 'title'" class="table_ellipsis">
{{ props.row.title }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
<q-td
auto-width
style="font-size: 14px; width: 10%"
@click="editPage(props.row.id)"
>
{{ props.row.active }}
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
2024-10-29 17:04:33 +07:00
งหมด {{ total }} รายการ
<q-pagination
2024-10-29 17:04:33 +07:00
v-model="pagination.page"
active-color="primary"
color="dark"
2024-10-29 17:04:33 +07:00
:max="Number(totalList)"
size="sm"
boundary-links
direction-links
2024-10-29 17:04:33 +07:00
:max-pages="5"
@update:model-value="getList()"
></q-pagination>
</template>
</d-table>
</div>
</q-card>
</template>