salix-front/src/pages/Worker/Card/WorkerDescriptor.vue

194 lines
6.4 KiB
Vue

<script setup>
import { computed, ref } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import CardDescriptor from 'src/components/ui/CardDescriptor.vue';
import VnLv from 'src/components/ui/VnLv.vue';
import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue';
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
import axios from 'axios';
import VnImg from 'src/components/ui/VnImg.vue';
import EditPictureForm from 'components/EditPictureForm.vue';
import WorkerDescriptorMenu from './WorkerDescriptorMenu.vue';
import DepartmentDescriptorProxy from 'src/pages/Worker/Department/Card/DepartmentDescriptorProxy.vue';
const $props = defineProps({
id: {
type: Number,
required: false,
default: null,
},
dataKey: {
type: String,
required: false,
default: 'Worker',
},
});
const image = ref(null);
const route = useRoute();
const { t } = useI18n();
const showEditPhotoForm = ref(false);
const toggleEditPictureForm = () => {
showEditPhotoForm.value = !showEditPhotoForm.value;
};
const entityId = computed(() => {
return $props.id || route.params.id;
});
const workerExcluded = ref(false);
const getIsExcluded = async () => {
const { data } = await axios.get(`WorkerDisableExcludeds/${entityId.value}/exists`);
if (!data) return;
workerExcluded.value = data.exists;
};
const handlePhotoUpdated = (evt = false) => {
image.value.reload(evt);
};
</script>
<template>
<CardDescriptor
ref="cardDescriptorRef"
:data-key="dataKey"
url="Workers/summary"
:filter="{ where: { id: entityId } }"
title="user.nickname"
@on-fetch="getIsExcluded"
>
<template #menu="{ entity }">
<WorkerDescriptorMenu
:worker="entity"
:is-excluded="workerExcluded"
@show-dialog="$refs.changePassRef.show"
/>
</template>
<template #before>
<div class="relative-position">
<VnImg
ref="image"
:id="parseInt(entityId)"
collection="user"
resolution="520x520"
class="photo"
>
<template #error>
<div
class="absolute-full picture text-center q-pa-md flex flex-center"
>
<div>
<div
class="text-grey-5"
style="opacity: 0.4; font-size: 5vh"
>
<QIcon name="vn:claims" />
</div>
<div class="text-grey-5" style="opacity: 0.4">
{{ t('worker.imageNotFound') }}
</div>
</div>
</div>
</template> </VnImg
><QBtn
color="primary"
size="lg"
round
class="edit-photo-btn"
@click="toggleEditPictureForm()"
>
<QIcon name="edit" size="sm" />
<QDialog ref="editPhotoFormDialog" v-model="showEditPhotoForm">
<EditPictureForm
collection="user"
:id="entityId"
@close-form="toggleEditPictureForm()"
@on-photo-uploaded="handlePhotoUpdated"
/>
</QDialog>
</QBtn>
</div>
</template>
<template #body="{ entity }">
<VnLv :label="t('globals.user')" :value="entity.user?.name" />
<VnLv
class="ellipsis-text"
:label="t('globals.params.email')"
:value="entity.user?.emailUser?.email"
copy
/>
<VnLv :label="t('worker.list.department')">
<template #value>
<span class="link" v-text="entity.department?.department?.name" />
<DepartmentDescriptorProxy :id="entity.department?.department?.id" />
</template>
</VnLv>
<VnLv :value="entity.phone">
<template #label>
{{ t('globals.phone') }}
<VnLinkPhone :phone-number="entity.phone" />
</template>
</VnLv>
<VnLv :value="entity?.sip?.extension">
<template #label>
{{ t('worker.summary.sipExtension') }}
<VnLinkPhone :phone-number="entity?.sip?.extension" />
</template>
</VnLv>
</template>
<template #actions="{ entity }">
<QCardActions class="flex justify-center">
<QBtn
:to="{
name: 'CustomerCard',
params: { id: entity.id },
}"
size="md"
icon="vn:Person"
color="primary"
>
<QTooltip>{{ t('Go to client') }}</QTooltip>
</QBtn>
<QBtn
:to="{
name: 'AccountCard',
params: { id: entity.user?.id },
}"
size="md"
icon="face"
color="primary"
>
<QTooltip>{{ t('Go to user') }}</QTooltip>
</QBtn>
</QCardActions>
</template>
</CardDescriptor>
<VnChangePassword
ref="changePassRef"
:submit-fn="
async (newPass) => {
await axios.patch(`Workers/${$route.params.id}/setPassword`, { newPass });
}
"
@on-submit="$refs.cardDescriptorRef?.getData"
/>
</template>
<style lang="scss" scoped>
.photo {
height: 256px;
}
.ellipsis-text {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
<i18n>
es:
Click to allow the user to be disabled: Marcar para deshabilitar
Click to exclude the user from getting disabled: Marcar para no deshabilitar
</i18n>