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(false) // store ลา >> รอบการปฏิบัติงาน export const useChangeRoundDataStore = defineStore( "changeRoundDataStore", () => { //ค้นหา คอลัมน์ คอลัมน์ที่แสดง const visibleColumns = ref([ "cardId", "fullName", "currentRound", "effectiveDate" ]); const visibleColumnsHistory = ref([ "round", "time", "effectiveDate", "reson" ]); // หัวตาราง const columns = ref([ { 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([ { 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([]); const rowsHistory = ref([]); 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 }; } );