Refactoring code module 06_retirement

This commit is contained in:
STW_TTTY\stwtt 2024-09-18 15:18:57 +07:00
parent 1225254062
commit ea921b39b0
29 changed files with 730 additions and 823 deletions

View file

@ -3,31 +3,41 @@ import { onMounted, ref, useAttrs, reactive, watch } from "vue";
import type { QTableProps } from "quasar";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { storeToRefs } from "pinia";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useDataStoreRetirement } from "@/modules/06_retirement/storeRetirement";
import type { resMain } from "@/modules/06_retirement/interface/response/Main";
import { storeToRefs } from "pinia";
import popupAdd from "../components/ListRetirement/popupAdd.vue";
import { checkPermission } from "@/utils/permissions";
const useStoreRetire = useDataStoreRetirement();
const { clickTab } = useStoreRetire;
const { tab, type } = storeToRefs(useDataStoreRetirement());
const mixin = useCounterMixin();
const { messageError, date2Thai, showLoader, hideLoader, dialogConfirm } =
mixin;
const router = useRouter();
const $q = useQuasar(); // noti quasar
import type { resMain } from "@/modules/06_retirement/interface/response/Main";
const fiscalyear = ref<number>();
import popupAdd from "@/modules/06_retirement/components/ListRetirement/popupAdd.vue";
const $q = useQuasar(); // noti quasar
const router = useRouter();
const mixin = useCounterMixin();
const useStoreRetire = useDataStoreRetirement();
const { tab, type } = storeToRefs(useDataStoreRetirement());
const { clickTab } = useStoreRetire;
const { messageError, date2Thai, showLoader, hideLoader } = mixin;
const fiscalyear = ref<number>(); //
const yearOptionsFilter = ref<any>({
yearOptions: [],
});
const actionOption = ref<resMain[]>([]);
const attrs = ref<any>(useAttrs());
const paging = ref<boolean>(true);
const pagination = ref({
sortBy: "",
descending: false,
page: 1,
rowsPerPage: 10,
});
const visibleColumns = ref<string[]>([
"no",
"signDate",
@ -85,20 +95,10 @@ const currentYear = new Date().getFullYear();
const rows = ref<resMain[]>([]);
const yearOptions = ref<any>([{ id: "", year: "ทั้งหมด" }]);
onMounted(async () => {
await fetchRetirement(type.value, currentYear);
// fiscalyear.value = currentYear + 543
// await fetchRetirement(type.value, currentYear);
});
//
const filteryear = () => {
// yearOptions.value.push({ id: currentYear, name: currentYear + 543 });
// yearOptionsFilter.value = [{ id: currentYear, name: currentYear + 543 }];
// yearOptionsFilter.value.push({ id: currentYear, name: currentYear + 543 });
fetchRetirement(type.value, currentYear);
};
//
const fetchRetirement = async (type: string, year: any) => {
async function fetchRetirement(type: string, year: any) {
showLoader();
await http
.get(config.API.retirement(type, year))
@ -155,57 +155,58 @@ const fetchRetirement = async (type: string, year: any) => {
.finally(() => {
hideLoader();
});
};
}
const checkjson = ref<boolean>();
// document
const checkststus = (data: any) => {
function checkststus(data: any) {
let jsonfasle = data.find((e: any) => e.document == false);
if (jsonfasle) {
checkjson.value = true;
} else checkjson.value = false;
};
}
//
const filterKeyword = ref<string>("");
const filterRef = ref<any>(null);
const resetFilter = () => {
/** reset ฟิลเตอร์ */
function resetFilter() {
filterKeyword.value = "";
filterRef.value.focus();
};
const attrs = ref<any>(useAttrs());
}
const paging = ref<boolean>(true);
const pagination = ref({
sortBy: "",
descending: false,
page: 1,
rowsPerPage: 10,
});
const filterSelector = (val: any, update: Function) => {
/**
* งชนฟลเตอร input
* @param val input
* @param update Function quasar
*/
function filterSelector(val: any, update: Function) {
update(() => {
yearOptions.value = yearOptionsFilter.value.filter(
(v: any) => v.year.indexOf(val) > -1
);
});
};
}
const paginationLabel = (start: string, end: string, total: string) => {
if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
else return start + "-" + end + " ใน " + total;
};
const nextPage = (prop: any) => {
/**
* ไปหนาแกไขรายละเอยด
* @param prop อม
*/
function nextPage(prop: any) {
router.push(`/retirement/${prop.id}`);
};
const nextPageDetail = (prop: any) => {
router.push(`/retirement-detail/${prop.id}`);
};
}
watch(type, () => {
fetchRetirement(type.value, currentYear);
});
//
const typeReportChangeName = (val: string) => {
/**
* ไปหนารายละเอยด
* @param prop อม
*/
function nextPageDetail(prop: any) {
router.push(`/retirement-detail/${prop.id}`);
}
/** แปลง status เป็น text */
function typeReportChangeName(val: string) {
switch (val) {
case "EDIT":
return "ประกาศแก้ไขเกษียณ";
@ -216,7 +217,15 @@ const typeReportChangeName = (val: string) => {
default:
return "ประกาศข้อมูลเกษียณ";
}
};
}
watch(type, () => {
fetchRetirement(type.value, currentYear);
});
onMounted(async () => {
await fetchRetirement(type.value, currentYear);
});
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
@ -345,7 +354,6 @@ const typeReportChangeName = (val: string) => {
class="custom-header-table"
v-bind="attrs"
:visible-columns="visibleColumns"
:pagination-label="paginationLabel"
v-model:pagination="pagination"
>
<template v-slot:header="props">