127 lines
4.1 KiB
TypeScript
127 lines
4.1 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
import type { DataOption } from "@/modules/11_discipline/interface/index/Main";
|
|
import type {
|
|
DataList,
|
|
DataListRow,
|
|
ocListType,
|
|
} from "@/modules/11_discipline/interface/response/complaint";
|
|
import type { ArrayPerson } from "@/modules/11_discipline/interface/request/complaint";
|
|
import type { QTableProps } from "quasar";
|
|
import { useDisciplineMainStore } from "@/modules/11_discipline/store";
|
|
const mainStore = useDisciplineMainStore();
|
|
|
|
const mixin = useCounterMixin();
|
|
const { date2Thai } = mixin;
|
|
|
|
export const useComplainstDataStore = defineStore(
|
|
"DisciplineComplainst",
|
|
() => {
|
|
const rows = ref<DataListRow[]>([]);
|
|
const visibleColumns = ref<string[]>([]);
|
|
const columns = ref<QTableProps["columns"]>([]);
|
|
|
|
function fetchComplainst(data: DataList[]) {
|
|
let dataList: DataListRow[] = data.map((e: DataList) => ({
|
|
id: e.id,
|
|
personId: e.personId,
|
|
title: e.title,
|
|
dateReceived: e.dateReceived ? date2Thai(e.dateReceived) : "-",
|
|
respondentType: mainStore.convertComplaintType(e.respondentType),
|
|
offenseDetails: mainStore.convertOffenseDetailst(e.offenseDetails),
|
|
createdAt: date2Thai(e.createdAt)!,
|
|
levelConsideration: levelConsiderationTran(e.levelConsideration),
|
|
dateConsideration: e.dateConsideration
|
|
? date2Thai(e.dateConsideration)
|
|
: "-",
|
|
status: statusTothai(e.status),
|
|
}));
|
|
rows.value = dataList;
|
|
}
|
|
|
|
const complainantoptions = ref<DataOption[]>(
|
|
mainStore.complainantoptionsMain
|
|
);
|
|
const consideredAgencytoptions = ref<DataOption[]>([]);
|
|
const organizationIdOp = ref<DataOption[]>([]);
|
|
|
|
const statusTothai = (val: string) => {
|
|
switch (val) {
|
|
case "NEW":
|
|
return "ใหม่";
|
|
case "STOP":
|
|
return "ยุติเรื่อง";
|
|
case "SEND_INVESTIGATE":
|
|
return "มีมูลส่งไปสืบสวนแล้ว";
|
|
default:
|
|
return "-";
|
|
}
|
|
};
|
|
|
|
const levelConsiderationtOptions = ref<DataOption[]>([
|
|
{ id: "NORMAL", name: "ปกติ" },
|
|
{ id: "URGENT", name: "ด่วน" },
|
|
{ id: "VERY_URGENT", name: "ด่วนมาก" },
|
|
]);
|
|
|
|
function levelConsiderationTran(val: string) {
|
|
return (
|
|
levelConsiderationtOptions.value.find((v: any) => v.id === val)?.name ??
|
|
"-"
|
|
);
|
|
}
|
|
|
|
const agencytoptions = ref<DataOption[]>(consideredAgencytoptions.value);
|
|
const optionListNameMain = ref<DataOption[]>([]);
|
|
const optionListName = ref<DataOption[]>([]);
|
|
|
|
function selectComplainantTpye(list: any) {
|
|
optionListNameMain.value = list;
|
|
optionListName.value = list;
|
|
}
|
|
|
|
function filterSelector(val: string, update: Function, type: string) {
|
|
update(() => {
|
|
const needle = val.toLowerCase();
|
|
if (type === "filterrespondentType") {
|
|
complainantoptions.value = mainStore.complainantoptionsMain.filter(
|
|
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
|
|
);
|
|
} else if (type === "filteragencytoptions") {
|
|
agencytoptions.value = consideredAgencytoptions.value.filter(
|
|
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
|
|
);
|
|
} else if (type === "filtercomplainantOP") {
|
|
optionListName.value = optionListNameMain.value.filter(
|
|
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
function ocListFn(data: ocListType[]) {
|
|
let dataList: DataOption[] = data.map((item: ocListType) => ({
|
|
id: item.organizationId,
|
|
name: item.organizationName,
|
|
}));
|
|
consideredAgencytoptions.value = dataList;
|
|
organizationIdOp.value = dataList;
|
|
}
|
|
return {
|
|
rows,
|
|
visibleColumns,
|
|
columns,
|
|
fetchComplainst,
|
|
selectComplainantTpye,
|
|
filterSelector,
|
|
complainantoptions,
|
|
consideredAgencytoptions,
|
|
optionListName,
|
|
organizationIdOp,
|
|
ocListFn,
|
|
levelConsiderationtOptions,
|
|
};
|
|
}
|
|
);
|