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(() => {
|
const idCheck = computed(() => {
|
||||||
if (typeAdd.value == "COMMANDER") {
|
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") {
|
} 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(() => {
|
const commanderList = computed(() => {
|
||||||
if (typeAdd.value == "COMMANDER") {
|
if (typeAdd.value === "COMMANDER") {
|
||||||
return rows.value?.approvers.map((items: SeqTypeRow) => items.profileId);
|
return rows.value?.approvers.map((items: SeqTypeRow) => ({
|
||||||
} else if (typeAdd.value == "APPROVER") {
|
profileId: items.profileId,
|
||||||
return rows.value?.commanders.map((items: SeqTypeRow) => 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 approveCheck = computed(() => {
|
||||||
const commanders = rows.value?.commanders;
|
const commanders = rows.value?.commanders;
|
||||||
|
|
@ -1272,5 +1292,6 @@ onMounted(async () => {
|
||||||
:id-check="idCheck"
|
:id-check="idCheck"
|
||||||
:keycloak-user-id="keycloakUserId"
|
:keycloak-user-id="keycloakUserId"
|
||||||
:commanders-list="commanderList"
|
:commanders-list="commanderList"
|
||||||
|
:commanders-is-act="isAct"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ const props = defineProps({
|
||||||
fetchDetailLeave: Function,
|
fetchDetailLeave: Function,
|
||||||
idCheck: Array,
|
idCheck: Array,
|
||||||
commandersList: Array,
|
commandersList: Array,
|
||||||
|
commandersIsAct: Boolean,
|
||||||
});
|
});
|
||||||
|
|
||||||
const pageId = ref<string>(route.params.id as string);
|
const pageId = ref<string>(route.params.id as string);
|
||||||
|
|
@ -117,7 +118,7 @@ async function getData() {
|
||||||
total.value = data.total;
|
total.value = data.total;
|
||||||
rows.value = data.data;
|
rows.value = data.data;
|
||||||
selected.value = data.data.filter((items: any) => {
|
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) => {
|
.catch((err) => {
|
||||||
|
|
@ -153,10 +154,14 @@ function onSubmit() {
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(" "),
|
.join(" "),
|
||||||
|
isAct: isAct.value,
|
||||||
|
keyId: items.key,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const hasCommander = selected.value.some((e) =>
|
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) {
|
if (hasCommander) {
|
||||||
|
|
@ -205,6 +210,7 @@ watch(
|
||||||
() => modal.value,
|
() => modal.value,
|
||||||
() => {
|
() => {
|
||||||
if (modal.value) {
|
if (modal.value) {
|
||||||
|
isAct.value = props.commandersIsAct ?? false;
|
||||||
getSearch();
|
getSearch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -233,6 +239,7 @@ watch(
|
||||||
label="ค้นหา"
|
label="ค้นหา"
|
||||||
v-model="keyword"
|
v-model="keyword"
|
||||||
style="width: 300px"
|
style="width: 300px"
|
||||||
|
@keydown.enter.prevent="onSearchData()"
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
<q-icon name="search"></q-icon>
|
<q-icon name="search"></q-icon>
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ interface SeqTypeRow {
|
||||||
keycloakId: string;
|
keycloakId: string;
|
||||||
approveStatus: string;
|
approveStatus: string;
|
||||||
comment: string;
|
comment: string;
|
||||||
|
keyId?: string;
|
||||||
|
isAct?: boolean;
|
||||||
}
|
}
|
||||||
interface DataDateMonthObject {
|
interface DataDateMonthObject {
|
||||||
month: number;
|
month: number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue