feat: detect can edit request list
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 6s
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 6s
This commit is contained in:
parent
56a63185a1
commit
92b4db45d2
2 changed files with 55 additions and 21 deletions
|
|
@ -54,6 +54,7 @@ import { Invoice } from 'src/stores/payment/types';
|
||||||
import { CreatedBy } from 'src/stores/types';
|
import { CreatedBy } from 'src/stores/types';
|
||||||
import { getUserId } from 'src/services/keycloak';
|
import { getUserId } from 'src/services/keycloak';
|
||||||
import { QuotationFull } from 'src/stores/quotations/types';
|
import { QuotationFull } from 'src/stores/quotations/types';
|
||||||
|
import useUserStore from 'src/stores/user';
|
||||||
|
|
||||||
const { locale, t } = useI18n();
|
const { locale, t } = useI18n();
|
||||||
|
|
||||||
|
|
@ -62,7 +63,9 @@ const route = useRoute();
|
||||||
const optionStore = useOptionStore();
|
const optionStore = useOptionStore();
|
||||||
const requestListStore = useRequestList();
|
const requestListStore = useRequestList();
|
||||||
const flowTemplateStore = useWorkflowTemplate();
|
const flowTemplateStore = useWorkflowTemplate();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
const currentUserGroup = ref<string[]>([]);
|
||||||
const workList = ref<RequestWork[]>([]);
|
const workList = ref<RequestWork[]>([]);
|
||||||
const statusFile = ref<Attributes>({
|
const statusFile = ref<Attributes>({
|
||||||
customer: {},
|
customer: {},
|
||||||
|
|
@ -158,6 +161,10 @@ onMounted(async () => {
|
||||||
initTheme();
|
initTheme();
|
||||||
initLang();
|
initLang();
|
||||||
|
|
||||||
|
const result = await userStore.fetchUserGroup();
|
||||||
|
|
||||||
|
currentUserGroup.value = result.map((v) => v.name);
|
||||||
|
|
||||||
// get data
|
// get data
|
||||||
await getData();
|
await getData();
|
||||||
});
|
});
|
||||||
|
|
@ -283,26 +290,38 @@ async function triggerViewFile(opt: {
|
||||||
if (!opt.download) window.open(url, '_blank');
|
if (!opt.download) window.open(url, '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
const responsiblePersonList = computed(() => {
|
const responsibleList = computed(() => {
|
||||||
const temp = workList.value?.reduce<Record<string, CreatedBy[]>>(
|
const temp = workList.value?.reduce<
|
||||||
(acc, curr: RequestWork) => {
|
Record<string, { user: CreatedBy[]; group: string[] }>
|
||||||
curr.productService.service?.workflow?.step.forEach((v) => {
|
>((acc, curr: RequestWork) => {
|
||||||
const key = v.order.toString();
|
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) => {
|
v.responsiblePerson.forEach((lhs) => {
|
||||||
if (current.find((rhs) => rhs.id === lhs.userId)) return;
|
if (current.user.find((rhs) => rhs.id === lhs.userId)) return;
|
||||||
current.push(lhs.user);
|
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 || {};
|
return temp || {};
|
||||||
});
|
});
|
||||||
|
|
@ -496,11 +515,11 @@ function toEmployee(employee: RequestData['employee']) {
|
||||||
<span class="app-text-muted">{{ $t('flow.responsiblePerson') }}</span>
|
<span class="app-text-muted">{{ $t('flow.responsiblePerson') }}</span>
|
||||||
<span>
|
<span>
|
||||||
<template
|
<template
|
||||||
v-if="responsiblePersonList[pageState.currentStep]?.length"
|
v-if="responsibleList[pageState.currentStep]?.user.length"
|
||||||
>
|
>
|
||||||
<AvatarGroup
|
<AvatarGroup
|
||||||
:data="
|
:data="
|
||||||
(responsiblePersonList[pageState.currentStep] || []).map(
|
(responsibleList[pageState.currentStep].user || []).map(
|
||||||
(v) => ({
|
(v) => ({
|
||||||
name:
|
name:
|
||||||
$i18n.locale === 'eng'
|
$i18n.locale === 'eng'
|
||||||
|
|
@ -798,11 +817,15 @@ function toEmployee(employee: RequestData['employee']) {
|
||||||
:cancel="data.requestDataStatus === RequestDataStatus.Canceled"
|
:cancel="data.requestDataStatus === RequestDataStatus.Canceled"
|
||||||
:readonly="
|
:readonly="
|
||||||
data.requestDataStatus === RequestDataStatus.Canceled ||
|
data.requestDataStatus === RequestDataStatus.Canceled ||
|
||||||
(responsiblePersonList &&
|
(responsibleList &&
|
||||||
!!responsiblePersonList[pageState.currentStep]?.length &&
|
!responsibleList[pageState.currentStep]?.user.find(
|
||||||
!responsiblePersonList[pageState.currentStep]?.find(
|
|
||||||
(v) => v.id === getUserId(),
|
(v) => v.id === getUserId(),
|
||||||
))
|
) &&
|
||||||
|
!responsibleList[pageState.currentStep]?.group.some((v) =>
|
||||||
|
currentUserGroup.includes(v),
|
||||||
|
)) ||
|
||||||
|
(!!responsibleList[pageState.currentStep]?.user?.length &&
|
||||||
|
!!responsibleList[pageState.currentStep]?.user?.length)
|
||||||
"
|
"
|
||||||
:order-able="value._messengerExpansion"
|
:order-able="value._messengerExpansion"
|
||||||
:installment-info="getInstallmentInfo()"
|
:installment-info="getInstallmentInfo()"
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import axios from 'axios';
|
||||||
import useBranchStore from '../branch';
|
import useBranchStore from '../branch';
|
||||||
import { Branch } from '../branch/types';
|
import { Branch } from '../branch/types';
|
||||||
import { getSignature, setSignature } from './signature';
|
import { getSignature, setSignature } from './signature';
|
||||||
|
import { getUserId } from 'src/services/keycloak';
|
||||||
|
|
||||||
const branchStore = useBranchStore();
|
const branchStore = useBranchStore();
|
||||||
|
|
||||||
|
|
@ -38,6 +39,14 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
|
|
||||||
const data = ref<Pagination<User[]>>();
|
const data = ref<Pagination<User[]>>();
|
||||||
|
|
||||||
|
async function fetchUserGroup(id?: string) {
|
||||||
|
return await api
|
||||||
|
.get<
|
||||||
|
{ id: string; name: string; path: string }[]
|
||||||
|
>(`/user/${id || getUserId()}/group`)
|
||||||
|
.then((res) => res.data);
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchHqOption() {
|
async function fetchHqOption() {
|
||||||
if (userOption.value.hqOpts.length === 0) {
|
if (userOption.value.hqOpts.length === 0) {
|
||||||
const res = await branchStore.fetchList({
|
const res = await branchStore.fetchList({
|
||||||
|
|
@ -334,6 +343,8 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
setSignature,
|
setSignature,
|
||||||
|
|
||||||
typeStats,
|
typeStats,
|
||||||
|
|
||||||
|
fetchUserGroup,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue