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

254 lines
6.6 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, useAttrs, onMounted, watch } from "vue";
2023-10-19 14:36:12 +07:00
import router from "@/router";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import config from "@/app.config";
import http from "@/plugins/http";
2023-10-19 14:36:12 +07:00
import { useInvestigateFactStore } from "@/modules/11_discipline/store/InvestigateFactStore";
const dataInvestigate = useInvestigateFactStore();
const mixin = useCounterMixin();
2023-11-30 21:06:50 +07:00
const { messageError, showLoader, hideLoader } = mixin;
const $q = useQuasar(); //ใช้ noti quasar
/** ค้นหาข้อมูลในตาราง */
const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null);
2023-12-27 15:50:41 +07:00
function resetFilter() {
filterKeyword.value = "";
if (filterRef.value) {
filterRef.value.focus();
2023-12-27 15:50:41 +07:00
getList();
}
2023-12-27 15:50:41 +07:00
}
2024-01-10 17:13:23 +07:00
const statusFilter = ref<string>("NEW");
const currentPage = ref<number>(1);
const maxPage = ref<number>(1);
const page = ref<number>(1);
const rowsPerPage = ref<number>(10);
const toptitle = ref<number>(0);
/**
*pagination ของตาราง
*/
const pagination = ref({
descending: false,
page: page.value,
rowsPerPage: rowsPerPage.value,
});
watch(
() => currentPage.value,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
getList();
}
);
watch(
() => pagination.value.rowsPerPage,
() => {
rowsPerPage.value = pagination.value.rowsPerPage;
currentPage.value = 1;
getList();
}
);
async function getList() {
showLoader();
await http
.get(
config.API.investigateMain(
currentPage.value,
rowsPerPage.value,
filterKeyword.value,
statusFilter.value
)
)
.then((res) => {
maxPage.value = Math.ceil(res.data.result.total / rowsPerPage.value);
toptitle.value = res.data.result.total;
const data = res.data.result.data;
dataInvestigate.fecthList(data);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
const attrs = ref<any>(useAttrs());
/**
* ไปหนาแกไข
* @param id ไอดเฉพาะ รายบคคล
*/
async function editPage(id: string) {
dataInvestigate.tabMenu = await "investigatefacts";
router.push(`/discipline/investigatefacts/${id}`);
}
2023-12-27 15:50:41 +07:00
function filterFn() {
getList();
2023-12-26 15:53:52 +07:00
}
/**
* งขอมลจำลองไปย store
*/
onMounted(async () => {
getList();
2023-10-19 14:36:12 +07:00
});
</script>
<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">
<div class="col-xs-12 col-sm-4 col-md-3">
2023-12-26 15:53:52 +07:00
<q-select
v-model="statusFilter"
label="สถานะ"
dense
outlined
emit-value
map-options
option-label="name"
option-value="id"
:options="dataInvestigate.statusOptions"
@update:model-value="getList()"
2024-07-04 13:44:29 +07:00
>
<template v-if="statusFilter !== 'ALL'" v-slot:append>
<q-icon
name="cancel"
@click.stop.prevent="(statusFilter = 'ALL'), getList()"
class="cursor-pointer"
/> </template
></q-select>
2023-12-26 15:53:52 +07:00
</div>
<q-space />
<q-input
for="#search"
class="col-xs-12 col-sm-3 col-md-2"
standout
dense
v-model="filterKeyword"
ref="filterRef"
outlined
placeholder="ค้นหา"
2023-12-27 15:50:41 +07:00
@keydown.enter.prevent="filterFn"
>
<template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" />
<q-icon
v-if="filterKeyword !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
/>
</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"
options-cover
style="min-width: 150px"
class="col-xs-12 col-sm-3 col-md-2"
/>
</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"
v-model:pagination="pagination"
:rows-per-page-options="[10, 25, 50, 100]"
>
<template v-slot:header="props">
<q-tr :props="props">
<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" class="cursor-pointer">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
@click="editPage(props.row.id)"
>
<div v-if="col.name == 'no'">
{{
2023-12-27 15:50:41 +07:00
(currentPage - 1) * Number(pagination.rowsPerPage) +
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">
งหมด {{ toptitle }}รายการ
<q-pagination
v-model="currentPage"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
></q-pagination>
</template>
</d-table>
</div>
</q-card>
</template>