diff --git a/src/interface/response/main.ts b/src/interface/response/main.ts index 561af060e..2267c36b3 100644 --- a/src/interface/response/main.ts +++ b/src/interface/response/main.ts @@ -43,4 +43,18 @@ interface DataRoles { parentNode: string; } -export type { ListMenu, ChildLevelTree, ChildConfig, DataPermissions,DataRoles }; +interface DataRoleWorkflow { + isDeputy: boolean; + isDirector: boolean; + isOfficer: boolean; + isStaff: boolean; +} + +export type { + ListMenu, + ChildLevelTree, + ChildConfig, + DataPermissions, + DataRoles, + DataRoleWorkflow, +}; diff --git a/src/modules/06_retirement/components/02_resign/DialogSendToCommand.vue b/src/modules/06_retirement/components/02_resign/DialogSendToCommand.vue index aabe6871e..8a284c7c8 100644 --- a/src/modules/06_retirement/components/02_resign/DialogSendToCommand.vue +++ b/src/modules/06_retirement/components/02_resign/DialogSendToCommand.vue @@ -4,6 +4,7 @@ import { useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; import { useRetirementDataStore } from "@/modules/06_retirement/store/Main"; +import { useRoleWorkflowDataStore } from "@/stores/roleWorkflow"; import type { PropType } from "vue"; import type { QTableProps } from "quasar"; @@ -15,6 +16,7 @@ import DialogCreateCommand from "@/modules/18_command/components/DialogCreateCom /** use */ const $q = useQuasar(); const stroe = useRetirementDataStore(); +const { fetchDataCheckIsoffice } = useRoleWorkflowDataStore(); const { statusText } = stroe; const selected = ref([]); const dataMapToSend = computed(() => { @@ -33,7 +35,7 @@ const dataMapToSend = computed(() => { })); }); const mixin = useCounterMixin(); -const { dialogConfirm, date2Thai, onSearchDataTable } = mixin; +const { dialogConfirm, date2Thai, onSearchDataTable, messageError } = mixin; /** props*/ const props = defineProps({ @@ -54,7 +56,7 @@ const columns = ref([ align: "left", label: "ลำดับ", sortable: false, - field: (row) => props?.rows!.indexOf(row) + 1, + field: (row) => rowsData.value!.indexOf(row) + 1, headerStyle: "font-size: 14px", style: "font-size: 14px", sort: (a: string, b: string) => @@ -190,13 +192,36 @@ async function onSearch() { ); } +const isOfficer = ref(false); +const isStaff = ref(false); + +/** ฟังก์ดึงข้อมูลผู้บังคับบัญชา*/ +async function fetchCheckOfficer() { + try { + const data = await fetchDataCheckIsoffice("SYS_RESIGN"); + isOfficer.value = data.isOfficer; + isStaff.value = data.isStaff; + } catch (err) { + messageError($q, err); + } +} + watch( () => props.modal, - (val) => { + async (val) => { if (val) { selected.value = []; - rowsData.value = props.rows ? props.rows : []; - rowsDataMain.value = props.rows ? props.rows : []; + await fetchCheckOfficer(); + const data = props?.rows?.filter((e: any) => { + if (isStaff.value) { + return e.group === "1.1"; + } else { + return e.group !== "1.1"; + } + }); + + rowsData.value = data ? data : []; + rowsDataMain.value = data ? data : []; } else { rowsData.value = []; rowsDataMain.value = []; diff --git a/src/modules/06_retirement/components/02_resign/ResignByid.vue b/src/modules/06_retirement/components/02_resign/ResignByid.vue index 72c4606ae..27e3b570a 100644 --- a/src/modules/06_retirement/components/02_resign/ResignByid.vue +++ b/src/modules/06_retirement/components/02_resign/ResignByid.vue @@ -8,6 +8,7 @@ import http from "@/plugins/http"; import config from "@/app.config"; import genReport from "@/plugins/genreport"; import { useCounterMixin } from "@/stores/mixin"; +import { useRoleWorkflowDataStore } from "@/stores/roleWorkflow"; import { checkPermission } from "@/utils/permissions"; import { useRetirementDataStore } from "@/modules/06_retirement/store/Main"; @@ -34,6 +35,7 @@ const route = useRoute(); const router = useRouter(); const store = useRetirementDataStore(); +const { fetchDataCheckIsoffice } = useRoleWorkflowDataStore(); const { convertStatusText } = store; const checkRoutePermisson = ref(route.name == "resignDetailbyid"); const mixin = useCounterMixin(); @@ -43,7 +45,6 @@ const { showLoader, hideLoader, success, - dialogConfirm, dialogRemove, } = mixin; @@ -54,6 +55,7 @@ const personId = ref(""); const roleUser = ref(""); const dataProfile = ref(); const approveStep = ref(""); +const group = ref(""); // const approveCheck = computed(() => { // return ( @@ -309,7 +311,10 @@ function diffDate() { return false; } -/** นำข้อมูลมาจาก API*/ +/** + * ฟังก์ชันดึงข้อมูลรายละเอียดการลาออก + * @param id id ของผู้ใช้งาน + */ async function fetchData(id: string) { showLoader(); await http @@ -346,6 +351,7 @@ async function fetchData(id: string) { isDiscipline.value = data.isDiscipline; statusCheck.value = data.status; approveStep.value = data.approveStep; + group.value = data.group; profileType.value = data.profileType; keycloakUserId.value = data.keycloakUserId; rowsApprover.value = { @@ -361,7 +367,11 @@ async function fetchData(id: string) { }); } -/**Pop up */ +/** + * ฟังก์ชันเปิด pop up อนุญาตหรือยับยั้ง + * @param action action อนุญาตหรือยับยั้ง + * @param type ประเภทผู้ใช้งาน + */ function popUp(action: "pass" | "passNot", type: string) { reasonReign.value = ""; dateBreak.value = null; @@ -370,7 +380,10 @@ function popUp(action: "pass" | "passNot", type: string) { openModal(); } -//เงื่อนไขpop up +/** + * ฟังก์ชันยืนยันการอนุญาตหรือยับยั้ง + * @param type ประเภทผู้บัริหาร + */ function onSubmit(type: string) { if (roleUser.value === "commander" && actionPass.value) { confirmpopUp("/comander"); @@ -396,7 +409,10 @@ function onSubmit(type: string) { // } } -//pop up ยืนยันการอนุญาต +/** + * ฟังก์ชันยืนยันการอนุญาต + * @param path path สำหรับการอนุญาต + */ async function confirmpopUp(path: string) { dialogConfirm( $q, @@ -427,7 +443,10 @@ async function confirmpopUp(path: string) { ); } -//pop up การยับยั้งสำเร็จ +/** + * ฟังก์ชันยืนยันการยับยั้ง + * @param path path สำหรับการยับยั้ง + */ async function rejectpopUp(path: string) { dialogConfirm( $q, @@ -459,9 +478,7 @@ async function rejectpopUp(path: string) { ); } -/** - * กดยกเลิก - */ +/** ฟังก์ชันยกเลิกการแก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย*/ async function clickCancel() { edit.value = false; const data = dataDetail.value; @@ -483,15 +500,14 @@ async function clickCancel() { } myForm.value?.resetValidation(); } -/** - * กดยกเลิก - */ + +/** ฟังก์ชันยกเลิกการแก้ไขข้อมูลรายการตรวจสอบเงื่อนไขต่างๆ*/ async function clickCancelConditions() { await fetchData(id.value); conditions.value = false; } -/** Function บันทึก รายการตรวจสอบเงื่อนไขต่างๆ*/ +/** ฟังก์ชันบันทึกเงื่อนไขต่างๆ*/ function onSubmitConditions() { dialogConfirm($q, () => { showLoader(); @@ -515,7 +531,7 @@ function onSubmitConditions() { }); } -/** Function บันทึก ,แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย*/ +/** ฟังก์ชันบันทึกข้อมูลเพื่อลงบัญชีแนบท้าย*/ function onSubmitAttached() { dialogConfirm($q, () => { const formData = new FormData(); @@ -550,7 +566,7 @@ function onSubmitAttached() { } /** - * Function เพิ่ม Class เวลา Edit + * ฟังก์ชันเปลี่ยน Class * @param val เมื่อเป็นEdit จะเปลี่ยน Class */ function getClass(val: boolean) { @@ -560,16 +576,6 @@ function getClass(val: boolean) { }; } -/** แปลง StatusOrder */ -function statusOrder(val: boolean) { - switch (val) { - case true: - return "ยับยั้ง"; - case false: - return "อนุญาต"; - } -} - // ดาว์นโหลดไฟล์ async function fileDownload(type: string, fileName: string) { showLoader(); @@ -673,7 +679,7 @@ async function downloadFiles(fileName: string) { } /** - * ลบไฟล์ + * ฟังก์ชันลบไฟล์ * @param id id file */ function removeFile(fileName: string) { @@ -719,47 +725,51 @@ function convertStatus(val: string) { } else return val; } -/** เปิด POP UP */ +/** + * ฟังก์ชันเปิด modal เพิ่มผู้บังคับบัญชา + * @param type บังคับบัญชา,ผู้มีอำนาจ + */ function onAddPerson(type: string) { modalAdd.value = true; typeAdd.value = type; } +/** ฟังก์ดึงข้อมูลผู้บังคับบัญชา*/ async function checkOfficer() { - http - .get(config.API.checkIsofficer + `SYS_RESIGN`) - .then(async (res) => { - isOfficer.value = await res.data.result.isOfficer; - isStaff.value = await res.data.result.isStaff; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); + try { + const data = await fetchDataCheckIsoffice("SYS_RESIGN"); + isOfficer.value = data.isOfficer; + isStaff.value = data.isStaff; + } catch (err) { + messageError($q, err); + } } +/** ฟังก์ชันส่งไปพิจารณา*/ function onSend() { dialogConfirm( $q, - () => { + async () => { showLoader(); - http + await http .get(config.API.sendApproveRetirement("", id.value)) - .then(async (res) => { - await fetchFile(); - await fetchData(id.value); + .then(async () => { + await Promise.all([fetchFile(), fetchData(id.value)]); success($q, "ส่งไปพิจารณา"); }) .catch((e) => { messageError($q, e); }) - .finally(() => {}); + .finally(() => { + hideLoader(); + }); }, "ยืนยันการส่งไปพิจารณา", "ต้องการส่งไปพิจารณาใช่หรือไม่" ); } +/** ฟังก์ชันดึงข้อมูลตำแหน่งจาก Keycloak*/ async function fetchKeycloakPosition() { if (myProfileId.value == "") { await http @@ -774,13 +784,13 @@ async function fetchKeycloakPosition() { } } -/** Hook */ +/** hook ฟังก์ชันเมื่อโหลดคอมโพเนนต์*/ onMounted(async () => { showLoader(); await Promise.all([ - await fetchData(id.value), - await fetchKeycloakPosition(), - await checkOfficer(), + fetchData(id.value), + fetchKeycloakPosition(), + checkOfficer(), fetchFile(), ]).finally(() => { hideLoader(); @@ -1025,11 +1035,11 @@ onMounted(async () => { เงื่อนไขต่างๆ - -
@@ -1107,7 +1117,9 @@ onMounted(async () => { { { ผลการพิจารณาของผู้บังคับบัญชา
+ {
{ @click="popUp('pass', 'commander')" /> {
ผลการพิจารณาของผู้มีอำนาจ
+ {
{ คลิกเพื่อส่งไปพิจารณา + {
(route.name == "resignDetailReject"); const mixin = useCounterMixin(); @@ -406,16 +408,13 @@ function onAddPerson(type: string) { } async function checkOfficer() { - http - .get(config.API.checkIsofficer + `SYS_RESIGN`) - .then(async (res) => { - isOfficer.value = await res.data.result.isOfficer; - isStaff.value = await res.data.result.isStaff; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); + try { + const data = await fetchDataCheckIsoffice("SYS_RESIGN"); + isOfficer.value = data.isOfficer; + isStaff.value = data.isStaff; + } catch (err) { + messageError($q, err); + } } function onSend() { @@ -456,7 +455,7 @@ async function fetchKeycloakPosition() { /** Hook */ onMounted(async () => { await fetchData(id.value); - await fetchKeycloakPosition() + await fetchKeycloakPosition(); await checkOfficer(); }); diff --git a/src/modules/06_retirement/components/03_resignEmp/ResignByid.vue b/src/modules/06_retirement/components/03_resignEmp/ResignByid.vue index 50ffe5dce..1fa3d33de 100644 --- a/src/modules/06_retirement/components/03_resignEmp/ResignByid.vue +++ b/src/modules/06_retirement/components/03_resignEmp/ResignByid.vue @@ -10,6 +10,7 @@ import genReport from "@/plugins/genreport"; import { useCounterMixin } from "@/stores/mixin"; import { checkPermission } from "@/utils/permissions"; import { useRetirementDataStore } from "@/modules/06_retirement/store/Main"; +import { useRoleWorkflowDataStore } from "@/stores/roleWorkflow"; import type { TypeFile, @@ -35,6 +36,7 @@ const $q = useQuasar(); const route = useRoute(); const router = useRouter(); const store = useRetirementDataStore(); +const { fetchDataCheckIsoffice } = useRoleWorkflowDataStore(); const { convertStatusText } = store; const checkRoutePermisson = ref(route.name == "resignDetailbyidEMP"); const mixin = useCounterMixin(); @@ -384,7 +386,14 @@ async function confirmpopUp() { reason: reasonReign.value, }; await http - .put(config.API.commanderApproveRetirement("-employee", id.value,'approve'), body) + .put( + config.API.commanderApproveRetirement( + "-employee", + id.value, + "approve" + ), + body + ) .then(async () => { await fetchData(id.value); closeModal(); @@ -413,7 +422,14 @@ async function rejectpopUp() { date: dateBreak.value, }; await http - .put(config.API.commanderApproveRetirement('-employee', id.value,'reject'), body) + .put( + config.API.commanderApproveRetirement( + "-employee", + id.value, + "reject" + ), + body + ) .then(async () => { await fetchData(id.value); closeModal(); @@ -698,16 +714,13 @@ function onAddPerson(type: string) { } async function checkOfficer() { - http - .get(config.API.checkIsofficer + `SYS_RESIGN_EMP`) - .then(async (res) => { - isOfficer.value = await res.data.result.isOfficer; - isStaff.value = await res.data.result.isStaff; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); + try { + const data = await fetchDataCheckIsoffice("SYS_RESIGN_EMP"); + isOfficer.value = data.isOfficer; + isStaff.value = data.isStaff; + } catch (err) { + messageError($q, err); + } } function onSend() { diff --git a/src/modules/06_retirement/components/03_resignEmp/ResignReject.vue b/src/modules/06_retirement/components/03_resignEmp/ResignReject.vue index b0c611071..f2b34249b 100644 --- a/src/modules/06_retirement/components/03_resignEmp/ResignReject.vue +++ b/src/modules/06_retirement/components/03_resignEmp/ResignReject.vue @@ -1,22 +1,17 @@ diff --git a/src/modules/06_retirement/components/DialogAddCommander.vue b/src/modules/06_retirement/components/DialogAddCommander.vue index 80455b16c..be8d76ce5 100644 --- a/src/modules/06_retirement/components/DialogAddCommander.vue +++ b/src/modules/06_retirement/components/DialogAddCommander.vue @@ -134,7 +134,7 @@ async function getData() { function onSubmit() { if (selected.value.length !== 0) { - dialogConfirm($q, () => { + dialogConfirm($q, async () => { if (props.keycloakUserId) { const body = selected.value.map((items: any, index: any) => ({ seq: index, @@ -146,7 +146,7 @@ function onSubmit() { keycloakId: items.keycloakId, })); showLoader(); - http + await http .post( config.API.addResign( (props.profileType?.toLocaleLowerCase() as string) == "officer" @@ -157,10 +157,10 @@ function onSubmit() { ), body ) - .then((res) => { + .then(async () => { + await props.getData?.(pageId.value); closeDialog(); success($q, "บันทึกสำเร็จ"); - props.getData?.(pageId.value); }) .catch((e) => { messageError($q, e); @@ -179,6 +179,7 @@ function closeDialog() { modal.value = false; rows.value = []; selected.value = []; + keyword.value = ""; } watch( diff --git a/src/modules/07_insignia/views/02_ManageMain.vue b/src/modules/07_insignia/views/02_ManageMain.vue index 0de4d28d8..1f5059f9a 100644 --- a/src/modules/07_insignia/views/02_ManageMain.vue +++ b/src/modules/07_insignia/views/02_ManageMain.vue @@ -5,6 +5,7 @@ import { useQuasar } from "quasar"; import { useRoute } from "vue-router"; import { useCounterMixin } from "@/stores/mixin"; import { useInsigniaDataStore } from "@/modules/07_insignia/store"; +import { useRoleWorkflowDataStore } from "@/stores/roleWorkflow"; import { checkPermission } from "@/utils/permissions"; import http from "@/plugins/http"; import config from "@/app.config"; @@ -33,6 +34,7 @@ const tab1 = defineAsyncComponent( const $q = useQuasar(); //ใช้ noti quasar const route = useRoute(); const DataStore = useInsigniaDataStore(); +const { fetchDataCheckIsoffice } = useRoleWorkflowDataStore(); const mixin = useCounterMixin(); const { messageError, dialogConfirm, showLoader, hideLoader, success } = mixin; @@ -184,18 +186,15 @@ async function fecthInsignia() { } async function fetchCheckIsofficer() { - http - .get(config.API.checkIsofficer + `SYS_INSIGNIA_MANAGE`) - .then((res) => { - const data = res.data.result; - DataStore.isStaff = data.isStaff; - DataStore.isOfficer = data.isOfficer; - DataStore.isDirector = data.isDirector; - DataStore.isDeputy = data.isDeputy; - }) - .catch((err) => { - messageError($q, err); - }); + try { + const data = await fetchDataCheckIsoffice("SYS_INSIGNIA_MANAGE"); + DataStore.isStaff = data.isStaff; + DataStore.isOfficer = data.isOfficer; + DataStore.isDirector = data.isDirector; + DataStore.isDeputy = data.isDeputy; + } catch (err) { + messageError($q, err); + } } /** diff --git a/src/modules/09_leave/components/05_Leave/DetailLeavePage.vue b/src/modules/09_leave/components/05_Leave/DetailLeavePage.vue index 6a8e35594..5357fba06 100644 --- a/src/modules/09_leave/components/05_Leave/DetailLeavePage.vue +++ b/src/modules/09_leave/components/05_Leave/DetailLeavePage.vue @@ -9,6 +9,7 @@ import genReport from "@/plugins/genreport"; import { useCounterMixin } from "@/stores/mixin"; import { useLeavelistDataStore } from "@/modules/09_leave/stores/LeaveStore"; import { checkPermission } from "@/utils/permissions"; +import { useRoleWorkflowDataStore } from "@/stores/roleWorkflow"; /** importType */ import type { FremData } from "@/modules/09_leave/interface/request/leave"; @@ -38,6 +39,7 @@ import DialogAddCommander from "@/modules/09_leave/components/05_Leave/Dialog/Di /** use */ const $q = useQuasar(); const mixin = useCounterMixin(); +const { fetchDataCheckIsoffice } = useRoleWorkflowDataStore(); const { dialogConfirm, showLoader, @@ -426,10 +428,7 @@ function checkLeaveType(leaveTypeId: string, formData: FremData) { checkForm.value = "FormHajj"; } else if (type === "LV-007") { checkForm.value = "FormCheckSelect"; - } else if ( - type === "LV-008" && - formData.leaveSubTypeName === "ศึกษาต่อ" - ) { + } else if (type === "LV-008" && formData.leaveSubTypeName === "ศึกษาต่อ") { checkForm.value = "FormStudy"; } else if ( (type === "LV-008" && formData.leaveSubTypeName === "ฝึกอบรม") || @@ -615,23 +614,19 @@ function onSend() { } async function checkOfficer() { - http - .get( - config.API.checkIsofficer + - `${ - formData.profileType == "OFFICER" - ? "SYS_LEAVE_LIST" - : "SYS_LEAVE_LIST_EMP" - }` - ) - .then(async (res) => { - isOfficer.value = await res.data.result.isOfficer; - isStaff.value = await res.data.result.isStaff; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); + try { + const data = await fetchDataCheckIsoffice( + `${ + formData.profileType == "OFFICER" + ? "SYS_LEAVE_LIST" + : "SYS_LEAVE_LIST_EMP" + }` + ); + isOfficer.value = data.isOfficer; + isStaff.value = data.isStaff; + } catch (err) { + messageError($q, err); + } } async function fetchKeycloakPosition() { diff --git a/src/modules/09_leave/components/05_Leave/DetailLeaveReject.vue b/src/modules/09_leave/components/05_Leave/DetailLeaveReject.vue index 163d8b63c..4a80d5455 100644 --- a/src/modules/09_leave/components/05_Leave/DetailLeaveReject.vue +++ b/src/modules/09_leave/components/05_Leave/DetailLeaveReject.vue @@ -9,6 +9,7 @@ import genReport from "@/plugins/genreport"; import { useCounterMixin } from "@/stores/mixin"; import { useLeavelistDataStore } from "@/modules/09_leave/stores/LeaveStore"; import { checkPermission } from "@/utils/permissions"; +import { useRoleWorkflowDataStore } from "@/stores/roleWorkflow"; /** importType */ import type { @@ -35,6 +36,7 @@ import FormVocationalRehabilitation from "@/modules/09_leave/components/05_Leave /** use */ const $q = useQuasar(); +const { fetchDataCheckIsoffice } = useRoleWorkflowDataStore(); const mixin = useCounterMixin(); const { dialogConfirm, @@ -450,23 +452,19 @@ async function onClickDownloadFile(id: string, fileName: string, type: string) { } async function checkOfficer() { - http - .get( - config.API.checkIsofficer + - `${ - formData.profileType == "OFFICER" - ? "SYS_LEAVE_LIST" - : "SYS_LEAVE_LIST_EMP" - }` - ) - .then(async (res) => { - isOfficer.value = await res.data.result.isOfficer; - isStaff.value = await res.data.result.isStaff; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); + try { + const data = await fetchDataCheckIsoffice( + `${ + formData.profileType == "OFFICER" + ? "SYS_LEAVE_LIST" + : "SYS_LEAVE_LIST_EMP" + }` + ); + isOfficer.value = data.isOfficer; + isStaff.value = data.isStaff; + } catch (err) { + messageError($q, err); + } } async function fetchKeycloakPosition() { diff --git a/src/stores/roleWorkflow.ts b/src/stores/roleWorkflow.ts new file mode 100644 index 000000000..ea0d81b53 --- /dev/null +++ b/src/stores/roleWorkflow.ts @@ -0,0 +1,25 @@ +import { defineStore } from "pinia"; +import { ref } from "vue"; +import http from "@/plugins/http"; +import config from "@/app.config"; + +import type { DataRoleWorkflow } from "@/interface/response/main"; + +export const useRoleWorkflowDataStore = defineStore("rolewrokflow", () => { + const dataRole = ref<{ [key: string]: DataRoleWorkflow[] }>({}); + + async function fetchDataCheckIsoffice(sysKey: string) { + if (dataRole.value[sysKey]) { + return dataRole.value[sysKey] || []; + } else { + try { + const res = await http.get(config.API.checkIsofficer + `${sysKey}`); + dataRole.value[sysKey] = res.data.result; + return res.data.result; + } catch (err) { + throw err; + } + } + } + return { fetchDataCheckIsoffice }; +});