From 7892e68e1b433f33e15fa524c3e5c961a18220c4 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 2 Sep 2024 15:03:47 +0200 Subject: [PATCH] feat: updates --- src/pages/Item/ItemFixedPrice.vue | 68 +++++++++++++++++-------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/pages/Item/ItemFixedPrice.vue b/src/pages/Item/ItemFixedPrice.vue index cfd2d91fb..41cfa0676 100644 --- a/src/pages/Item/ItemFixedPrice.vue +++ b/src/pages/Item/ItemFixedPrice.vue @@ -233,8 +233,9 @@ function checkLastVisibleRow() { return lastVisibleRow; } } -const addRow = (fixedPrice = null) => { - const lastvisible = checkLastVisibleRow(); +const addRow = (original = null) => { + // const original = checkLastVisibleRow(); + let copy = null; // if (!fixedPrices.value || fixedPrices.value.length === 0) { // fixedPrices.value = []; @@ -253,52 +254,53 @@ const addRow = (fixedPrice = null) => { // fixedPrices.value.push({ ...newPrice }); // return; // } - if (!fixedPrice) { + if (!original) { const today = Date.vnNew(); const millisecsInDay = 86400000; const daysInWeek = 7; const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay); // lastItem.value = { - lastItem.value = { + copy = { started: today, ended: nextWeek, hasMinPrice: 0, }; - return; + // return; } - const lastItemCopy = { - itemFk: fixedPrice.itemFk, - name: fixedPrice.name, - subName: fixedPrice.subName, - value5: fixedPrice.value5, - value6: fixedPrice.value6, - value7: fixedPrice.value7, - value8: fixedPrice.value8, - value9: fixedPrice.value9, - value10: fixedPrice.value10, - warehouseFk: fixedPrice.warehouseFk, - rate2: fixedPrice.rate2, - rate3: fixedPrice.rate3, - hasMinPrice: fixedPrice.hasMinPrice, - minPrice: fixedPrice.minPrice, - started: fixedPrice.started, - ended: fixedPrice.ended, + copy = { + $index: original.$index - 1, + itemFk: original.itemFk, + name: original.name, + subName: original.subName, + value5: original.value5, + value6: original.value6, + value7: original.value7, + value8: original.value8, + value9: original.value9, + value10: original.value10, + warehouseFk: original.warehouseFk, + rate2: original.rate2, + rate3: original.rate3, + hasMinPrice: original.hasMinPrice, + minPrice: original.minPrice, + started: Date.vnNew(), + ended: Date.vnNew(), }; // lastItem.value = lastItemCopy; // tableRef.value.create.onDataSaved(lastItem); - return lastItemCopy; + // nextTick(() => { + // highlightNewRow(fixedPrice); + // }); // delete lastItemCopy.id; // fixedPricesOriginalData.value.splice(lastvisible, 0, lastItemCopy); // fixedPrices.value.unshift(lastItemCopy); - // nextTick(() => { - // highlightNewRow(lastvisible); - // }); + return { original, copy }; }; const lastItem = ref(null); -function highlightNewRow(index) { +function highlightNewRow({ $index: index }) { const row = document .getElementsByClassName('q-table')[0] .querySelectorAll('tr.cursor-pointer')[index]; @@ -365,10 +367,11 @@ onMounted(async () => { params.warehouseFk = user.value.warehouseFk; }); function handleOnDataSave({ CrudModelRef }) { - const roww = addRow(CrudModelRef.formData[CrudModelRef.formData.length - 1]); - CrudModelRef.formData.unshift(lastItem); + const { original, copy } = addRow(CrudModelRef.formData[checkLastVisibleRow()]); + // CrudModelRef.formData.unshift(roww); + CrudModelRef.formData.splice(original.$index, 0, copy); nextTick(() => { - highlightNewRow(checkLastVisibleRow()); + highlightNewRow(original); }); } onUnmounted(() => (stateStore.rightDrawer = false)); @@ -415,10 +418,13 @@ onUnmounted(() => (stateStore.rightDrawer = false));