ต่อ api เพิ่ม form การลา

This commit is contained in:
AnandaTon 2023-12-07 18:43:52 +07:00
parent 8b7d83e1d7
commit 26667a4d22
20 changed files with 1555 additions and 750 deletions

View file

@ -1,257 +1,263 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { defineStore } from "pinia"
import { ref } from "vue"
import { useQuasar } from "quasar"
import type { QTableProps } from "quasar";
import type {
OptionData,
TypeLeave,
} from "@/modules/05_leave/interface/index/main";
import type {
ListLeave,
ListLeaveTable,
} from "@/modules/05_leave/interface/response/leave";
import type { QTableProps } from "quasar"
import type { OptionData, TypeLeave } from "@/modules/05_leave/interface/index/main"
import type { ListLeave, ListLeaveTable } from "@/modules/05_leave/interface/response/leave"
import http from "@/plugins/http"
import config from "@/app.config"
import { useCounterMixin } from "@/stores/mixin";
const mixin = useCounterMixin();
const { date2Thai } = mixin;
import { useCounterMixin } from "@/stores/mixin"
const mixin = useCounterMixin()
const { date2Thai, messageError } = mixin
const $q = useQuasar()
export const useLeaveStore = defineStore("Leave", () => {
const tabValue = ref<string>("calendar");
const typeLeave = ref<string | undefined>("");
const tabValue = ref<string>("calendar")
const typeLeave = ref<string | undefined>("")
const LeaveType = ref<string | null>("0");
const LeaveStatus = ref<string | null>("0");
const fiscalYearyear = ref<Number | null>(new Date().getFullYear());
const rows = ref<ListLeaveTable[]>([]);
const LeaveType = ref<string | null>("0")
const LeaveStatus = ref<string | null>("0")
const fiscalYearyear = ref<Number | null>(new Date().getFullYear())
const rows = ref<ListLeaveTable[]>([])
/**
* function Table
* @param data Table
*/
async function fetchListLeave(data: ListLeave[]) {
let datalist: ListLeaveTable[] = data.map((e: ListLeave) => ({
id: e.id,
leaveTypeName: e.leaveTypeName,
leaveTypeId: e.leaveTypeId,
fullName: e.fullName,
dateSendLeave: e.dateSendLeave && date2Thai(e.dateSendLeave),
status: e.status,
statusConvert: convertStatud(e.status),
isDelete: e.isDelete,
}));
rows.value = datalist;
}
/**
* function Table
* @param data Table
*/
async function fetchListLeave(data: ListLeave[]) {
let datalist: ListLeaveTable[] = data.map((e: ListLeave) => ({
id: e.id,
leaveTypeName: e.leaveTypeName,
leaveTypeId: e.leaveTypeId,
fullName: e.fullName,
dateSendLeave: e.dateSendLeave && date2Thai(e.dateSendLeave),
status: e.status,
statusConvert: convertStatud(e.status),
isDelete: e.isDelete,
}))
rows.value = datalist
}
function convertStatud(val: string) {
switch (val) {
case "NEW":
return "ใหม่";
case "PENDING":
return "กำลังดำเนินการ";
case "APPROVE":
return "อนุมัติ";
case "REJECT":
return "ไม่อนุมัติ";
case "DELETE":
return "ยกเลิก";
}
}
function convertStatud(val: string) {
switch (val) {
case "NEW":
return "ใหม่"
case "PENDING":
return "กำลังดำเนินการ"
case "APPROVE":
return "อนุมัติ"
case "REJECT":
return "ไม่อนุมัติ"
case "DELETE":
return "ยกเลิก"
}
}
/** ประเภทการลา */
const typeOptions = ref<OptionData[]>([]);
const typeOptionsMain = ref<OptionData[]>([]);
/**
* function
* @param data
*/
async function fetchLeaveType(data: TypeLeave[]) {
typeOptionsMain.value = [
{ id: "00000000-0000-0000-0000-000000000000", name: "ทั้งหมด" },
];
const optionType = data.map((e: TypeLeave) => ({
id: e.id,
name: e.name,
}));
typeOptionsMain.value.push(...optionType);
typeOptions.value = typeOptionsMain.value;
}
/** ประเภทการลา */
const typeOptions = ref<OptionData[]>([])
const typeId = ref<string | undefined>("")
const typeOptionsMain = ref<OptionData[]>([])
const typeOptionsAdd = ref<OptionData[]>([])
/** รายการข้อมูลประเภทใบลา */
const options = ref<OptionData[]>([])
/**
* function
* @param data
*/
async function fetchLeaveType(data: TypeLeave[]) {
typeOptionsMain.value = [{ id: "00000000-0000-0000-0000-000000000000", name: "ทั้งหมด", code: "LV-000" }]
const optionType = data.map((e: TypeLeave) => ({
id: e.id,
name: e.name,
code: e.code,
}))
typeOptionsMain.value.push(...optionType)
typeOptions.value = typeOptionsMain.value
console.log(typeOptions.value)
/** สถานะของการลา */
const statusOptionsMain = ref<OptionData[]>([
{ id: "ALL", name: "ทั้งหมด" },
{ id: "NEW", name: "ใหม่" },
{ id: "PENDING", name: "กำลังดำเนินการ" },
{ id: "APPROVE", name: "อนุมัติ " },
{ id: "REJECT", name: "ไม่อนุมัติ" },
{ id: "DELETE", name: "ยกเลิก" },
]);
const statusOptions = ref<OptionData[]>(statusOptionsMain.value);
typeOptionsAdd.value.push(...optionType)
options.value = typeOptionsAdd.value
console.log(options.value)
}
/**
* function Option
* @param val
* @param update
* @param refData
*/
function filterOption(val: any, update: Function, refData: string) {
switch (refData) {
case "LeaveTypeOption":
update(() => {
typeOptions.value = typeOptionsMain.value.filter(
(v: any) => v.name.indexOf(val) > -1
);
});
break;
case "LeaveStatusOption":
update(() => {
statusOptions.value = statusOptionsMain.value.filter(
(v: any) => v.name.indexOf(val) > -1
);
});
break;
default:
break;
}
}
/** สถานะของการลา */
const statusOptionsMain = ref<any[]>([
{ id: "ALL", name: "ทั้งหมด" },
{ id: "NEW ", name: "ใหม่" },
{ id: "PENDING ", name: "กำลังดำเนินการ" },
{ id: "APPROVE ", name: "อนุมัติ " },
{ id: "REJECT ", name: "ไม่อนุมัติ" },
{ id: "DELETE ", name: "ยกเลิก" },
])
const statusOptions = ref<any[]>(statusOptionsMain.value)
/** รายการประเภทการลาของ ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน*/
const optionsSpecific = ref([
{ id: "s0", name: "ลาไปศึกษาต่อ" },
{ id: "s1", name: "ลาฝึกอบรม" },
{ id: "s2", name: "ลาปฎิบัติการวิจัย" },
{ id: "s3", name: "ลาดูงาน" },
]);
/**
* function Option
* @param val
* @param update
* @param refData
*/
function filterOption(val: any, update: Function, refData: string) {
switch (refData) {
case "LeaveTypeOption":
update(() => {
typeOptions.value = typeOptionsMain.value.filter((v: any) => v.name.indexOf(val) > -1)
})
break
case "LeaveStatusOption":
update(() => {
statusOptions.value = statusOptionsMain.value.filter((v: any) => v.name.indexOf(val) > -1)
})
break
default:
break
}
}
/** รายการประเภทการลาของ ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน*/
const optionsSpecific = ref([
{ id: "s0", name: "ลาไปศึกษาต่อ", code: "s0" },
{ id: "s1", name: "ลาฝึกอบรม", code: "s1" },
{ id: "s2", name: "ลาปฎิบัติการวิจัย", code: "s2" },
{ id: "s3", name: "ลาดูงาน", code: "s3" },
])
/** รายการประเภทการลาของ ลาอุปสมบทหรือลาประกอบพิธีฮัจย์ฯ*/
const optionsOrdination = ref([
{ id: "0", name: "ลาอุปสมบท" },
{ id: "1", name: "ลาประกอบพิธีฮัจย์ฯ" },
]);
/** รายการประเภทการลาของ ลาอุปสมบทหรือลาประกอบพิธีฮัจย์ฯ*/
const optionsOrdination = ref([
{ id: "0", name: "ลาอุปสมบท", code: "0" },
{ id: "1", name: "ลาประกอบพิธีฮัจย์ฯ", code: "1" },
])
/** รายการข้อมูลประเภทใบลา */
const options = ref<OptionData[]>([
{ id: "1", name: "ลาป่วย" },
{ id: "2", name: "ลากิจส่วนตัว" },
{ id: "3", name: "ลาคลอดบุตร" },
{ id: "4", name: "ลาไปช่วยเหลือภริยาที่คลอดบุตร" },
{ id: "5", name: "ลาพักผ่อน" },
{ id: "6", name: "ลาอุปสมบทหรือลาประกอบพิธีฮัจย์ฯ" },
{ id: "7", name: "ลาเข้ารับการตรวจเลือกหรือเข้ารับการเตรียมพล" },
{ id: "8", name: "ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน" },
{ id: "9", name: "ลาไปปฎิบัติงานในองค์การระหว่างประเทศ" },
{ id: "10", name: "ลาติดตามคู่สมรส" },
{ id: "11", name: "ลาไปฟื้นฟูสมรรถภาพด้านอาชีพ" },
]);
/** data table filter & column ของรายการลา */
const visibleColumns = ref<String[]>(["no", "leaveTypeName", "dateSendLeave", "status"])
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:5%;",
},
{
name: "leaveTypeName",
align: "left",
label: "ประเภทการลา",
sortable: true,
field: "leaveTypeName",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "dateSendLeave",
align: "left",
label: "วันที่ยื่นใบลา",
sortable: true,
field: "dateSendLeave",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "status",
align: "left",
label: "สถานะ",
sortable: true,
field: "status",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:10%;",
},
])
/**
*
* @param item
* @param subitem
*/
function typeConvert(item: string, subitem: any) {
// console.log('first',item)
if (item !== "LV-006" && item !== "LV-008") {
typeLeave.value = convertSubtitle(item)
} else if (item === "LV-006") {
typeLeave.value = convertSubtitleInfo(subitem)
} else if (item === "LV-008") {
typeLeave.value = convertSubtitleInfo2(subitem)
}
typeId.value = convertId(item)
console.log(typeId.value)
}
/** data table filter & column ของรายการลา */
const visibleColumns = ref<String[]>([
"no",
"leaveTypeName",
"dateSendLeave",
"status",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:5%;",
},
{
name: "leaveTypeName",
align: "left",
label: "ประเภทการลา",
sortable: true,
field: "leaveTypeName",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "dateSendLeave",
align: "left",
label: "วันที่ยื่นใบลา",
sortable: true,
field: "dateSendLeave",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "status",
align: "left",
label: "สถานะ",
sortable: true,
field: "status",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:10%;",
},
]);
/**
* /
* @param val string
* @returns
*/
function convertSubtitle(val: string) {
return options.value.find(x => x.id == val)?.name
}
/**
*
* @param item
* @param subitem
*/
function typeConvert(item: string, subitem: any) {
// console.log('first',item)
if (item !== "6" && item !== "8") {
typeLeave.value = convertSubtitle(item);
} else if (item === "6") {
typeLeave.value = convertSubtitleInfo(subitem);
} else if (item === "8") {
typeLeave.value = convertSubtitleInfo2(subitem);
}
}
/**
* /
* @param val string
* @returns
*/
function convertSubtitleInfo(val: string) {
return optionsOrdination.value.find(x => x.id == val)?.name
}
/**
* /
* @param val string
* @returns
*/
function convertSubtitle(val: string) {
return options.value.find((x) => x.id == val)?.name;
}
/**
*
* @param val string
* @returns
*/
function convertSubtitleInfo2(val: string) {
return optionsSpecific.value.find(x => x.id == val)?.name
}
/**
* /
* @param val string
* @returns
*/
function convertSubtitleInfo(val: string) {
return optionsOrdination.value.find((x) => x.id == val)?.name;
}
/**
* id
* @param val string
* @returns
*/
function convertId(val: string) {
return options.value.find(x => x.code == val)?.id
}
/**
*
* @param val string
* @returns
*/
function convertSubtitleInfo2(val: string) {
return optionsSpecific.value.find((x) => x.id == val)?.name;
}
async function fetchProfile() {
console.log("profile")
await http
.post(config.API.leaveProfile(), { type: typeId.value })
.then((res: any) => {
const data = res.data.result
console.log(data.va)
})
.catch((e: any) => {
messageError($q, e)
})
}
return {
tabValue,
typeOptions,
optionsSpecific,
statusOptions,
return {
tabValue,
typeOptions,
optionsSpecific,
statusOptions,
visibleColumns,
columns,
rows,
LeaveType,
LeaveStatus,
visibleColumns,
columns,
rows,
LeaveType,
LeaveStatus,
fiscalYearyear,
options,
optionsOrdination,
typeConvert,
typeLeave,
fiscalYearyear,
options,
optionsOrdination,
typeConvert,
typeLeave,
typeId,
fetchListLeave,
fetchLeaveType,
filterOption,
};
});
fetchListLeave,
fetchLeaveType,
filterOption,
fetchProfile,
}
})