fix(registry): sort data
This commit is contained in:
parent
8d9059ad32
commit
e3345d7be3
8 changed files with 444 additions and 266 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive, watch } from "vue";
|
||||
import { ref, onMounted, reactive } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
|
||||
import { useRouter } from "vue-router";
|
||||
|
|
@ -8,18 +8,16 @@ import {
|
|||
checkPermissionList,
|
||||
checkPermissionCreate,
|
||||
} from "@/utils/permissions";
|
||||
import { updateCurrentPage } from "@/utils/function";
|
||||
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { useRegistryEmp } from "@/modules/08_registryEmployee/stores/registry-employee";
|
||||
import { usePagination } from "@/composables/usePagination";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
/** importType*/
|
||||
import type { QInput, QTableProps } from "quasar";
|
||||
import type {
|
||||
NewPagination,
|
||||
DataOption,
|
||||
} from "@/modules/08_registryEmployee/interface/index/Main";
|
||||
import type { DataOption } from "@/modules/08_registryEmployee/interface/index/Main";
|
||||
import type { DataEmployee } from "@/modules/08_registryEmployee/interface/response/Employee";
|
||||
|
||||
/** importComponents*/
|
||||
|
|
@ -39,6 +37,7 @@ const {
|
|||
findOrgNameHtml,
|
||||
} = useCounterMixin();
|
||||
const { statusText } = useRegistryEmp();
|
||||
const { pagination, params, onRequest } = usePagination("", fetchList);
|
||||
|
||||
const modalAddEmployee = ref<boolean>(false); // popup เพิ่มข้อมูลลูกจ้างชั่วคราว
|
||||
const modalPos = ref<boolean>(false); //popup กำหนดตำแหน่ง
|
||||
|
|
@ -47,11 +46,7 @@ const dataRow = ref<DataEmployee>(); //ข้อมูลรายชื่อ
|
|||
|
||||
/** Table */
|
||||
const rows = ref<DataEmployee[]>([]); //รายชื่อลูกจ้างชั่วคราว
|
||||
const maxPage = ref<number>(0); //จำนวนหน้า
|
||||
const total = ref<number>(0); //จำนวนข้อมูล
|
||||
const queryParams = reactive({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
type: "temp",
|
||||
searchField: "fullName",
|
||||
searchKeyword: "",
|
||||
|
|
@ -67,12 +62,7 @@ const columns = ref<QTableProps["columns"]>([
|
|||
align: "left",
|
||||
label: "ลำดับ",
|
||||
sortable: false,
|
||||
field: (row) =>
|
||||
(
|
||||
(queryParams.page - 1) * queryParams.pageSize +
|
||||
rows.value.indexOf(row) +
|
||||
1
|
||||
).toLocaleString(),
|
||||
field: "no",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
|
|
@ -80,16 +70,16 @@ const columns = ref<QTableProps["columns"]>([
|
|||
name: "citizenId",
|
||||
align: "left",
|
||||
label: "เลขประจำตัวประชาชน",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "citizenId",
|
||||
headerStyle: "font-size: 14px; min-width: 200px",
|
||||
style: "font-size: 14px; ",
|
||||
},
|
||||
{
|
||||
name: "fullname",
|
||||
name: "firstName",
|
||||
align: "left",
|
||||
label: "ชื่อ-นามสกุล",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "fullname",
|
||||
format(val, row) {
|
||||
return `${row.prefix}${row.firstName} ${row.lastName}`;
|
||||
|
|
@ -98,29 +88,20 @@ const columns = ref<QTableProps["columns"]>([
|
|||
style: "font-size: 14px; ",
|
||||
},
|
||||
{
|
||||
name: "draftOrganizationOrganization",
|
||||
name: "positionTemp",
|
||||
align: "left",
|
||||
label: "ตำแหน่ง/สังกัดที่รับการบรรจุ",
|
||||
sortable: false,
|
||||
field: "draftOrganizationOrganization",
|
||||
sortable: true,
|
||||
field: "positionTemp",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
// {
|
||||
// name: "draftPositionEmployee",
|
||||
// align: "left",
|
||||
// label: "ตำแหน่งที่บรรจุ",
|
||||
// sortable: false,
|
||||
// field: "draftPositionEmployee",
|
||||
// headerStyle: "font-size: 14px; min-width: 200px",
|
||||
// style: "font-size: 14px; ",
|
||||
// },
|
||||
|
||||
{
|
||||
name: "govAge",
|
||||
align: "left",
|
||||
label: "อายุราชการ(ปี)",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "govAge",
|
||||
format(val) {
|
||||
return val;
|
||||
|
|
@ -143,17 +124,17 @@ const columns = ref<QTableProps["columns"]>([
|
|||
name: "dateAppoint",
|
||||
align: "left",
|
||||
label: "วันที่แต่งตั้ง",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "dateAppoint",
|
||||
headerStyle: "font-size: 14px",
|
||||
format: (val) => date2Thai(val),
|
||||
style: "font-size: 14px",
|
||||
},
|
||||
{
|
||||
name: "age",
|
||||
name: "birthDate",
|
||||
align: "left",
|
||||
label: "อายุ",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "age",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
|
|
@ -162,7 +143,7 @@ const columns = ref<QTableProps["columns"]>([
|
|||
name: "createdAt",
|
||||
align: "left",
|
||||
label: "วันที่สร้าง",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "createdAt",
|
||||
format(val) {
|
||||
return date2Thai(val);
|
||||
|
|
@ -174,7 +155,7 @@ const columns = ref<QTableProps["columns"]>([
|
|||
name: "dateRetireLaw",
|
||||
align: "left",
|
||||
label: "วันที่พ้นราชการ",
|
||||
sortable: false,
|
||||
sortable: true,
|
||||
field: "dateRetireLaw",
|
||||
format(val) {
|
||||
return date2Thai(val);
|
||||
|
|
@ -198,12 +179,11 @@ const columns = ref<QTableProps["columns"]>([
|
|||
const visibleColumns = ref<String[]>([
|
||||
"no",
|
||||
"citizenId",
|
||||
"fullname",
|
||||
"draftOrganizationOrganization",
|
||||
// "draftPositionEmployee",
|
||||
"firstName",
|
||||
"positionTemp",
|
||||
"govAge",
|
||||
"dateEmployment",
|
||||
"age",
|
||||
"birthDate",
|
||||
"createdAt",
|
||||
"dateRetireLaw",
|
||||
"statustext",
|
||||
|
|
@ -216,14 +196,15 @@ async function fetchList() {
|
|||
await http
|
||||
.get(config.API.registryNew("-temp"), {
|
||||
params: {
|
||||
...params.value,
|
||||
...queryParams,
|
||||
searchKeyword: queryParams.searchKeyword.trim(),
|
||||
},
|
||||
})
|
||||
.then(async (res) => {
|
||||
rows.value = await res.data.result.data;
|
||||
maxPage.value = Math.ceil(res.data.result.total / queryParams.pageSize);
|
||||
total.value = res.data.result.total;
|
||||
const result = await res.data.result;
|
||||
pagination.value.rowsNumber = result.total;
|
||||
rows.value = result.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
@ -243,11 +224,9 @@ function onClickDelete(id: string) {
|
|||
await http
|
||||
.delete(config.API.registryNew("-employee") + `/${id}`)
|
||||
.then(async () => {
|
||||
queryParams.page = await updateCurrentPage(
|
||||
queryParams.page,
|
||||
maxPage.value,
|
||||
rows.value.length
|
||||
);
|
||||
if (rows.value.length === 1 && pagination.value.page > 1) {
|
||||
pagination.value.page = pagination.value.page - 1;
|
||||
}
|
||||
await fetchList();
|
||||
await success($q, "ลบข้อมูลสำเร็จ");
|
||||
})
|
||||
|
|
@ -287,22 +266,22 @@ function onClickSendOrder() {
|
|||
modalSendOrder.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันอัพเดต Pagination
|
||||
* @param newPagination ข้อมูล Pagination ใหม่
|
||||
*/
|
||||
function updatePagination(newPagination: NewPagination) {
|
||||
queryParams.page = 1;
|
||||
queryParams.pageSize = newPagination.rowsPerPage;
|
||||
}
|
||||
// /**
|
||||
// * ฟังก์ชันอัพเดต Pagination
|
||||
// * @param newPagination ข้อมูล Pagination ใหม่
|
||||
// */
|
||||
// function updatePagination(newPagination: NewPagination) {
|
||||
// queryParams.page = 1;
|
||||
// queryParams.pageSize = newPagination.rowsPerPage;
|
||||
// }
|
||||
|
||||
/** ทำงานเมื่อมีการเปลี่่ยนจำนวนข้อมูลต่อหน้า */
|
||||
watch(
|
||||
() => queryParams.pageSize,
|
||||
() => {
|
||||
fetchList();
|
||||
}
|
||||
);
|
||||
// /** ทำงานเมื่อมีการเปลี่่ยนจำนวนข้อมูลต่อหน้า */
|
||||
// watch(
|
||||
// () => queryParams.pageSize,
|
||||
// () => {
|
||||
// fetchList();
|
||||
// }
|
||||
// );
|
||||
|
||||
/** ทำงานเมื่อมีการเรียกใข้ Components */
|
||||
onMounted(async () => {
|
||||
|
|
@ -364,7 +343,12 @@ onMounted(async () => {
|
|||
placeholder="ค้นหา"
|
||||
style="max-width: 200px"
|
||||
class="q-ml-sm"
|
||||
@keydown.enter.prevent="(queryParams.page = 1), fetchList()"
|
||||
@keydown.enter.prevent="
|
||||
() => {
|
||||
pagination.page = 1;
|
||||
fetchList();
|
||||
}
|
||||
"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
|
|
@ -388,13 +372,14 @@ onMounted(async () => {
|
|||
</div>
|
||||
</div>
|
||||
<div class="col-12 q-pt-sm">
|
||||
<d-table
|
||||
<p-table
|
||||
:rows="rows"
|
||||
:columns="columns"
|
||||
:visible-columns="visibleColumns"
|
||||
row-key="id"
|
||||
:rows-per-page-options="[10, 25, 50, 100]"
|
||||
@update:pagination="updatePagination"
|
||||
v-model:pagination="pagination"
|
||||
@request="onRequest"
|
||||
>
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
|
|
@ -473,7 +458,7 @@ onMounted(async () => {
|
|||
</q-btn>
|
||||
</q-td>
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<template v-if="col.name === 'draftOrganizationOrganization'">
|
||||
<template v-if="col.name === 'positionTemp'">
|
||||
<div v-if="props.row.draftPositionEmployee !== null">
|
||||
<div class="col-4">
|
||||
<div>
|
||||
|
|
@ -522,13 +507,16 @@ onMounted(async () => {
|
|||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else-if="col.name === 'no'">
|
||||
{{ props.rowIndex + 1 }}
|
||||
</div>
|
||||
<div v-else>
|
||||
{{ col.value !== null && col.value !== "" ? col.value : "-" }}
|
||||
</div>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
<template v-slot:pagination="scope">
|
||||
<!-- <template v-slot:pagination="scope">
|
||||
ทั้งหมด {{ total }} รายการ
|
||||
<q-pagination
|
||||
v-model="queryParams.page"
|
||||
|
|
@ -541,8 +529,8 @@ onMounted(async () => {
|
|||
:max-pages="5"
|
||||
@update:model-value="fetchList"
|
||||
></q-pagination>
|
||||
</template>
|
||||
</d-table>
|
||||
</template> -->
|
||||
</p-table>
|
||||
</div>
|
||||
</q-card>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue