fix: scroll to new work

This commit is contained in:
puriphatt 2024-10-17 13:21:31 +07:00
parent f855acca4f
commit 59f3af101a

View file

@ -7,7 +7,7 @@ import WorkManagementComponent from './WorkManagementComponent.vue';
import AddButton from '../button/AddButton.vue'; import AddButton from '../button/AddButton.vue';
import { ServiceCreate, WorkItems } from 'stores/product-service/types'; import { ServiceCreate, WorkItems } from 'stores/product-service/types';
import TreeView from '../shared/TreeView.vue'; import TreeView from '../shared/TreeView.vue';
import { ref, watch } from 'vue'; import { nextTick, ref, watch } from 'vue';
const { t } = useI18n(); const { t } = useI18n();
@ -34,6 +34,8 @@ defineEmits<{
(e: 'workProperties', index: number): void; (e: 'workProperties', index: number): void;
}>(); }>();
defineExpose({ addWork });
const nodes = ref([ const nodes = ref([
{ {
title: props.service?.name, title: props.service?.name,
@ -68,13 +70,20 @@ const nodes = ref([
}, },
]); ]);
function addWork() { async function addWork() {
workItems.value.push({ workItems.value.push({
id: '', id: '',
name: '', name: '',
attributes: { additional: [], showTotalPrice: false }, attributes: { additional: [], showTotalPrice: false },
product: [], product: [],
}); });
await nextTick();
const scrollTarget = document.getElementById(
`work-${workItems.value.length - 1}`,
);
if (scrollTarget)
scrollTarget.scrollIntoView({ behavior: 'instant', inline: 'center' });
} }
function confirmDelete(items: unknown[], index: number) { function confirmDelete(items: unknown[], index: number) {
@ -157,6 +166,7 @@ watch(
<WorkManagementComponent <WorkManagementComponent
class="col-12" class="col-12"
v-for="(work, index) in workItems" v-for="(work, index) in workItems"
:id="`work-${index}`"
:key="work.id" :key="work.id"
:index="index" :index="index"
:length="workItems.length" :length="workItems.length"