hrms-user/src/modules/07_appealComplain/store.ts

108 lines
3.5 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from 'vue'
import { useCounterMixin } from "@/stores/mixin";
import type { DataOption } from "@/modules/07_appealComplain/interface/index/main";
import type { QTableProps } from "quasar";
import type { RowList, MainList } from '@/modules/07_appealComplain/interface/response/mainType'
export const useAppealComplainStore = defineStore("appealComplainStore", () => {
const mixin = useCounterMixin()
const { date2Thai } = mixin
const rows = ref<RowList[]>([]);
const visibleColumns = ref<string[]>([]);
const columns = ref<QTableProps["columns"]>([]);
const typeOptions = ref<DataOption[]>([
{ id: "APPEAL", name: "อุทธรณ์" },
{ id: "COMPLAIN", 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: "ปิดคำร้อง" },
]);
/**
* จัดข้อมูลที่ได้รับมา
* @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;
}
/**
* แปลงข้อมูลที่รับมา เป็น text
* @param val status
* @returns ส่งค่าที่แปลง ออกไป
*/
const typeConvert = (val: string) => {
switch (val) {
case "APPEAL":
return "อุทธรณ์";
case "COMPLAIN":
return "ร้องทุกข์";
default:
return "-";
}
};
/**
* แปลงข้อมูลที่รับมา เป็น text
* @param val status
* @returns ส่งค่าที่แปลง ออกไป
*/
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 {
visibleColumns,
columns,
fetchAppealComplain,
rows,
typeOptions,
statusOptions,
statusTothai
};
});