hrms-mgt/src/modules/11_discipline/store/AppealComplainStore.ts
2024-01-19 13:06:32 +07:00

135 lines
5.4 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import type { QTableProps } from "quasar";
import type { DataOption } from '@/modules/11_discipline/interface/index/Main'
import type { MainList, RowList, RowAddList } from '@/modules/11_discipline/interface/response/appealComplain'
export const useAppealComplainStore = defineStore(
"AppealComplainStore",
() => {
const rows = ref<RowList[]>([]);
const rowsAdd = ref<RowAddList[]>([]);
const visibleColumns = ref<string[]>([]);
const columns = ref<QTableProps["columns"]>([]);
const mixin = useCounterMixin()
const { date2Thai } = mixin
const typeOptions = ref<DataOption[]>([
{ id: "APPEAL", name: "อุทธรณ์" },
{ id: "COMPLAIN", name: "ร้องทุกข์" },
]);
const fiscalyearOP = ref<DataOption[]>([
{ id: "0", name: "ทั้งหมด" },
])
const statusOptions = ref<DataOption[]>([
{ id: "ALL", name: "ทั้งหมด" },
{ id: "NEW", name: "ใหม่" },
{ id: "RECEIVE_DOC", name: "ได้รับเอกสารแล้ว" },
{ id: "RECEIVE_APPEAL", name: "รับอุทธรณ์/ร้องทุกข์" },
{ id: "NO_RECEIVE_APPEAL", name: "ไม่รับอุทธรณ์/ร้องทุกข์" },
{ id: "DIAGNOSTIC", name: "ตั้งองค์คณะวินิจฉัย" },
{ id: "SUMMARY", name: "สรุปผลการพิจารณา" },
{ id: "DONE", name: "ปิดคำร้อง" },
]);
const statusOptionsEdit = ref<DataOption[]>([
{ id: "NEW", name: "ใหม่" },
{ id: "RECEIVE_DOC", name: "ได้รับเอกสารแล้ว" },
{ id: "RECEIVE_APPEAL", name: "รับอุทธรณ์/ร้องทุกข์" },
{ id: "NO_RECEIVE_APPEAL", name: "ไม่รับอุทธรณ์/ร้องทุกข์" },
{ id: "DIAGNOSTIC", name: "ตั้งองค์คณะวินิจฉัย" },
{ id: "SUMMARY", name: "สรุปผลการพิจารณา" },
{ id: "DONE", name: "ปิดคำร้อง" },
]);
/**
* ฟังชั่นแปลง status เป็น ไทย
* @param val status ที่รับมา
* @returns ส่งที่เเปลงออกไป
*/
function typeConvert(val: string){
switch (val) {
case "APPEAL":
return "อุทธรณ์";
case "COMPLAIN":
return "ร้องทุกข์";
default:
return "-";
}
};
/**
* จัดเรียงข้อมูล
* @param data ข้อมูลที่รับมาจาก API
*/
function fetchAppealComplain(data: MainList[]) {
let dataList: RowList[] = data.map((e: MainList) => ({
id: e.id,
profileId: e.profileId,
type: typeConvert(e.type),
title: e.title,
description: e.description,
year: e.year + 543,
fullname: e.fullname,
citizenId: e.citizenId,
caseType: e.caseType,
caseNumber: e.caseNumber,
lastUpdatedAt: date2Thai(e.lastUpdatedAt),
status: statusTothai(e.status)
}));
rows.value = dataList;
}
/**
* ฟังชั่นเอาไว้เก็บข้อมูล
* @param data ข้อมูลจาก list ทั้งหมด
*/
function getRow(data: RowAddList[]) {
if (data) {
rowsAdd.value = data
}
}
/**
* แปลง status เป็น Text
* @param val status
* @returns text
*/
function statusTothai(val: string) {
switch (val) {
case "NEW":
return "ใหม่";
case "RECEIVE_DOC":
return "ได้รับเอกสารแล้ว";
case "RECEIVE_APPEAL":
return "รับอุทธรณ์/ร้องทุกข์";
case "NO_RECEIVE_APPEAL":
return "ไม่รับอุทธรณ์/ร้องทุกข์";
case "DIAGNOSTIC":
return "ตั้งองค์คณะวินิจฉัย";
case "SUMMARY":
return "สรุปผลการพิจารณา";
case "DONE":
return "ปิดคำร้อง";
default:
return "-";
}
};
return {
rows,
visibleColumns,
columns,
fetchAppealComplain,
// filterSelector,
typeOptions,
statusOptions,
fiscalyearOP,
getRow,
rowsAdd,
statusOptionsEdit,
statusTothai
};
}
);