refactor: refs #6696 remove VnUsesMana component and update related logic in TicketEditMana and TicketSale
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2025-04-02 15:38:39 +02:00
parent c516ae1e12
commit 85f74e5ad8
4 changed files with 48 additions and 103 deletions

View File

@ -1,60 +0,0 @@
<script setup>
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const props = defineProps({
usesMana: {
type: Boolean,
required: true,
},
manaCode: {
type: String,
required: true,
},
manaVal: {
type: String,
default: 'mana',
},
manaLabel: {
type: String,
default: 'Promotion mana',
},
manaClaimVal: {
type: String,
default: 'manaClaim',
},
claimLabel: {
type: String,
default: 'Claim mana',
},
});
const manaCode = ref(props.manaCode);
</script>
<template>
<div class="column q-gutter-y-sm q-mt-sm">
<QRadio
v-model="manaCode"
dense
:val="manaVal"
:label="t(manaLabel)"
:dark="true"
class="q-mb-sm"
/>
<QRadio
v-model="manaCode"
dense
:val="manaClaimVal"
:label="t(claimLabel)"
:dark="true"
class="q-mb-sm"
/>
</div>
</template>
<i18n>
es:
Promotion mana: Maná promoción
Claim mana: Maná reclamación
</i18n>

View File

@ -4,7 +4,6 @@ import { useI18n } from 'vue-i18n';
import { computed, ref } from 'vue';
import { useRoute } from 'vue-router';
import { toCurrency } from 'src/filters';
import VnUsesMana from 'components/ui/VnUsesMana.vue';
const $props = defineProps({
newPrice: {
@ -15,23 +14,36 @@ const $props = defineProps({
type: Object,
default: null,
},
componentId: {
type: Number,
default: null,
},
});
const emit = defineEmits(['save', 'cancel', 'update:componentId']);
const route = useRoute();
const mana = ref(null);
const usesMana = ref(false);
const emit = defineEmits(['save', 'cancel']);
const usesMana = ref([]);
const { t } = useI18n();
const QPopupProxyRef = ref(null);
const manaCode = ref($props.manaCode);
const componentId = computed({
get: () => $props.componentId,
set: (val) => emit('update:componentId', val),
});
const save = (sale = $props.sale) => {
emit('save', sale);
QPopupProxyRef.value.hide();
};
const cancel = () => {
emit('cancel');
QPopupProxyRef.value.hide();
};
const getMana = async () => {
const { data } = await axios.get(`Tickets/${route.params.id}/getDepartmentMana`);
mana.value = data;
@ -39,15 +51,12 @@ const getMana = async () => {
};
const getUsesMana = async () => {
const { data } = await axios.get('Sales/usesMana');
const { data } = await axios.get('Sales/getComponents');
usesMana.value = data;
};
const cancel = () => {
emit('cancel');
QPopupProxyRef.value.hide();
};
const hasMana = computed(() => typeof mana.value === 'number');
defineExpose({ save });
</script>
@ -59,17 +68,28 @@ defineExpose({ save });
>
<div class="container">
<div class="header">Mana: {{ toCurrency(mana) }}</div>
<QSpinner v-if="!hasMana" color="primary" size="md" />
<QSpinner v-if="!usesMana.length" color="primary" />
<div class="q-pa-md" v-else>
<slot :popup="QPopupProxyRef" />
<div v-if="usesMana" class="column q-gutter-y-sm q-mt-sm">
<VnUsesMana :mana-code="manaCode" />
<div v-if="usesMana.length" class="column q-gutter-y-sm q-mt-sm">
<QRadio
v-for="(item, index) in usesMana"
:key="index"
v-model="componentId"
:val="item.id"
:label="item.name"
dense
:dark="true"
class="q-mb-sm"
/>
</div>
<div v-if="newPrice" class="column items-center q-mt-lg">
<span class="text-primary">{{ t('New price') }}</span>
<span class="text-subtitle1">
{{ toCurrency($props.newPrice) }}
</span>
<span class="text-subtitle1">{{ toCurrency(newPrice) }}</span>
</div>
</div>
@ -77,7 +97,6 @@ defineExpose({ save });
<QBtn
color="primary"
class="no-border-radius"
dense
style="width: 50%"
@click="cancel()"
>
@ -86,7 +105,6 @@ defineExpose({ save });
<QBtn
color="primary"
class="no-border-radius"
dense
style="width: 50%"
@click="save()"
data-cy="saveManaBtn"
@ -116,8 +134,3 @@ defineExpose({ save });
min-width: 230px;
}
</style>
<i18n>
es:
New price: Nuevo precio
</i18n>

View File

@ -45,7 +45,7 @@ const isTicketEditable = ref(false);
const sales = ref([]);
const editableStatesOptions = ref([]);
const selectedSales = ref([]);
const manaCode = ref('mana');
const componentId = ref(null);
const ticketState = computed(() => store.data?.ticketState?.state?.code);
const transfer = ref({
lastActiveTickets: [],
@ -262,18 +262,6 @@ const DEFAULT_EDIT = {
oldQuantity: null,
};
const edit = ref({ ...DEFAULT_EDIT });
const usesMana = ref(null);
const getUsesMana = async () => {
const { data } = await axios.get('Sales/usesMana');
usesMana.value = data;
};
const getMana = async () => {
const { data } = await axios.get(`Tickets/${route.params.id}/getDepartmentMana`);
mana.value = data;
await getUsesMana();
};
const selectedValidSales = computed(() => {
if (!sales.value) return;
@ -306,11 +294,14 @@ const changePrice = async (sale) => {
if (newPrice != null && newPrice != sale.price) {
if (await isSalePrepared(sale)) {
await confirmUpdate(() => updatePrice(sale, newPrice));
} else updatePrice(sale, newPrice);
} else await updatePrice(sale, newPrice);
}
};
const updatePrice = async (sale, newPrice) => {
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
await axios.post(`Sales/${sale.id}/updatePrice`, {
newPrice: newPrice,
componentId: componentId.value,
});
sale.price = newPrice;
edit.value = { ...DEFAULT_EDIT };
notify('globals.dataSaved', 'positive');
@ -341,7 +332,7 @@ const updateDiscount = async (sales, newDiscount = 0) => {
const params = {
salesIds,
newDiscount,
manaCode: manaCode.value,
componentId: componentId.value,
};
await axios.post(`Tickets/${route.params.id}/updateDiscount`, params);
notify('globals.dataSaved', 'positive');
@ -796,10 +787,11 @@ watch(
ref="editPriceProxyRef"
:sale="row"
:new-price="getNewPrice"
v-model:component-id="componentId"
@save="changePrice"
>
<VnInput
@keyup.enter.stop="() => editManaProxyRef.save(row)"
@keyup.enter.stop="() => editPriceProxyRef.save(row)"
v-model.number="edit.price"
:label="t('basicData.price')"
type="number"
@ -818,7 +810,7 @@ watch(
ref="editManaProxyRef"
:sale="row"
:new-price="getNewPrice"
:mana-code="manaCode"
v-model:component-id="componentId"
@save="changeDiscount"
>
<VnInput

View File

@ -113,7 +113,7 @@ const ticketCard = {
name: 'TicketExpedition',
meta: {
title: 'expedition',
icon: 'vn:package',
icon: 'view_in_ar',
},
component: () => import('src/pages/Ticket/Card/TicketExpedition.vue'),
},
@ -168,7 +168,7 @@ const ticketCard = {
name: 'TicketBoxing',
meta: {
title: 'boxing',
icon: 'view_in_ar',
icon: 'videocam',
},
component: () => import('src/pages/Ticket/Card/TicketBoxing.vue'),
},