hrms-mgt/src/modules/07_insignia/storeAllocate.ts

108 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-08-26 15:59:09 +07:00
import { defineStore } from "pinia";
import { ref } from "vue";
2023-08-26 15:59:09 +07:00
export const useAllocateDataStore = defineStore("insigniaallocate", () => {
const roundId = ref<string>("");
const roundYear = ref<number>();
const insigniaName = ref<string>("");
const insignia = ref<string>("");
const insigniaOp = ref<any[]>([{ name: "ทั้งหมด", id: "", type: "" }]);
const insigniaType = ref<any>();
const rows = ref<any>([]);
const listInsignia = ref<any>([]);
const mainTab = ref<string>("");
const type = ref<any[]>([]);
/**
* function
* @param data
*/
async function fetchDatainsignia(data: any) {
insigniaOp.value = [{ name: "ทั้งหมด", id: "", type: "" }];
2023-08-26 15:59:09 +07:00
data.forEach((e: any) => {
insigniaOp.value.push({
name: `${e.name} (${e.shortName})`,
id: e.id,
type: e.insigniaType.id,
});
2023-08-26 15:59:09 +07:00
});
data.forEach((e: any) => {
type.value.push({
name: e.name,
shortName: e.shortName,
});
});
2023-08-26 15:59:09 +07:00
}
/**
* function
* @param data
*/
async function fetchDatainsigniaType(data: any) {
insigniaType.value = data.map((e: any) => ({ name: e.id, label: e.name }));
2023-08-26 15:59:09 +07:00
}
/**
* function
* @param data
*/
async function listinsignia(data: any) {
2023-08-26 15:59:09 +07:00
rows.value = [];
let list = await data.map((e: any) => ({
2023-08-26 15:59:09 +07:00
id: e.id,
insignia: `${e.insignia} (${
type.value.find((item) => item.name === e.insignia)?.shortName || ""
})`,
insigniaId: e.insigniaId,
total: e.total,
allocate: e.allocate,
remain: e.remain,
year: e.year,
}));
rows.value = list;
listInsignia.value = list;
selectInsignia(insignia.value);
2023-08-26 15:59:09 +07:00
}
2023-08-28 16:38:04 +07:00
/**
* function
* @param type
*/
function selectInsignia(type: string) {
insignia.value = type;
if (insignia.value !== "") {
rows.value = listInsignia.value.filter(
(e: any) => e.insigniaId === insignia.value
);
} else rows.value = listInsignia.value;
2023-08-26 15:59:09 +07:00
}
/**
* function convert
* @param val
*/
function profileType(val: string) {
2023-08-26 15:59:09 +07:00
switch (val) {
case "officer":
return "ข้าราชการ กทม.สามัญ";
case "employee":
return "ลูกจ้างประจำ";
}
}
return {
2023-09-15 17:22:58 +07:00
roundId,
roundYear,
2023-08-26 15:59:09 +07:00
rows,
insignia,
insigniaOp,
insigniaType,
fetchDatainsignia,
fetchDatainsigniaType,
listinsignia,
selectInsignia,
2023-08-26 15:59:09 +07:00
profileType,
insigniaName,
mainTab,
2023-08-26 15:59:09 +07:00
};
});