paging รายการลา

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2023-11-17 15:28:03 +07:00
parent 45ef9649e1
commit 817d4da196
8 changed files with 248 additions and 192 deletions

View file

@ -3,43 +3,20 @@ import { ref, onMounted } from "vue";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { DataOption } from "@/modules/09_leave/interface/index/Main";
import type { QTableProps } from "quasar";
import type { DataRows } from "@/modules/09_leave/interface/response/leave";
import type {
ListsData,
FremData,
} from "@/modules/09_leave/interface/request/leave";
import type { FremData } from "@/modules/09_leave/interface/request/leave";
const mixin = useCounterMixin();
const { date2Thai, showLoader, hideLoader } = mixin;
export const useLeavelistDataStore = defineStore("leave", () => {
/** TABMENU*/
const amounttab1 = ref<number>(0);
const amounttab2 = ref<number>(0);
/**ข้อมูลใน Table*/
const mainData = ref<any>([]);
const rows = ref<DataRows[]>([]);
const columns = ref<QTableProps["columns"]>([]);
const visibleColumns = ref<string[]>([]);
const loadTable = ref<boolean>(false);
const leaveOp = [
{ id: "all", name: "ทั้งหมด" },
{ id: "leave1", name: "ลากิจส่วนตัว" },
{ id: "leave2", name: "ลาป่วย" },
];
const statusOp = [
{ id: "all", name: "ทั้งหมด" },
{ id: "NEW", name: "ใหม่" },
{ id: "PENDING", name: "อยู่ระหว่างดำเนินการ" },
{ id: "APPROVE", name: "อนุมัติ" },
{ id: "REJECT", name: "ไม่อนุมัติ" },
];
const leaveOps = ref<any>(leaveOp);
const statusOps = ref<any>(statusOp);
/**
* fetchList
* @param data Page
@ -55,101 +32,7 @@ export const useLeavelistDataStore = defineStore("leave", () => {
}));
console.log(datalist);
mainData.value = datalist;
// const filteramounttab1 = datalist.filter((e) => e.status === "PENDING");
// amounttab1.value = filteramounttab1.length;
// amounttab2.value = datalist.length;
await searchDataFn(selectType.value, selectStatus.value);
}
/**ref ของการค้นหาข้อมูล */
const selectYear = ref<string>("all");
const selectType = ref<string>("all");
const selectStatus = ref<string>("all");
const optionYear = ref<DataOption[]>([{ id: "all", name: "ทั้งหมด" }]);
const optionType = ref<DataOption[]>([]);
const optionStatus = ref<DataOption[]>([]);
const optionTypeMain = ref<DataOption[]>([]);
const optionStatusMain = ref<DataOption[]>([]);
const filterTable = ref<string>("");
/**
* Table
* @param type
* @param status
*/
function searchDataFn(type: string, status: string) {
type = type || "all";
status = convertSatatus(status) || "all";
// showLoader()
loadTable.value = true;
if (selectYear.value == "all" && type == "all" && status == "all") {
console.log(1);
rows.value = mainData.value;
} else if (selectYear.value !== "all" && type == "all" && status == "all") {
console.log(2);
} else if (selectYear.value == "all" && type !== "all" && status == "all") {
console.log(3);
rows.value = mainData.value.filter((e: any) => e.leaveTypeId === type);
} else if (selectYear.value == "all" && type == "all" && status !== "all") {
console.log(4);
console.log(status);
rows.value = mainData.value.filter((e: any) => e.status === status);
} else if (
selectYear.value !== "all" &&
type !== "all" &&
status == "all"
) {
console.log(5);
} else if (
selectYear.value !== "all" &&
type == "all" &&
status !== "all"
) {
console.log(6);
} else if (
selectYear.value == "all" &&
type !== "all" &&
status !== "all"
) {
console.log(7);
rows.value = mainData.value.filter(
(e: any) => e.leaveTypeId === type && e.status === status
);
} else console.log("ค้นหาจากทั้งหมด");
setTimeout(function () {
loadTable.value = false;
}, 500);
}
/**
*
*/
function clearFilter() {
selectYear.value = "all";
selectType.value = "all";
selectStatus.value = "all";
filterTable.value = "";
}
/**
* Option Filter
* @param val
* @param update Function
* @param name Select
*/
function filterOption(val: string, update: any, name: string) {
update(() => {
const needle = val.toLowerCase();
if (name === "type") {
leaveOps.value = leaveOp.filter(
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
} else if (name === "status") {
statusOps.value = statusOp.filter(
(v: any) => v.name.toLowerCase().indexOf(needle) > -1
);
}
});
rows.value = mainData.value;
}
/**
@ -220,30 +103,12 @@ export const useLeavelistDataStore = defineStore("leave", () => {
}
return {
amounttab1,
amounttab2,
/**ข้อมูลใน Table */
rows,
fetchList,
loadTable,
columns,
visibleColumns,
/**ค้นหาข้อมูล */
filterTable,
selectYear,
selectType,
selectStatus,
optionYear,
optionType,
optionStatus,
clearFilter,
searchDataFn,
filterOption,
leaveOp,
statusOp,
leaveOps,
statusOps,
/** Function แปลงค่า */
convertLeave,
convertLeaveDaytype,