hrms-mgt/src/modules/09_leave/stores/ChangeRoundStore.ts

168 lines
5.7 KiB
TypeScript
Raw Normal View History

import { defineStore } from "pinia";
import { ref, reactive } from "vue";
import type { changeShow, dataRowChangeRound, dataRowChangeRoundHistory, historyShow } from "@/modules/09_leave/interface/response/changeRound";
import type { dataPost } from "@/modules/09_leave/interface/request/changeRound";
import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
const mixin = useCounterMixin()
const { date2Thai } = mixin
const checkCilck = ref<boolean>(false)
// store ลา >> รอบการปฏิบัติงาน
export const useChangeRoundDataStore = defineStore(
"changeRoundDataStore",
() => {
//ค้นหา คอลัมน์ คอลัมน์ที่แสดง
const visibleColumns = ref<string[]>([
"cardId",
"fullName",
"currentRound",
"effectiveDate"
]);
const visibleColumnsHistory = ref<string[]>([
"round",
"time",
"effectiveDate",
"reson"
]);
// หัวตาราง
const columns = ref<QTableProps["columns"]>([
{
name: "cardId",
align: "left",
label: "เลขบัตรประชาชน",
sortable: true,
field: "cardId",
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: "currentRound",
align: "left",
label: "รอบปัจจุบัน",
sortable: true,
field: "currentRound",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "effectiveDate",
align: "left",
label: "วันที่มีผล",
sortable: true,
field: "effectiveDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const columnsHistory = ref<QTableProps["columns"]>([
{
name: "round",
align: "left",
label: "ครั้งที่",
sortable: true,
field: "round",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "time",
align: "left",
label: "รอบเวลา",
sortable: true,
field: "time",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "effectiveDate",
align: "left",
label: "วันที่มีผล",
sortable: true,
field: "effectiveDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "reson",
align: "left",
label: "เหตุผล",
sortable: true,
field: "reson",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
// ข้อมูลในตาราง
const rows = ref<changeShow[]>([]);
const rowsHistory = ref<historyShow[]>([]);
function fetchDatainHistory(data: dataRowChangeRoundHistory[]) {
let datalistHistory: historyShow[] = data.map((e: dataRowChangeRoundHistory) => {
return {
id: e.id,
time: `${e.roundStart}-${e.roundEnd}`,
effectiveDate: date2Thai(e.effectiveDate),
reson: e.reson ?? '-'
};
});
rowsHistory.value = datalistHistory;
}
function fetchDataForCardId(dataDetail: any, data: any) {
if (dataDetail) {
const filteredData = data.filter((e:any) => {
return (!dataDetail.cardId || e.cardId === dataDetail.cardId) &&
(!dataDetail.firstName || e.firstName === dataDetail.firstName) &&
(!dataDetail.lastName || e.lastName === dataDetail.lastName);
});
if (filteredData.length > 0) {
checkCilck.value = false;
rows.value = filteredData.map((e:any) => ({
cardId: e.cardId,
prefix: e.prefix,
firstName: e.firstName,
lastName: e.lastName,
fullName: `${e.prefix}${e.firstName} ${e.lastName}`,
roundStart: e.roundStart,
roundEnd: e.roundEnd,
currentRound: `${e.roundStart}-${e.roundEnd}`,
effectiveDate: date2Thai(e.effectiveDate),
}));
} else {
rows.value = [];
console.log(3);
checkCilck.value = true;
}
}
}
return {
visibleColumns,
columns,
columnsHistory,
rows,
rowsHistory,
fetchDatainHistory,
visibleColumnsHistory,
fetchDataForCardId,
checkCilck
};
}
);