hrms-mgt/src/modules/11_discipline/store/InvestigateFactStore.ts

266 lines
8.2 KiB
TypeScript
Raw Normal View History

import { defineStore } from "pinia";
import { ref } from "vue";
import { useCounterMixin } from "@/stores/mixin";
2023-10-19 14:36:12 +07:00
import type { QTableProps } from "quasar";
import type {
InvestigatefactsDataRowType,
DataOption,
DataNumberOption,
} from "@/modules/11_discipline/interface/index/Main";
import type {
ListData,
ocListType,
} from "@/modules/11_discipline/interface/response/investigate";
2023-11-30 21:06:50 +07:00
import { useDisciplineMainStore } from "@/modules/11_discipline/store/main";
const mainStore = useDisciplineMainStore();
const mixin = useCounterMixin();
const { date2Thai } = mixin;
const organizationIdOp = ref<DataOption[]>([]);
const consideredAgencytoptions = ref<DataOption[]>([]);
function ocListFn(data: ocListType[]) {
let dataList: DataOption[] = data.map((item: ocListType) => ({
id: item.organizationId,
name: item.organizationName,
}));
consideredAgencytoptions.value = dataList;
organizationIdOp.value = dataList;
}
/*** store ของข้อมูลสืบสวนข้อเท็จจริง */
export const useInvestigateFactStore = defineStore(
"DisciplineInvestigateFact",
() => {
const tabMenu = ref<string>("investigatefacts");
const daysExtendOps = ref<DataNumberOption[]>([
{ id: 15, name: "15 วัน" },
{ id: 30, name: "30 วัน" },
{ id: 45, name: "45 วัน" },
{ id: 60, name: "60 วัน" },
]);
const investigationDetailOps = ref<DataOption[]>([
{ id: "APPOINT_DIRECTORS", name: "แต่งตั้งกรรมการสืบสวน" },
{ id: "SECRET_INVESTIGATION", name: "สืบสวนทางลับ" },
{ id: "OTHER", name: "อื่นๆ" },
]);
const faultOps = ref<DataOption[]>([
{ id: "NEW", name: "กำลังสืบสวน" },
{ id: "STOP", name: "ยุติเรื่อง" },
{ id: "SEND_DISCIPLINARY", name: "ส่งไปสอบสวนแล้ว" },
]);
const daysExtendOp = ref<DataNumberOption[]>(daysExtendOps.value);
const investigationDetailOp = ref<DataOption[]>(
investigationDetailOps.value
);
const faultOp = ref<DataOption[]>(faultOps.value);
2023-10-19 14:36:12 +07:00
const visibleColumns = ref<string[]>([
"no",
"title",
"respondentType",
"offenseDetails",
"investigationDetail",
"dateInvestigate",
"investigationStatusResult",
2023-12-15 17:29:47 +07:00
"createdAt",
"status",
]);
2023-10-19 14:36:12 +07:00
// หัวตาราง
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "center",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "title",
align: "left",
label: "เรื่องร้องเรียน",
sortable: true,
field: "title",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "respondentType",
align: "left",
2023-12-04 14:28:17 +07:00
label: "ผู้ถูกสืบสวน",
sortable: true,
field: "respondentType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "offenseDetails",
align: "left",
label: "ลักษณะความผิด",
sortable: true,
field: "offenseDetails",
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: "investigationStatusResult",
align: "left",
label: "ผลการสืบสวน",
sortable: true,
field: "investigationStatusResult",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
2023-12-15 17:29:47 +07:00
{
name: "createdAt",
align: "left",
label: "วันที่รับเรื่อง",
2023-12-15 17:29:47 +07:00
sortable: true,
field: "createdAt",
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",
},
2023-10-19 14:36:12 +07:00
]);
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") {
investigationDetailOp.value = investigationDetailOps.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<InvestigatefactsDataRowType[]>();
const respondentTypeOps = ref<DataOption[]>(
mainStore.complainantoptionsMain
);
function filterSelector(val: string, update: Function, type: string) {
console.log(val);
update(() => {
const needle = val.toLowerCase();
if (type === "filtercomplainantType") {
respondentTypeOps.value = mainStore.complainantoptionsMain.filter(
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
}
});
}
async function fecthList(data: ListData[]) {
rows.value = await data.map((e: ListData) => {
return {
id: e.id,
title: e.title,
respondentType: mainStore.convertComplaintType(e.respondentType),
offenseDetails: mainStore.convertOffenseDetailst(e.offenseDetails),
investigationDetail: convertInvestigationDetail(
e.investigationDetail
),
dateInvestigate:
e.investigationDateStart && e.investigationDateEnd
? `${date2Thai(e.investigationDateStart)} - ${date2Thai(
e.investigationDateEnd
)}`
: "-",
investigationStatusResult: mainStore.convertStatusResult(
e.investigationStatusResult
),
2023-12-15 17:29:47 +07:00
createdAt: date2Thai(e.createdAt as Date),
status: convertStatus(e.status),
};
});
}
function convertInvestigationDetail(val: string) {
const result = investigationDetailOps.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 : "-";
}
return {
tabMenu,
fecthList,
rows,
daysExtendOps,
investigationDetailOps,
faultOps,
filterFnOptionsType,
faultOp,
daysExtendOp,
investigationDetailOp,
visibleColumns,
columns,
filterSelector,
respondentTypeOps,
organizationIdOp,
ocListFn,
};
}
);