Merge pull request 'HOTFIX: OrderCatalog scroll To Item' (!1026) from hotfix_scrollToItem into master
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1026 Reviewed-by: Alex Moreno <alexm@verdnatura.es> Reviewed-by: Jon Elias <jon@verdnatura.es>
This commit is contained in:
commit
ce72388d5e
|
@ -67,7 +67,7 @@ const dialog = ref(null);
|
|||
<QTooltip>{{ t('globals.add') }}</QTooltip>
|
||||
<QPopupProxy ref="dialog">
|
||||
<OrderCatalogItemDialog
|
||||
:prices="item.prices"
|
||||
:item="item"
|
||||
@added="() => dialog.hide()"
|
||||
/>
|
||||
</QPopupProxy>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script setup>
|
||||
import { useStateStore } from 'stores/useStateStore';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { onMounted, onUnmounted, ref, computed, watch } from 'vue';
|
||||
import { onMounted, onUnmounted, ref, computed, watch, provide, nextTick } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnPaginate from 'src/components/ui/VnPaginate.vue';
|
||||
|
@ -18,6 +18,7 @@ const dataKey = 'OrderCatalogList';
|
|||
const arrayData = useArrayData(dataKey);
|
||||
const store = arrayData.store;
|
||||
const tags = ref([]);
|
||||
const itemRefs = ref({});
|
||||
|
||||
let catalogParams = {
|
||||
orderFk: route.params.id,
|
||||
|
@ -76,6 +77,19 @@ watch(
|
|||
},
|
||||
{ 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>
|
||||
|
||||
<template>
|
||||
|
@ -115,6 +129,7 @@ watch(
|
|||
<CatalogItem
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
:ref="(el) => (itemRefs[row.id] = el)"
|
||||
:item="row"
|
||||
is-catalog
|
||||
class="fill-icon"
|
||||
|
|
|
@ -1,41 +1,53 @@
|
|||
<script setup>
|
||||
import toCurrency from '../../../filters/toCurrency';
|
||||
import { ref } from 'vue';
|
||||
import toCurrency from 'src/filters/toCurrency';
|
||||
import { inject, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import axios from 'axios';
|
||||
import { useRoute } from 'vue-router';
|
||||
import useNotify from 'composables/useNotify';
|
||||
import { useArrayData } from 'composables/useArrayData';
|
||||
import VnInputNumber from 'src/components/common/VnInputNumber.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const { notify } = useNotify();
|
||||
const emit = defineEmits(['added']);
|
||||
const route = useRoute();
|
||||
const props = defineProps({
|
||||
prices: {
|
||||
item: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const fields = ref((props.prices || []).map((item) => ({ ...item, quantity: 0 })));
|
||||
const onItemSaved = inject('onItemSaved');
|
||||
const prices = ref((props.item.prices || []).map((item) => ({ ...item, quantity: 0 })));
|
||||
const descriptorData = useArrayData('orderData');
|
||||
const isLoading = ref(false);
|
||||
const addToOrder = async () => {
|
||||
if (isLoading.value) return;
|
||||
isLoading.value = true;
|
||||
const items = (fields.value || []).filter((item) => Number(item.quantity) > 0);
|
||||
const items = (prices.value || []).filter((item) => Number(item.quantity) > 0);
|
||||
await axios.post('/OrderRows/addToOrder', {
|
||||
items,
|
||||
orderFk: Number(route.params.id),
|
||||
});
|
||||
notify(t('globals.dataSaved'), 'positive');
|
||||
emit('added');
|
||||
descriptorData.fetch({});
|
||||
await descriptorData.fetch({});
|
||||
onItemSaved({ ...props, items, saved: true });
|
||||
emit('added', items);
|
||||
isLoading.value = false;
|
||||
};
|
||||
const canAddToOrder = () => {
|
||||
return (fields.value || []).some((item) => Number(item.quantity) > 0);
|
||||
let canAddToOrder = (prices.value || []).some((price) => Number(price.quantity) > 0);
|
||||
if (canAddToOrder) {
|
||||
const excedQuantity = prices.value.reduce(
|
||||
(acc, { quantity }) => acc + quantity,
|
||||
0
|
||||
);
|
||||
if (excedQuantity > props.item.available) {
|
||||
canAddToOrder = false;
|
||||
}
|
||||
}
|
||||
return canAddToOrder;
|
||||
};
|
||||
</script>
|
||||
|
||||
|
@ -44,30 +56,33 @@ const canAddToOrder = () => {
|
|||
<QForm @submit="addToOrder">
|
||||
<QMarkupTable class="shadow-0">
|
||||
<tbody>
|
||||
<tr v-for="item in fields" :key="item.warehouse">
|
||||
<tr v-for="price in prices" :key="price.warehouse">
|
||||
<td class="text-bold q-pr-md td" style="width: 35%">
|
||||
{{ item.warehouse }}
|
||||
{{ price.warehouse }}
|
||||
</td>
|
||||
<td class="text-right" style="width: 35%">
|
||||
<span
|
||||
class="link"
|
||||
@click="
|
||||
@click.shift="
|
||||
() => {
|
||||
item.quantity += item.grouping;
|
||||
price.quantity -= price.grouping;
|
||||
}
|
||||
"
|
||||
@click.exact="
|
||||
() => {
|
||||
price.quantity += price.grouping;
|
||||
}
|
||||
"
|
||||
>
|
||||
{{ item.grouping }}
|
||||
{{ price.grouping }}
|
||||
</span>
|
||||
x {{ toCurrency(item.price) }}
|
||||
x {{ toCurrency(price.price) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<QInput
|
||||
v-model.number="item.quantity"
|
||||
type="number"
|
||||
:step="item.grouping"
|
||||
<VnInputNumber
|
||||
v-model.number="price.quantity"
|
||||
:step="price.grouping"
|
||||
min="0"
|
||||
dense
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue