142 lines
No EOL
4.7 KiB
TypeScript
142 lines
No EOL
4.7 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, DataAdd, ArrayPerson,ocListType } from "@/modules/11_discipline/interface/response/complaint"
|
|
import type { QTableProps } from "quasar";
|
|
|
|
const mixin = useCounterMixin()
|
|
const { date2Thai } = mixin
|
|
|
|
// id
|
|
// cardId
|
|
// prefix
|
|
// firstName
|
|
// lastName
|
|
// position
|
|
// level
|
|
// oc
|
|
export const useComplainstDataStore = defineStore("DisciplineComplainst", () => {
|
|
const rows = ref<DataListRow[]>([])
|
|
const rowsAdd = ref<ArrayPerson[]>([])
|
|
const visibleColumns = ref<string[]>([]);
|
|
const columns = ref<QTableProps["columns"]>([]);
|
|
|
|
function fetchComplainstAdd(data: ArrayPerson[]) {
|
|
rowsAdd.value = data
|
|
}
|
|
|
|
function addCommas(salaryString: string): string {
|
|
const salaryNumber = parseFloat(salaryString.replace(/,/g, ''));
|
|
return salaryNumber.toLocaleString();
|
|
}
|
|
|
|
function fetchComplainst(data: DataList[]) {
|
|
let datalist: DataListRow[] = data.map((e: DataList) => ({
|
|
id: e.id,
|
|
title: e.title,
|
|
description: e.description,
|
|
appellant: e.appellant,
|
|
offenseDetails: offenseDetailsTran(e.offenseDetails),
|
|
createdAt: date2Thai(e.createdAt)!,
|
|
levelConsideration: levelConsiderationTran(e.levelConsideration),
|
|
dateConsideration: date2Thai(e.dateConsideration)!,
|
|
status: statusTothai(e.status),
|
|
}));
|
|
rows.value = datalist;
|
|
}
|
|
|
|
// filter options
|
|
const complainantoptionsMain = ref<DataOption[]>([
|
|
{ id: "PERSON", name: "บุคคล" },
|
|
{ id: "ORGANIZATION", name: "หน่วยงาน" },
|
|
{ id: "BANGKOK", name: "กรุงเทพมหานคร" },
|
|
]);
|
|
const complainantoptions = ref<DataOption[]>(complainantoptionsMain.value)
|
|
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 "-";
|
|
}
|
|
};
|
|
|
|
function offenseDetailsTran(val: string){
|
|
switch (val) {
|
|
case 'NOT_SPECIFIED': return "ยังไม่ระบุ";
|
|
case 'NOT_DEADLY': return "ร้ายแรง";
|
|
case 'DEADLY': return "ไม่ร้ายแรง";
|
|
default: return "-";
|
|
}
|
|
}
|
|
function levelConsiderationTran(val: string){
|
|
switch (val) {
|
|
case 'NORMAL': return "ปกติ";
|
|
case 'URGENT': return "ด่วน";
|
|
case 'VERT_URGENT': return "ด่วนมาก";
|
|
default: return "-";
|
|
}
|
|
}
|
|
|
|
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 === "filtercomplainantType") {
|
|
complainantoptions.value = complainantoptionsMain.value.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,
|
|
rowsAdd,
|
|
visibleColumns,
|
|
columns,
|
|
fetchComplainst,
|
|
selectComplainantTpye,
|
|
filterSelector,
|
|
complainantoptions,
|
|
consideredAgencytoptions,
|
|
optionListName,
|
|
fetchComplainstAdd,
|
|
organizationIdOp,
|
|
ocListFn
|
|
|
|
|
|
}
|
|
}) |