2023-10-16 18:07:42 +07:00
|
|
|
import { defineStore } from "pinia";
|
|
|
|
|
import { ref } from "vue";
|
2023-10-26 13:47:42 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2023-10-16 18:07:42 +07:00
|
|
|
|
2023-10-19 15:39:18 +07:00
|
|
|
import type { DataOption } from "@/modules/11_discipline/interface/index/Main";
|
2023-10-26 13:47:42 +07:00
|
|
|
import type { DataList, DataListRow } from "@/modules/11_discipline/interface/response/complaint"
|
2023-10-20 10:31:07 +07:00
|
|
|
import type { QTableProps } from "quasar";
|
2023-10-18 14:41:11 +07:00
|
|
|
|
2023-10-26 13:47:42 +07:00
|
|
|
const mixin = useCounterMixin()
|
|
|
|
|
const { date2Thai } = mixin
|
|
|
|
|
|
2023-10-17 17:49:31 +07:00
|
|
|
|
2023-10-19 15:39:18 +07:00
|
|
|
export const useComplainstDataStore = defineStore("DisciplineComplainst", () => {
|
2023-10-26 13:47:42 +07:00
|
|
|
const rows = ref<DataListRow[]>([])
|
2023-10-20 10:31:07 +07:00
|
|
|
const visibleColumns = ref<string[]>([]);
|
|
|
|
|
const columns = ref<QTableProps["columns"]>([]);
|
2023-10-19 15:39:18 +07:00
|
|
|
function fetchComplainst(data: DataList[]) {
|
|
|
|
|
let datalist = data.map((e: DataList) => ({
|
2023-11-06 17:50:19 +07:00
|
|
|
id: e.id,
|
2023-10-16 18:07:42 +07:00
|
|
|
subject: e.subject,
|
|
|
|
|
detail: e.detail,
|
|
|
|
|
complainant: e.complainant,
|
|
|
|
|
offenseDescription: e.offenseDescription,
|
2023-10-26 13:47:42 +07:00
|
|
|
creationDate: date2Thai(e.creationDate),
|
2023-10-16 18:07:42 +07:00
|
|
|
considerationLevel: e.considerationLevel,
|
2023-10-26 13:47:42 +07:00
|
|
|
considerationDeadlineDate: date2Thai(e.considerationDeadlineDate),
|
2023-10-16 18:07:42 +07:00
|
|
|
}))
|
|
|
|
|
rows.value = datalist
|
|
|
|
|
}
|
2023-10-20 10:31:07 +07:00
|
|
|
// filter options
|
2023-11-06 17:50:19 +07:00
|
|
|
const complainantoptionsMain = ref<DataOption[]>([
|
|
|
|
|
{ id: "0", name: "บุคคล" },
|
|
|
|
|
{ id: "1", name: "หน่ายงาน" },
|
|
|
|
|
{ id: "2", name: "กรุงเทพหมานคร" },
|
|
|
|
|
]);
|
|
|
|
|
const complainantoptions = ref<DataOption[]>(complainantoptionsMain.value)
|
|
|
|
|
const agencytoptionsMain = ref<DataOption[]>([
|
|
|
|
|
{ id: "0", name: "หน่ายงานเอ" },
|
|
|
|
|
{ id: "1", name: "หน่ายงานบี" },
|
|
|
|
|
{ id: "2", name: "หน่ายงานชี" },
|
|
|
|
|
]);
|
|
|
|
|
const agencytoptions = ref<DataOption[]>(agencytoptionsMain.value)
|
2023-10-18 14:41:11 +07:00
|
|
|
const optionListNameMain = ref<DataOption[]>([])
|
|
|
|
|
const optionListName = ref<DataOption[]>([])
|
2023-11-06 17:50:19 +07:00
|
|
|
|
2023-10-18 14:41:11 +07:00
|
|
|
function selectComplainantTpye(list: any) {
|
|
|
|
|
optionListNameMain.value = list
|
|
|
|
|
optionListName.value = list
|
2023-10-17 17:49:31 +07:00
|
|
|
}
|
2023-10-19 15:39:18 +07:00
|
|
|
function filterSelector(val: string, update: Function, type: string) {
|
2023-10-18 14:41:11 +07:00
|
|
|
update(() => {
|
2023-11-06 17:50:19 +07:00
|
|
|
const needle = val.toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (type === "filtercomplainantType") {
|
2023-10-18 14:41:11 +07:00
|
|
|
complainantoptions.value = complainantoptionsMain.value.filter(
|
2023-11-06 17:50:19 +07:00
|
|
|
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
|
2023-10-18 14:41:11 +07:00
|
|
|
);
|
2023-11-06 17:50:19 +07:00
|
|
|
|
|
|
|
|
} else if (type === "filteragencytoptions") {
|
2023-10-18 14:41:11 +07:00
|
|
|
agencytoptions.value = agencytoptionsMain.value.filter(
|
2023-11-06 17:50:19 +07:00
|
|
|
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
|
2023-10-18 14:41:11 +07:00
|
|
|
);
|
2023-11-06 17:50:19 +07:00
|
|
|
} else if (type === "filtercomplainantOP") {
|
2023-10-18 14:41:11 +07:00
|
|
|
optionListName.value = optionListNameMain.value.filter(
|
2023-11-06 17:50:19 +07:00
|
|
|
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
|
2023-10-18 14:41:11 +07:00
|
|
|
);
|
2023-10-17 17:49:31 +07:00
|
|
|
}
|
|
|
|
|
|
2023-11-06 17:50:19 +07:00
|
|
|
});
|
2023-10-17 17:49:31 +07:00
|
|
|
}
|
2023-10-20 10:31:07 +07:00
|
|
|
|
2023-10-16 18:07:42 +07:00
|
|
|
return {
|
|
|
|
|
rows,
|
2023-10-20 10:31:07 +07:00
|
|
|
visibleColumns,
|
|
|
|
|
columns,
|
2023-10-19 15:39:18 +07:00
|
|
|
fetchComplainst,
|
2023-10-17 17:49:31 +07:00
|
|
|
selectComplainantTpye,
|
|
|
|
|
filterSelector,
|
|
|
|
|
complainantoptions,
|
|
|
|
|
agencytoptions,
|
2023-10-20 10:31:07 +07:00
|
|
|
optionListName,
|
|
|
|
|
|
|
|
|
|
|
2023-10-16 18:07:42 +07:00
|
|
|
}
|
|
|
|
|
})
|