handle replaceItem

This commit is contained in:
Javier Segarra 2024-06-19 15:25:57 +02:00
parent 86cfbace72
commit 1367c372e3
2 changed files with 51 additions and 6 deletions

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, computed } from 'vue'; import { ref, computed, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import VnPaginate from 'components/ui/VnPaginate.vue'; import VnPaginate from 'components/ui/VnPaginate.vue';
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue'; import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
@ -28,6 +28,16 @@ const $props = defineProps({
required: true, required: true,
default: () => {}, default: () => {},
}, },
itemLack: {
type: Object,
required: true,
default: () => {},
},
replaceAction: {
type: Boolean,
required: false,
default: false,
},
tickets: { tickets: {
type: Array, type: Array,
required: false, required: false,
@ -173,9 +183,11 @@ async function confirm() {
// } // }
// onDialogOK({ data: true }); // onDialogOK({ data: true });
emit('refreshData', { type: 'refresh', itemProposal: proposalSelected.value[0] }); emit('refreshData', { type: 'refresh', itemProposal: proposalSelected.value[0] });
proposalSelected.value = null;
popupProxyRef.value.hide();
} }
const { dialogRef, onDialogOK, onDialogCancel } = useDialogPluginComponent(); const { dialogRef, onDialogOK, onDialogCancel } = useDialogPluginComponent();
const popupProxyRef = ref(null);
// Definir el emisor de eventos // Definir el emisor de eventos
const emit = defineEmits(['dialogClosed', 'refreshData']); const emit = defineEmits(['dialogClosed', 'refreshData']);
@ -184,10 +196,12 @@ function onDialogClose() {
// Emitir el evento personalizado // Emitir el evento personalizado
emit('dialogClosed', { data: true }); emit('dialogClosed', { data: true });
} }
onUnmounted(() => {});
</script> </script>
<template> <template>
<QPopupProxy ref="popupProxyRef"> <QPopupProxy ref="popupProxyRef">
<QCard class="q-pa-lg"> <QCard class="q-pa-lg">
<!-- {{ itemLack }} -->
<QCardSection v-if="false" class="row items-center q-pb-none"> <QCardSection v-if="false" class="row items-center q-pb-none">
<VnLv class="image"> <VnLv class="image">
<template #label> <template #label>
@ -226,7 +240,7 @@ function onDialogClose() {
}} --> }} -->
</span> </span>
</QCardSection> </QCardSection>
<QCardActions> <QCardActions v-if="$props.replaceAction">
<QBtn <QBtn
:label="t('globals.removeSelection')" :label="t('globals.removeSelection')"
color="primary" color="primary"
@ -257,7 +271,7 @@ function onDialogClose() {
<QCardSection class="row items-center justify-center column items-stretch"> <QCardSection class="row items-center justify-center column items-stretch">
<!-- <VnRow style="display: flex"> --> <!-- <VnRow style="display: flex"> -->
<div> <div>
{{ proposalSelected }} <!-- {{ proposalSelected }} -->
<VnPaginate <VnPaginate
:append="false" :append="false"
data-key="ItemsGetSimilar" data-key="ItemsGetSimilar"
@ -276,6 +290,7 @@ function onDialogClose() {
:columns="columns" :columns="columns"
row-key="id" row-key="id"
selection="single" selection="single"
disa
:pagination="{ rowsPerPage: 0 }" :pagination="{ rowsPerPage: 0 }"
class="full-width q-mt-md" class="full-width q-mt-md"
:no-data-label="t('globals.noResults')" :no-data-label="t('globals.noResults')"
@ -288,6 +303,34 @@ function onDialogClose() {
hide-pagination hide-pagination
hide-bottom hide-bottom
> >
<template #body-selection="scope">
<QTd align="center" v-if="$props.replaceAction"
><QCheckbox
v-model="scope.selected"
:disable="
!(
scope.row.available >=
itemLack.lack * -1
)
"
>
<QTooltip
v-if="
!(
scope.row.available >=
itemLack.lack * -1
)
"
>
Nop</QTooltip
>
</QCheckbox>
<!-- <div v-else class="q-ml-sm">
<QIcon name="info" size="sm"></QIcon>
</div
>--></QTd
>
</template>
<template #top-row> <template #top-row>
<!-- <QTr> <!-- <QTr>
<QTd /> <QTd />

View File

@ -345,7 +345,7 @@ const replaceItem = () => {
if (ticket.quantity > itemProposalSelected.value.available) continue; if (ticket.quantity > itemProposalSelected.value.available) continue;
originalRowDataCopy.value.splice(originalRowDataCopy.value.indexOf(ticket)); originalRowDataCopy.value.splice(originalRowDataCopy.value.indexOf(ticket));
ticket.itemFk = itemProposalSelected.value.id; ticket.itemFk = itemProposalSelected.value.id;
ticket.quantity *= 2; // ticket.quantity *= 2;
selectedRows.value.push({ ticketFk: ticket.ticketFk }); selectedRows.value.push({ ticketFk: ticket.ticketFk });
itemProposalSelected.value.available -= ticket.quantity; itemProposalSelected.value.available -= ticket.quantity;
itemLack.value.lack += ticket.quantity; itemLack.value.lack += ticket.quantity;
@ -450,6 +450,8 @@ const replaceItem = () => {
<ItemProposal <ItemProposal
ref="proposalDialogRef" ref="proposalDialogRef"
:item="item" :item="item"
:item-lack="itemLack"
:replace-action="true"
:tickets="selectedRows" :tickets="selectedRows"
@refresh-data="itemProposalEvt" @refresh-data="itemProposalEvt"
></ItemProposal> ></ItemProposal>
@ -493,7 +495,7 @@ const replaceItem = () => {
</QBtn> </QBtn>
<QBadge <QBadge
text-color="white" text-color="white"
color="red" :color="itemLack.lack === 0 ? 'green' : 'red'"
:label="itemLack.lack" :label="itemLack.lack"
/> />