0
0
Fork 0

fix: scrollInto Item

This commit is contained in:
Javier Segarra 2024-11-30 01:33:18 +01:00
parent d9d6819390
commit 0e1552f962
2 changed files with 18 additions and 2 deletions

View File

@ -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>

View File

@ -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,20 @@ watch(
},
{ immediate: true }
);
const onItemSaved = (updatedItem) => {
scrollToItem(updatedItem.items[0].itemFk);
};
const scrollToItem = async (id) => {
await nextTick();
setTimeout(() => {
const element = itemRefs.value[id]?.$el;
if (element) {
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}, 100);
};
provide('onItemSaved', onItemSaved);
</script>
<template>
@ -115,6 +130,7 @@ watch(
<CatalogItem
v-for="row in rows"
:key="row.id"
:ref="(el) => (itemRefs[row.id] = el)"
:item="row"
is-catalog
class="fill-icon"