salix-front/src/components/ui/CardDescriptor.vue

111 lines
2.9 KiB
Vue
Raw Normal View History

2022-11-08 06:41:36 +00:00
<script setup>
import { onMounted, useSlots, computed, ref, toRef, watch } from 'vue';
2022-11-08 06:41:36 +00:00
import { useI18n } from 'vue-i18n';
import axios from 'axios';
import SkeletonDescriptor from 'components/ui/SkeletonDescriptor.vue';
2022-11-08 06:41:36 +00:00
const props = defineProps({
id: {
type: Number,
2022-11-08 12:36:22 +00:00
required: true,
},
module: {
type: String,
2022-11-08 06:41:36 +00:00
required: true,
},
2022-11-08 12:36:22 +00:00
description: {
type: String,
required: false,
default: '',
2022-11-08 12:36:22 +00:00
},
2022-11-08 06:41:36 +00:00
});
2022-11-08 06:41:36 +00:00
const slots = useSlots();
const { t } = useI18n();
onMounted(async () => {
await fetch();
});
const entity = ref();
const entityId = toRef(props, 'id');
const description = computed(() => {
return props.description || entity.value.name;
});
async function fetch() {
const { data } = await axios.get(`Clients/${entityId.value}/getCard`);
entity.value = data;
}
watch(entityId, async () => {
entity.value = null;
await fetch();
});
2022-11-08 06:41:36 +00:00
</script>
<template>
<div class="descriptor">
<div class="header bg-primary q-pa-sm">
2022-11-08 12:36:22 +00:00
<router-link :to="{ name: `${module}List` }">
2022-11-08 06:41:36 +00:00
<q-btn round flat dense size="md" icon="view_list" color="white">
2022-11-08 12:36:22 +00:00
<q-tooltip>{{ t('components.cardDescriptor.mainList') }}</q-tooltip>
2022-11-08 06:41:36 +00:00
</q-btn>
</router-link>
<router-link :to="{ name: `${module}Summary`, params: { id: entityId } }">
2022-11-08 06:41:36 +00:00
<q-btn round flat dense size="md" icon="launch" color="white">
2022-11-08 12:36:22 +00:00
<q-tooltip>{{ t('components.cardDescriptor.summary') }}</q-tooltip>
2022-11-08 06:41:36 +00:00
</q-btn>
</router-link>
<q-btn v-if="slots.menu" size="md" icon="more_vert" color="white" round flat dense>
2022-11-08 12:36:22 +00:00
<q-tooltip>{{ t('components.cardDescriptor.moreOptions') }}</q-tooltip>
2022-11-08 06:41:36 +00:00
<q-menu>
<q-list>
<slot name="menu" />
</q-list>
</q-menu>
</q-btn>
</div>
<div v-if="entity" class="body q-py-sm">
2022-11-08 12:36:22 +00:00
<q-list>
<q-item-label header class="ellipsis text-h5" :lines="1">
{{ description }}
<q-tooltip>{{ description }}</q-tooltip>
2022-11-08 12:36:22 +00:00
</q-item-label>
<q-item dense>
<q-item-label class="text-subtitle2" caption>#{{ entity.id }}</q-item-label>
2022-11-08 12:36:22 +00:00
</q-item>
</q-list>
<slot name="body" :entity="entity" />
2022-11-08 06:41:36 +00:00
</div>
<!-- Skeleton -->
<skeleton-descriptor v-if="!entity" />
2022-11-08 06:41:36 +00:00
</div>
</template>
2022-11-08 12:36:22 +00:00
<style lang="scss">
.body {
.q-card__actions {
justify-content: center;
}
.text-h5 {
padding-top: 5px;
padding-bottom: 5px;
}
}
</style>
2022-11-08 06:41:36 +00:00
<style lang="scss" scoped>
.descriptor {
2022-11-08 12:36:22 +00:00
width: 256px;
2022-11-08 06:41:36 +00:00
.header {
display: flex;
justify-content: space-between;
align-items: stretch;
}
}
</style>