ผูก API รายลงเวลาปฏิบัติงานของ Admin (รายการลงเวลา)
This commit is contained in:
parent
c76af202de
commit
e693e024e6
9 changed files with 557 additions and 295 deletions
|
|
@ -1,95 +1,36 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
/** import Type */
|
||||
import type { QTableProps } from "quasar";
|
||||
import type { DataOption } from "@/modules/09_leave/interface/index/Main";
|
||||
import type {
|
||||
TableRows,
|
||||
DataRes,
|
||||
} from "@/modules/09_leave/interface/response/work";
|
||||
const mixin = useCounterMixin();
|
||||
const { date2Thai } = mixin;
|
||||
|
||||
export const useWorklistDataStore = defineStore("work", () => {
|
||||
// ข้อมูลในตาราง
|
||||
const rows = ref<TableRows[]>([]);
|
||||
/** ข้อมูล Table */
|
||||
const columns = ref<QTableProps["columns"]>([]);
|
||||
const visibleColumns = ref<string[]>([]);
|
||||
const dataMain = ref<TableRows[]>([]);
|
||||
function fetchList(data: DataRes[]) {
|
||||
let datalist: TableRows[] = data.map((e: DataRes) => ({
|
||||
fullName: e.fullName,
|
||||
timeIn: e.timeIn,
|
||||
coordinatesIn: e.coordinatesIn,
|
||||
latIn: e.latIn,
|
||||
longIn: e.longIn,
|
||||
timeOut: e.timeOut,
|
||||
coordinatesOut: e.coordinatesOut,
|
||||
latOut: e.latOut,
|
||||
longOut: e.longOut,
|
||||
status: convertSatatus(e.status),
|
||||
date: date2Thai(e.date),
|
||||
}));
|
||||
dataMain.value = datalist;
|
||||
fetchOption();
|
||||
searchDataFn(selectDate.value, selectStatus.value);
|
||||
}
|
||||
|
||||
//ค้นหาข้อมูล
|
||||
const filterTable = ref<string>("");
|
||||
/** ค้นหาวัน ข้อมูล Table */
|
||||
const selectDate = ref<Date | null>(new Date());
|
||||
const selectStatus = ref<String>("all");
|
||||
const optionStatusMain = ref<DataOption[]>([]);
|
||||
const optionStatus = ref<DataOption[]>([]);
|
||||
function searchDataFn(searchDate: any, searchStatus: any) {
|
||||
searchStatus = searchStatus || "all";
|
||||
if (searchDate == null && searchStatus == "all") {
|
||||
rows.value = dataMain.value;
|
||||
} else if (searchDate == null && searchStatus !== "all") {
|
||||
rows.value = dataMain.value.filter((e: any) => e.status === searchStatus);
|
||||
} else if (searchDate !== null && searchStatus == "all") {
|
||||
rows.value = dataMain.value.filter(
|
||||
(e: any) => e.date === date2Thai(searchDate)
|
||||
);
|
||||
} else {
|
||||
rows.value = dataMain.value.filter(
|
||||
(e: any) =>
|
||||
e.date === date2Thai(searchDate) && e.status === searchStatus
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
function fetchOption() {
|
||||
const double_status = [
|
||||
...new Set(dataMain.value.map((item: any) => item.status)),
|
||||
];
|
||||
optionStatusMain.value = [{ id: "all", name: "ทั้งหมด" }];
|
||||
for (let i = 1; i <= double_status.length; i++) {
|
||||
const status = double_status[i - 1];
|
||||
if (typeof status === "string") {
|
||||
const listtype: DataOption = {
|
||||
id: status,
|
||||
name: status,
|
||||
};
|
||||
optionStatusMain.value.push(listtype);
|
||||
optionStatus.value = optionStatusMain.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
function filterFn(val: string, update: Function) {
|
||||
if (val == "") {
|
||||
update(() => {
|
||||
optionStatus.value = optionStatusMain.value;
|
||||
});
|
||||
} else {
|
||||
update(() => {
|
||||
optionStatus.value = optionStatusMain.value.filter(
|
||||
(e: any) => e.name.search(val) !== -1
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// function filterFn(val: string, update: Function) {
|
||||
// if (val == "") {
|
||||
// update(() => {
|
||||
// optionStatus.value = optionStatusMain.value;
|
||||
// });
|
||||
// } else {
|
||||
// update(() => {
|
||||
// optionStatus.value = optionStatusMain.value.filter(
|
||||
// (e: any) => e.name.search(val) !== -1
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// convertSatatus
|
||||
/**
|
||||
* function แปลงค่าสถานะ
|
||||
* @param val ค่าสถานนะ
|
||||
*/
|
||||
function convertSatatus(val: string) {
|
||||
switch (val) {
|
||||
case "normal":
|
||||
|
|
@ -102,17 +43,16 @@ export const useWorklistDataStore = defineStore("work", () => {
|
|||
}
|
||||
return {
|
||||
//ข้อมูลในตาราง
|
||||
rows,
|
||||
|
||||
columns,
|
||||
visibleColumns,
|
||||
fetchList,
|
||||
// fetchListLog,
|
||||
// fetchListTime,
|
||||
//ค้นหาข้อมูล
|
||||
filterTable,
|
||||
|
||||
selectDate,
|
||||
selectStatus,
|
||||
optionStatus,
|
||||
searchDataFn,
|
||||
filterFn,
|
||||
|
||||
// filterFn,
|
||||
convertSatatus,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue