From 92b4db45d2e8006ca9ebbde72fd98470780fecfe Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:32:10 +0700 Subject: [PATCH] feat: detect can edit request list --- src/pages/08_request-list/RequestListView.vue | 65 +++++++++++++------ src/stores/user/index.ts | 11 ++++ 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/pages/08_request-list/RequestListView.vue b/src/pages/08_request-list/RequestListView.vue index 9327f419..4675b124 100644 --- a/src/pages/08_request-list/RequestListView.vue +++ b/src/pages/08_request-list/RequestListView.vue @@ -54,6 +54,7 @@ import { Invoice } from 'src/stores/payment/types'; import { CreatedBy } from 'src/stores/types'; import { getUserId } from 'src/services/keycloak'; import { QuotationFull } from 'src/stores/quotations/types'; +import useUserStore from 'src/stores/user'; const { locale, t } = useI18n(); @@ -62,7 +63,9 @@ const route = useRoute(); const optionStore = useOptionStore(); const requestListStore = useRequestList(); const flowTemplateStore = useWorkflowTemplate(); +const userStore = useUserStore(); +const currentUserGroup = ref([]); const workList = ref([]); const statusFile = ref({ customer: {}, @@ -158,6 +161,10 @@ onMounted(async () => { initTheme(); initLang(); + const result = await userStore.fetchUserGroup(); + + currentUserGroup.value = result.map((v) => v.name); + // get data await getData(); }); @@ -283,26 +290,38 @@ async function triggerViewFile(opt: { if (!opt.download) window.open(url, '_blank'); } -const responsiblePersonList = computed(() => { - const temp = workList.value?.reduce>( - (acc, curr: RequestWork) => { - curr.productService.service?.workflow?.step.forEach((v) => { - const key = v.order.toString(); +const responsibleList = computed(() => { + const temp = workList.value?.reduce< + Record + >((acc, curr: RequestWork) => { + curr.productService.service?.workflow?.step.forEach((v) => { + const key = v.order.toString(); + const responsibleGroup = ( + v.responsibleGroup as unknown as { group: string }[] + ).map((v) => v.group); - if (!acc[key]) acc[key] = v.responsiblePerson.map((v) => v.user); + if (!acc[key]) { + acc[key] = { + user: v.responsiblePerson.map((v) => v.user), + group: responsibleGroup, + }; + } - const current = acc[key]; + const current = acc[key]; - v.responsiblePerson.forEach((lhs) => { - if (current.find((rhs) => rhs.id === lhs.userId)) return; - current.push(lhs.user); - }); + v.responsiblePerson.forEach((lhs) => { + if (current.user.find((rhs) => rhs.id === lhs.userId)) return; + current.user.push(lhs.user); }); - return acc; - }, - {}, - ); + responsibleGroup.forEach((lhs) => { + if (current.group.find((rhs) => rhs === lhs)) return; + current.group.push(lhs); + }); + }); + + return acc; + }, {}); return temp || {}; }); @@ -496,11 +515,11 @@ function toEmployee(employee: RequestData['employee']) { {{ $t('flow.responsiblePerson') }}