refactor(leave): validate isAct commander
This commit is contained in:
parent
852f3226c1
commit
8dc473eec0
3 changed files with 38 additions and 8 deletions
|
|
@ -150,21 +150,41 @@ const rows = ref<RowsType>();
|
|||
// เช็คสิทธิ์การอนุมัติ
|
||||
const idCheck = computed(() => {
|
||||
if (typeAdd.value == "COMMANDER") {
|
||||
return rows.value?.commanders.map((items: SeqTypeRow) => items.profileId);
|
||||
return rows.value?.commanders.map((items: SeqTypeRow) => items.keyId);
|
||||
} else if (typeAdd.value == "APPROVER") {
|
||||
return rows.value?.approvers.map((items: SeqTypeRow) => items.profileId);
|
||||
return rows.value?.approvers.map((items: SeqTypeRow) => items.keyId);
|
||||
}
|
||||
});
|
||||
|
||||
// เช็คสิทธิ์การเลือกผู้มีอำนาจ
|
||||
const commanderList = computed(() => {
|
||||
if (typeAdd.value == "COMMANDER") {
|
||||
return rows.value?.approvers.map((items: SeqTypeRow) => items.profileId);
|
||||
} else if (typeAdd.value == "APPROVER") {
|
||||
return rows.value?.commanders.map((items: SeqTypeRow) => items.profileId);
|
||||
if (typeAdd.value === "COMMANDER") {
|
||||
return rows.value?.approvers.map((items: SeqTypeRow) => ({
|
||||
profileId: items.profileId,
|
||||
isAct: items.isAct,
|
||||
}));
|
||||
} else if (typeAdd.value === "APPROVER") {
|
||||
return rows.value?.commanders.map((items: SeqTypeRow) => ({
|
||||
profileId: items.profileId,
|
||||
isAct: items.isAct,
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
//
|
||||
const isAct = computed(() => {
|
||||
if (typeAdd.value === "COMMANDER") {
|
||||
return rows.value?.commanders && rows.value.commanders.length > 0
|
||||
? rows.value.commanders[0].isAct
|
||||
: false;
|
||||
} else if (typeAdd.value === "APPROVER") {
|
||||
return rows.value?.approvers && rows.value.approvers.length > 0
|
||||
? rows.value.approvers[0].isAct
|
||||
: false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// เช็คว่าผู้ใช้มีสิทธิ์อนุมัติหรือไม่
|
||||
const approveCheck = computed(() => {
|
||||
const commanders = rows.value?.commanders;
|
||||
|
|
@ -1272,5 +1292,6 @@ onMounted(async () => {
|
|||
:id-check="idCheck"
|
||||
:keycloak-user-id="keycloakUserId"
|
||||
:commanders-list="commanderList"
|
||||
:commanders-is-act="isAct"
|
||||
/>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ const props = defineProps({
|
|||
fetchDetailLeave: Function,
|
||||
idCheck: Array,
|
||||
commandersList: Array,
|
||||
commandersIsAct: Boolean,
|
||||
});
|
||||
|
||||
const pageId = ref<string>(route.params.id as string);
|
||||
|
|
@ -117,7 +118,7 @@ async function getData() {
|
|||
total.value = data.total;
|
||||
rows.value = data.data;
|
||||
selected.value = data.data.filter((items: any) => {
|
||||
return props.idCheck?.some((i: any) => i === items.id);
|
||||
return props.idCheck?.some((i: any) => i === items.key);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
|
|
@ -153,10 +154,14 @@ function onSubmit() {
|
|||
]
|
||||
.filter(Boolean)
|
||||
.join(" "),
|
||||
isAct: isAct.value,
|
||||
keyId: items.key,
|
||||
}));
|
||||
|
||||
const hasCommander = selected.value.some((e) =>
|
||||
props.commandersList?.some((i: any) => i === e.id)
|
||||
props.commandersList?.some(
|
||||
(i: any) => i.profileId === e.id && i.isAct === isAct.value
|
||||
)
|
||||
);
|
||||
|
||||
if (hasCommander) {
|
||||
|
|
@ -205,6 +210,7 @@ watch(
|
|||
() => modal.value,
|
||||
() => {
|
||||
if (modal.value) {
|
||||
isAct.value = props.commandersIsAct ?? false;
|
||||
getSearch();
|
||||
}
|
||||
}
|
||||
|
|
@ -233,6 +239,7 @@ watch(
|
|||
label="ค้นหา"
|
||||
v-model="keyword"
|
||||
style="width: 300px"
|
||||
@keydown.enter.prevent="onSearchData()"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon name="search"></q-icon>
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ interface SeqTypeRow {
|
|||
keycloakId: string;
|
||||
approveStatus: string;
|
||||
comment: string;
|
||||
keyId?: string;
|
||||
isAct?: boolean;
|
||||
}
|
||||
interface DataDateMonthObject {
|
||||
month: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue