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