Merge pull request 'fix_orderCatalog_reload' (!1085) 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: #1085 Reviewed-by: Jon Elias <jon@verdnatura.es>
This commit is contained in:
commit
601111ee9f
|
@ -20,21 +20,15 @@ const props = defineProps({
|
|||
});
|
||||
const state = useState();
|
||||
|
||||
const total = computed(() => state.get('orderTotal'));
|
||||
const orderData = computed(() => state.get('orderData'));
|
||||
|
||||
const prices = ref((props.item.prices || []).map((item) => ({ ...item, quantity: 0 })));
|
||||
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 totalQuantity = (items) =>
|
||||
items.reduce((acc, item) => {
|
||||
return acc + item.quantity;
|
||||
}, 0);
|
||||
const addToOrder = async () => {
|
||||
if (isLoading.value) return;
|
||||
isLoading.value = true;
|
||||
|
@ -44,11 +38,18 @@ const addToOrder = async () => {
|
|||
orderFk: Number(route.params.id),
|
||||
});
|
||||
|
||||
const { totalQuantity, totalSum } = calculateTotals(items);
|
||||
const { data: orderTotal } = await axios.get(
|
||||
`Orders/${Number(route.params.id)}/getTotal`
|
||||
);
|
||||
|
||||
state.set('orderTotal', total.value + totalSum);
|
||||
state.set('orderTotal', orderTotal);
|
||||
const rows = orderData.value.rows.push(...items) || [];
|
||||
state.set('orderData', {
|
||||
...orderData.value,
|
||||
rows,
|
||||
});
|
||||
notify(t('globals.dataSaved'), 'positive');
|
||||
emit('added', -totalQuantity);
|
||||
emit('added', -totalQuantity(items));
|
||||
isLoading.value = false;
|
||||
};
|
||||
const canAddToOrder = () => {
|
||||
|
|
Loading…
Reference in New Issue