import { defineStore } from "pinia"; import { ref } from "vue"; import { useCounterMixin } from "@/stores/mixin"; import type { QTableProps } from "quasar"; import type { InvestigatefactsDataRowType, DataOption, DataNumberOption, } from "@/modules/11_discipline/interface/index/Main"; import type { ListData } from "@/modules/11_discipline/interface/response/investigate"; const mixin = useCounterMixin(); const { date2Thai } = mixin; /*** store ของข้อมูลสืบสวนข้อเท็จจริง */ export const useInvestigateFactStore = defineStore( "DisciplineInvestigateFact", () => { const tabMenu = ref("investigatefacts"); const daysExtendOps = ref([ { id: 15, name: "15 วัน" }, { id: 30, name: "30 วัน" }, { id: 45, name: "45 วัน" }, { id: 60, name: "60 วัน" }, ]); const offenseDetailsOps = ref([ { id: "NOT_SPECIFIED", name: "ยังไม่ระบุ" }, { id: "NOT_DEADLY", name: "ไม่ร้ายแรง" }, { id: "DEADLY", name: "ร้ายแรง" }, ]); const investigationOps = ref([ { id: "appoint_directors", name: "แต่งตั้งกรรมการสืบสวน" }, { id: "secret_investigation", name: "สืบสวนทางลับ" }, { id: "other", name: "อื่นๆ" }, ]); const faultOps = ref([ { id: "new", name: "กำลังสืบสวน" }, { id: "stop", name: "ยุติเรื่อง" }, { id: "complete", name: "ส่งไปสอบสวน" }, ]); const statusResultOptions = ref([ { id: "not_specified", name: "ยังไม่ระบุ" }, { id: "have_cause", name: "มีมูล" }, { id: "no_cause", name: "ไม่มีมูล" }, ]); const causeTextOptions = ref([ { id: "ร้ายแรง", name: "ร้ายแรง" }, { id: "ไม่ร้ายแรง", name: "ไม่ร้ายแรง" }, ]); const daysExtendOp = ref(daysExtendOps.value); const investigationOp = ref(investigationOps.value); const faultOp = ref(faultOps.value); const visibleColumns = ref([ "no", "subject", "interrogated", "complaintOffenseDetails", "investigationDetail", "dateInvestigate", "statusResult", "status", ]); // หัวตาราง const columns = ref([ { name: "no", align: "center", label: "ลำดับ", sortable: false, field: "no", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { name: "subject", align: "left", label: "เรื่องร้องเรียน", sortable: true, field: "subject", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { name: "interrogated", align: "left", label: "ผู้ถูกสอบสวน", sortable: true, field: "interrogated", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { name: "complaintOffenseDetails", align: "left", label: "ลักษณะความผิด", sortable: true, field: "complaintOffenseDetails", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { name: "investigationDetail", align: "left", label: "ลักษณะการสืบสวน", sortable: true, field: "investigationDetail", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { name: "dateInvestigate", align: "left", label: "วันที่สืบสวน", sortable: true, field: "dateInvestigate", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { name: "statusResult", align: "left", label: "ผลการสืบสวน", sortable: true, field: "statusResult", headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, { name: "status", align: "left", label: "สถานะ", sortable: false, field: "status", headerStyle: "font-size: 14px", style: "font-size: 14px", }, ]); function filterFnOptionsType( val: string | number, update: any, type: string ) { update(() => { if (type === "faultOp") { faultOp.value = faultOps.value.filter( (v: any) => v.name.toLowerCase().indexOf(val) > -1 ); } else if (type === "investigationOp") { investigationOp.value = investigationOps.value.filter( (v: any) => v.name.toLowerCase().indexOf(val) > -1 ); } else if (type === "daysExtendOp") { daysExtendOp.value = daysExtendOps.value.filter( (v: any) => v.id.indexOf(val) > -1 ); } }); } const rows = ref(); async function fecthList(data: ListData[]) { rows.value = await data.map((e: ListData) => { return { id: e.id, subject: e.subject, interrogated: e.interrogated, complaintOffenseDetails: convertOffenseDetails( e.complaintOffenseDetails ), investigationDetail: convertInvestigationDetail( e.investigationDetail ), dateInvestigate: e.startDate && e.endDate ? `${date2Thai(e.startDate)} - ${date2Thai(e.endDate)}` : "-", statusResult: activeStatusResult(e.statusResult), status: convertStatus(e.status), }; }); } function convertOffenseDetails(val: string) { const result = offenseDetailsOps.value.find((x: any) => x.id == val)?.name; return result ? result : "-"; } function convertInvestigationDetail(val: string) { const result = investigationOps.value.find((x: any) => x.id == val)?.name; return result ? result : "-"; } function convertStatus(val: string) { const result = faultOps.value.find((x: any) => x.id == val)?.name; return result ? result : "-"; } function activeStatusResult(val: string) { const result = statusResultOptions.value.find( (x: any) => x.id == val )?.name; return result ? result : "-"; } return { tabMenu, fecthList, rows, daysExtendOps, investigationOps, faultOps, filterFnOptionsType, faultOp, daysExtendOp, investigationOp, visibleColumns, columns, statusResultOptions, causeTextOptions, }; } );