Merge pull request 'fix_orderCatalog_reload' (!1081) from fix_orderCatalog_reload into dev
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1081 Reviewed-by: Jon Elias <jon@verdnatura.es>
This commit is contained in:
commit
74bf536db1
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref, toRef } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import VnLv from 'components/ui/VnLv.vue';
|
import VnLv from 'components/ui/VnLv.vue';
|
||||||
|
@ -13,7 +13,7 @@ const DEFAULT_PRICE_KG = 0;
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
defineProps({
|
const props = defineProps({
|
||||||
item: {
|
item: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -25,57 +25,63 @@ defineProps({
|
||||||
});
|
});
|
||||||
|
|
||||||
const dialog = ref(null);
|
const dialog = ref(null);
|
||||||
|
const card = toRef(props, 'item');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="container order-catalog-item overflow-hidden">
|
<div class="container order-catalog-item overflow-hidden">
|
||||||
<QCard class="card shadow-6">
|
<QCard class="card shadow-6">
|
||||||
<div class="img-wrapper">
|
<div class="img-wrapper">
|
||||||
<VnImg :id="item.id" class="image" zoom-resolution="1600x900" />
|
<VnImg :id="card.id" class="image" zoom-resolution="1600x900" />
|
||||||
<div v-if="item.hex && isCatalog" class="item-color-container">
|
<div v-if="card.hex && isCatalog" class="item-color-container">
|
||||||
<div
|
<div
|
||||||
class="item-color"
|
class="item-color"
|
||||||
:style="{ backgroundColor: `#${item.hex}` }"
|
:style="{ backgroundColor: `#${card.hex}` }"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<span class="link">
|
<span class="link">
|
||||||
{{ item.name }}
|
{{ card.name }}
|
||||||
<ItemDescriptorProxy :id="item.id" />
|
<ItemDescriptorProxy :id="card.id" />
|
||||||
</span>
|
</span>
|
||||||
<p class="subName">{{ item.subName }}</p>
|
<p class="subName">{{ card.subName }}</p>
|
||||||
<template v-for="index in 4" :key="`tag-${index}`">
|
<template v-for="index in 4" :key="`tag-${index}`">
|
||||||
<VnLv
|
<VnLv
|
||||||
v-if="item?.[`tag${index + 4}`]"
|
v-if="card?.[`tag${index + 4}`]"
|
||||||
:label="item?.[`tag${index + 4}`] + ':'"
|
:label="card?.[`tag${index + 4}`] + ':'"
|
||||||
:value="item?.[`value${index + 4}`]"
|
:value="card?.[`value${index + 4}`]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<div v-if="item.minQuantity" class="min-quantity">
|
<div v-if="card.minQuantity" class="min-quantity">
|
||||||
<QIcon name="production_quantity_limits" size="xs" />
|
<QIcon name="production_quantity_limits" size="xs" />
|
||||||
{{ item.minQuantity }}
|
{{ card.minQuantity }}
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<div class="price">
|
<div class="price">
|
||||||
<p v-if="isCatalog">
|
<p v-if="isCatalog">
|
||||||
{{ item.available }} {{ t('to') }}
|
{{ card.available }} {{ t('to') }}
|
||||||
{{ toCurrency(item.price) }}
|
{{ toCurrency(card.price) }}
|
||||||
</p>
|
</p>
|
||||||
<slot name="price" />
|
<slot name="price" />
|
||||||
<QIcon v-if="isCatalog" name="add_circle" class="icon">
|
<QIcon v-if="isCatalog" name="add_circle" class="icon">
|
||||||
<QTooltip>{{ t('globals.add') }}</QTooltip>
|
<QTooltip>{{ t('globals.add') }}</QTooltip>
|
||||||
<QPopupProxy ref="dialog">
|
<QPopupProxy ref="dialog">
|
||||||
<OrderCatalogItemDialog
|
<OrderCatalogItemDialog
|
||||||
:item="item"
|
:item="card"
|
||||||
@added="() => dialog.hide()"
|
@added="
|
||||||
|
(quantityAdded) => {
|
||||||
|
card.available += quantityAdded;
|
||||||
|
dialog.hide();
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</QPopupProxy>
|
</QPopupProxy>
|
||||||
</QIcon>
|
</QIcon>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="item.priceKg" class="price-kg">
|
<p v-if="card.priceKg" class="price-kg">
|
||||||
{{ t('price-kg') }}
|
{{ t('price-kg') }}
|
||||||
{{ toCurrency(item.priceKg) || DEFAULT_PRICE_KG }}
|
{{ toCurrency(card.priceKg) || DEFAULT_PRICE_KG }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -75,19 +75,6 @@ watch(
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
const onItemSaved = (updatedItem) => {
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
scrollToItem(updatedItem.items[0].itemFk);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const scrollToItem = async (id) => {
|
|
||||||
const element = itemRefs.value[id]?.$el;
|
|
||||||
if (element) {
|
|
||||||
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
provide('onItemSaved', onItemSaved);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -65,7 +65,6 @@ const selectCategory = async (params, category, search) => {
|
||||||
params.typeFk = null;
|
params.typeFk = null;
|
||||||
params.categoryFk = category.id;
|
params.categoryFk = category.id;
|
||||||
await loadTypes(category?.id);
|
await loadTypes(category?.id);
|
||||||
await search();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadTypes = async (id) => {
|
const loadTypes = async (id) => {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import toCurrency from 'src/filters/toCurrency';
|
import toCurrency from 'src/filters/toCurrency';
|
||||||
import { inject, ref } from 'vue';
|
import { computed, inject, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import useNotify from 'composables/useNotify';
|
import useNotify from 'composables/useNotify';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
|
||||||
import VnInputNumber from 'src/components/common/VnInputNumber.vue';
|
import VnInputNumber from 'src/components/common/VnInputNumber.vue';
|
||||||
|
import { useState } from 'src/composables/useState';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
|
@ -18,10 +18,23 @@ const props = defineProps({
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const onItemSaved = inject('onItemSaved');
|
const state = useState();
|
||||||
|
|
||||||
|
const total = computed(() => state.get('orderTotal'));
|
||||||
|
|
||||||
const prices = ref((props.item.prices || []).map((item) => ({ ...item, quantity: 0 })));
|
const prices = ref((props.item.prices || []).map((item) => ({ ...item, quantity: 0 })));
|
||||||
const descriptorData = useArrayData('orderData');
|
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
const calculateTotals = (items) => {
|
||||||
|
return items.reduce(
|
||||||
|
(acc, item) => {
|
||||||
|
acc.totalQuantity += item.quantity;
|
||||||
|
acc.totalSum += item.quantity * item.price;
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{ totalQuantity: 0, totalSum: 0 }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const addToOrder = async () => {
|
const addToOrder = async () => {
|
||||||
if (isLoading.value) return;
|
if (isLoading.value) return;
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
|
@ -30,10 +43,12 @@ const addToOrder = async () => {
|
||||||
items,
|
items,
|
||||||
orderFk: Number(route.params.id),
|
orderFk: Number(route.params.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { totalQuantity, totalSum } = calculateTotals(items);
|
||||||
|
|
||||||
|
state.set('orderTotal', total.value + totalSum);
|
||||||
notify(t('globals.dataSaved'), 'positive');
|
notify(t('globals.dataSaved'), 'positive');
|
||||||
await descriptorData.fetch({});
|
emit('added', -totalQuantity);
|
||||||
onItemSaved({ ...props, items, saved: true });
|
|
||||||
emit('added', items);
|
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
};
|
};
|
||||||
const canAddToOrder = () => {
|
const canAddToOrder = () => {
|
||||||
|
|
|
@ -63,21 +63,26 @@ const setData = (entity) => {
|
||||||
if (!entity) return;
|
if (!entity) return;
|
||||||
getTotalRef.value && getTotalRef.value.fetch();
|
getTotalRef.value && getTotalRef.value.fetch();
|
||||||
data.value = useCardDescription(entity?.client?.name, entity?.id);
|
data.value = useCardDescription(entity?.client?.name, entity?.id);
|
||||||
state.set('orderData', entity);
|
state.set('orderTotal', total);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getConfirmationValue = (isConfirmed) => {
|
const getConfirmationValue = (isConfirmed) => {
|
||||||
return t(isConfirmed ? 'globals.confirmed' : 'order.summary.notConfirmed');
|
return t(isConfirmed ? 'globals.confirmed' : 'order.summary.notConfirmed');
|
||||||
};
|
};
|
||||||
|
|
||||||
const total = ref(null);
|
const orderTotal = computed(() => state.get('orderTotal') ?? 0);
|
||||||
|
const total = ref(0);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
<FetchData
|
||||||
ref="getTotalRef"
|
ref="getTotalRef"
|
||||||
:url="`Orders/${entityId}/getTotal`"
|
:url="`Orders/${entityId}/getTotal`"
|
||||||
@on-fetch="(response) => (total = response)"
|
@on-fetch="
|
||||||
|
(response) => {
|
||||||
|
total = response;
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<CardDescriptor
|
<CardDescriptor
|
||||||
ref="descriptor"
|
ref="descriptor"
|
||||||
|
@ -112,7 +117,7 @@ const total = ref(null);
|
||||||
:label="t('order.summary.items')"
|
:label="t('order.summary.items')"
|
||||||
:value="(entity?.rows?.length || DEFAULT_ITEMS).toString()"
|
:value="(entity?.rows?.length || DEFAULT_ITEMS).toString()"
|
||||||
/>
|
/>
|
||||||
<VnLv :label="t('order.summary.total')" :value="toCurrency(total)" />
|
<VnLv :label="t('order.summary.total')" :value="toCurrency(orderTotal)" />
|
||||||
</template>
|
</template>
|
||||||
<template #actions="{ entity }">
|
<template #actions="{ entity }">
|
||||||
<QCardActions>
|
<QCardActions>
|
||||||
|
|
Loading…
Reference in New Issue