refactor: refs #7010 modified front

This commit is contained in:
Jon Elias 2024-09-26 14:12:59 +02:00
parent 6d5a8cba6f
commit 1c99c01d1d
1 changed files with 3 additions and 45 deletions

View File

@ -1,6 +1,6 @@
<script setup> <script setup>
import axios from 'axios'; import axios from 'axios';
import { computed, ref, onMounted, reactive } from 'vue'; import { computed, ref, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@ -62,7 +62,6 @@ const dialogData = ref();
const companiesOptions = ref([]); const companiesOptions = ref([]);
const accountingOptions = ref([]); const accountingOptions = ref([]);
const amountToReturn = ref(); const amountToReturn = ref();
const salesData = reactive({});
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -190,9 +189,9 @@ const columns = computed(() => [
}, },
{ {
align: 'left', align: 'left',
name: 'itemPackageFk', name: 'packing',
label: t('ticketSale.packaging'), label: t('ticketSale.packaging'),
format: (row, dashIfEmpty) => dashIfEmpty(row.itemPackageFk), format: (row, dashIfEmpty) => dashIfEmpty(row.packing),
}, },
{ {
align: 'right', align: 'right',
@ -442,41 +441,6 @@ function setReference(data) {
dialogData.value.value.description = newDescription; dialogData.value.value.description = newDescription;
} }
async function fetchSalesData(row) {
if (salesData[row.id]) {
return salesData[row.id]; // Retorna de caché si ya existen datos
}
try {
const sales = await getSales(row.id);
const packingTypes = getPackingTypes(sales);
const result = packingTypes.length > 0 ? packingTypes.join(', ') : '-';
salesData[row.id] = result; // Cachea el resultado
return result;
} catch (err) {
console.error('Error fetching sales', err);
salesData[row.id] = 'Error'; // Cachea el error
return 'Error';
}
}
async function getSales(rowId) {
const { data } = await axios.get(`Tickets/${rowId}/getSales`);
return data;
}
function getPackingTypes(sales) {
const itemPackingTypes = [];
sales.forEach((sale) => {
const packingType = sale?.item?.itemPackingTypeFk;
if (packingType && !itemPackingTypes.includes(packingType)) {
itemPackingTypes.push(packingType);
}
});
return itemPackingTypes;
}
</script> </script>
<template> <template>
@ -641,12 +605,6 @@ function getPackingTypes(sales) {
{{ row.totalWithVat }} {{ row.totalWithVat }}
</QChip> </QChip>
</template> </template>
<template #column-itemPackageFk="{ row }">
<div v-if="salesData[row.id]">{{ dashIfEmpty(salesData[row.id]) }}</div>
<div v-else>
{{ fetchSalesData(row) }}
</div>
</template>
<template #more-create-dialog="{ data }"> <template #more-create-dialog="{ data }">
<VnRow> <VnRow>
<VnSelect <VnSelect