hrms-mgt/src/modules/11_discipline/store/DirectorStore.ts
2024-01-15 17:52:25 +07:00

118 lines
3.2 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
import type {
DirectorRows,
DirectorRowsResponse,
} from "@/modules/11_discipline/interface/response/director";
import type { QTableProps } from "quasar";
// store ระบบวินัย >> ข้อมูลพื้นฐาน >> กรรมการ
export const useDisciplineDirectorDataStore = defineStore(
"disciplineDirector",
() => {
//ค้นหา คอลัมน์ คอลัมน์ที่แสดง
const rows = ref<DirectorRowsResponse[]>([]);
const visibleColumns = ref<string[]>([
"no",
"fullName",
"position",
"email",
"phone",
"totalInvestigate",
"totalDisciplinary",
]);
// หัวตาราง
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "fullName",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "fullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่ง",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "email",
align: "left",
label: "อีเมล",
sortable: true,
field: "email",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "phone",
align: "left",
label: "เบอร์โทรศัพท์",
sortable: true,
field: "phone",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "totalInvestigate",
align: "left",
label: "จำนวนการสืบสวน",
sortable: true,
field: "totalInvestigate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "totalDisciplinary",
align: "left",
label: "จำนวนการสอบสวน",
sortable: true,
field: "totalDisciplinary",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/**
* เก็บข้อมูลที่ได้จาก API เเล้วจัดเรียง
* @param data ข้อมูลจาก API
*/
function fetchData(data: DirectorRows[]) {
const dataList: DirectorRowsResponse[] = data.map(
(item: DirectorRows) => ({
id: item.id,
fullName: `${item.prefix}${item.firstName} ${item.lastName}`,
position: item.position,
email: item.email ? item.email : '-',
phone: item.phone ? item.phone : '-',
totalInvestigate: item.totalInvestigate,
totalDisciplinary: item.totalDisciplinary,
})
);
rows.value = dataList;
}
return {
visibleColumns,
columns,
rows,
fetchData,
};
}
);