0
0
Fork 0

fix: refs #6942 cardDescriptor use store if its popup or different source data

This commit is contained in:
Jorge Penadés 2024-05-23 12:33:13 +02:00
parent af32c4b79c
commit e8fed46dd1
2 changed files with 42 additions and 40 deletions

View File

@ -5,6 +5,7 @@ import SkeletonDescriptor from 'components/ui/SkeletonDescriptor.vue';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import { useSummaryDialog } from 'src/composables/useSummaryDialog'; import { useSummaryDialog } from 'src/composables/useSummaryDialog';
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import { useRoute } from 'vue-router';
const $props = defineProps({ const $props = defineProps({
url: { url: {
@ -21,12 +22,16 @@ const $props = defineProps({
}, },
subtitle: { subtitle: {
type: Number, type: Number,
default: 0, default: null,
}, },
dataKey: { dataKey: {
type: String, type: String,
default: null, default: null,
}, },
module: {
type: String,
default: null,
},
summary: { summary: {
type: Object, type: Object,
default: null, default: null,
@ -36,18 +41,23 @@ const $props = defineProps({
const state = useState(); const state = useState();
const { t } = useI18n(); const { t } = useI18n();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
const arrayData = useArrayData($props.dataKey || 'descriptor', { let arrayData;
url: $props.url, let store;
filter: $props.filter, let entity;
skip: 0,
});
const { store } = arrayData;
const entity = computed(() => (Array.isArray(store.data) ? store.data[0] : store.data));
const isLoading = ref(false); const isLoading = ref(false);
defineExpose({ getData }); defineExpose({ getData });
onBeforeMount(async () => { onBeforeMount(async () => {
if (!$props.dataKey) await getData(); arrayData = useArrayData($props.dataKey, {
url: $props.url,
filter: $props.filter,
skip: 0,
});
store = arrayData.store;
entity = computed(() => (Array.isArray(store.data) ? store.data[0] : store.data));
if ($props.dataKey !== useRoute().meta.moduleName) await getData();
watch( watch(
() => [$props.url, $props.filter], () => [$props.url, $props.filter],
async () => await getData() async () => await getData()
@ -91,7 +101,7 @@ const emit = defineEmits(['onFetch']);
</QBtn> </QBtn>
<RouterLink <RouterLink
:to="{ :to="{
name: `${$route.meta.moduleName}Summary`, name: `${module}Summary`,
params: { id: entity.id }, params: { id: entity.id },
}" }"
> >
@ -134,7 +144,7 @@ const emit = defineEmits(['onFetch']);
<QItemLabel header class="ellipsis text-h5" :lines="1"> <QItemLabel header class="ellipsis text-h5" :lines="1">
<div class="title"> <div class="title">
<span v-if="$props.title" :title="$props.title"> <span v-if="$props.title" :title="$props.title">
{{ $props.title }} {{ entity[title] ?? $props.title }}
</span> </span>
<slot v-else name="description" :entity="entity"> <slot v-else name="description" :entity="entity">
<span :title="entity.name"> <span :title="entity.name">

View File

@ -129,7 +129,11 @@ const correctionFormData = reactive({
}); });
const isNotFilled = computed(() => Object.values(correctionFormData).includes(null)); const isNotFilled = computed(() => Object.values(correctionFormData).includes(null));
onBeforeMount(async () => await setInvoiceCorrection(entityId.value)); onBeforeMount(async () => {
await setInvoiceCorrection(entityId.value);
const { data } = await axios.get(`InvoiceIns/${entityId.value}/getTotals`);
totalAmount.value = data.totalDueDay;
});
watch( watch(
() => currentRoute.value.params.id, () => currentRoute.value.params.id,
@ -169,11 +173,6 @@ async function setInvoiceCorrection(id) {
); );
} }
async function setTotals() {
const { data } = await axios.get(`InvoiceIns/${entityId.value}/getTotals`);
totalAmount.value = data.totalDueDay;
}
function openDialog() { function openDialog() {
quasar.dialog({ quasar.dialog({
component: VnConfirm, component: VnConfirm,
@ -263,7 +262,6 @@ const createInvoiceInCorrection = async () => {
push({ path: `/invoice-in/${correctingId}/summary` }); push({ path: `/invoice-in/${correctingId}/summary` });
}; };
</script> </script>
<template> <template>
<FetchData <FetchData
url="InvoiceInConfigs" url="InvoiceInConfigs"
@ -288,21 +286,18 @@ const createInvoiceInCorrection = async () => {
auto-load auto-load
/> />
<CardDescriptor <CardDescriptor
v-if="invoiceIn"
ref="cardDescriptorRef" ref="cardDescriptorRef"
module="InvoiceIn" module="InvoiceIn"
data-key="InvoiceIn"
:url="`InvoiceIns/${entityId}`" :url="`InvoiceIns/${entityId}`"
:filter="filter" :filter="filter"
:title="invoiceIn.supplierRef" title="supplierRef"
:subtitle="invoiceIn.id"
data-key="InvoiceIn"
@on-fetch="setTotals"
> >
<template #menu> <template #menu="{ entity }">
<InvoiceInToBook> <InvoiceInToBook>
<template #content="{ book }"> <template #content="{ book }">
<QItem <QItem
v-if="!invoiceIn?.isBooked && isAdministrative()" v-if="!entity?.isBooked && isAdministrative()"
v-ripple v-ripple
clickable clickable
@click="book(entityId)" @click="book(entityId)"
@ -312,7 +307,7 @@ const createInvoiceInCorrection = async () => {
</template> </template>
</InvoiceInToBook> </InvoiceInToBook>
<QItem <QItem
v-if="invoiceIn?.isBooked && isAdministrative()" v-if="entity?.isBooked && isAdministrative()"
v-ripple v-ripple
clickable clickable
@click="triggerMenu('unbook')" @click="triggerMenu('unbook')"
@ -364,37 +359,34 @@ const createInvoiceInCorrection = async () => {
<QItemSection>{{ t('Create rectificative invoice') }}...</QItemSection> <QItemSection>{{ t('Create rectificative invoice') }}...</QItemSection>
</QItem> </QItem>
<QItem <QItem
v-if="invoiceIn.dmsFk" v-if="entity.dmsFk"
v-ripple v-ripple
clickable clickable
@click="downloadFile(invoiceIn.dmsFk)" @click="downloadFile(entity.dmsFk)"
> >
<QItemSection>{{ t('components.smartCard.downloadFile') }}</QItemSection> <QItemSection>{{ t('components.smartCard.downloadFile') }}</QItemSection>
</QItem> </QItem>
</template> </template>
<template #body> <template #body="{ entity }">
<VnLv :label="t('invoiceIn.card.issued')" :value="toDate(invoiceIn.issued)" /> <VnLv :label="t('invoiceIn.card.issued')" :value="toDate(entity.issued)" />
<VnLv <VnLv :label="t('invoiceIn.summary.booked')" :value="toDate(entity.booked)" />
:label="t('invoiceIn.summary.booked')"
:value="toDate(invoiceIn.booked)"
/>
<VnLv :label="t('invoiceIn.card.amount')" :value="toCurrency(totalAmount)" /> <VnLv :label="t('invoiceIn.card.amount')" :value="toCurrency(totalAmount)" />
<VnLv :label="t('invoiceIn.summary.supplier')"> <VnLv :label="t('invoiceIn.summary.supplier')">
<template #value> <template #value>
<span class="link"> <span class="link">
{{ invoiceIn?.supplier?.nickname }} {{ entity?.supplier?.nickname }}
<SupplierDescriptorProxy :id="invoiceIn?.supplierFk" /> <SupplierDescriptorProxy :id="entity?.supplierFk" />
</span> </span>
</template> </template>
</VnLv> </VnLv>
</template> </template>
<template #action> <template #action="{ entity }">
<QCardActions> <QCardActions>
<QBtn <QBtn
size="md" size="md"
icon="vn:supplier" icon="vn:supplier"
color="primary" color="primary"
:to="routes.getSupplier(invoiceIn.supplierFk)" :to="routes.getSupplier(entity.supplierFk)"
> >
<QTooltip>{{ t('invoiceIn.list.supplier') }}</QTooltip> <QTooltip>{{ t('invoiceIn.list.supplier') }}</QTooltip>
</QBtn> </QBtn>
@ -402,7 +394,7 @@ const createInvoiceInCorrection = async () => {
size="md" size="md"
icon="vn:entry" icon="vn:entry"
color="primary" color="primary"
:to="routes.getEntry(invoiceIn.entryFk)" :to="routes.getEntry(entity.entryFk)"
> >
<QTooltip>{{ t('Entry') }}</QTooltip> <QTooltip>{{ t('Entry') }}</QTooltip>
</QBtn> </QBtn>
@ -410,7 +402,7 @@ const createInvoiceInCorrection = async () => {
size="md" size="md"
icon="vn:ticket" icon="vn:ticket"
color="primary" color="primary"
:to="routes.getTickets(invoiceIn.supplierFk)" :to="routes.getTickets(entity.supplierFk)"
> >
<QTooltip>{{ t('invoiceOut.card.ticketList') }}</QTooltip> <QTooltip>{{ t('invoiceOut.card.ticketList') }}</QTooltip>
</QBtn> </QBtn>