From 68192e50744b7a5e75680a32f65b4a5c887eb35a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 12 Jul 2024 01:20:36 +0200 Subject: [PATCH] perf: onRowchange --- src/pages/Item/ItemFixedPrice.vue | 48 +++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/pages/Item/ItemFixedPrice.vue b/src/pages/Item/ItemFixedPrice.vue index f89c50b1c..32ccbc281 100644 --- a/src/pages/Item/ItemFixedPrice.vue +++ b/src/pages/Item/ItemFixedPrice.vue @@ -281,28 +281,54 @@ const validations = (row, rowIndex, col) => { ); }; +async function upsertFixedPrice(row) { + try { + const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row); + return data; + } catch (err) { + console.error('Error editing price', err); + } +} const upsertPrice = async ({ row, col, rowIndex }, resetMinPrice = false) => { if (!validations(row, rowIndex, col)) return; try { if (resetMinPrice) row.hasMinPrice = 0; - - const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row); - row = data; + row = await upsertFixedPrice(row); fixedPricesOriginalData.value[rowIndex][col.field] = row[col.field]; } catch (err) { console.error('Error editing price', err); } }; -const lastRow = ref(null); async function saveOnRowChange(_, row) { - if (lastRow.value && lastRow.value !== row.id) { - console.log('update'); - // await upsertPrice(row); - } - lastRow.value = row.id; + if (rowsSelected.value.length > 1) return; + if (rowsSelected.value[0]?.id === row.id) return; + else if (rowsSelected.value.length === 1) + await upsertFixedPrice(rowsSelected.value[0]); rowsSelected.value = [row]; + // if (rowsSelected.value.length > 0) { + // disableUnselectedRows(); + // } else { + // resetRowStates(); + // } + // if (lastRow.value && lastRow.value !== row.id) { + // console.log('update'); + // // await upsertPrice(row); + // } + // lastRow.value = row.id; } +// function disableUnselectedRows() { +// fixedPrices.value.forEach((row) => { +// row.disabled = !rowsSelected.value.includes(row.id); +// }); +// } +// function resetRowStates() { +// fixedPrices.value.forEach((row) => { +// row.disable = false; +// }); +// // AquĆ­ puedes guardar los cambios si es necesario +// console.log('Guardando cambios...'); +// } const tableRef = ref(); function checkLastVisibleRow() { const tableBody = tableRef.value.$el.querySelector('tbody'); @@ -370,6 +396,7 @@ async function showBadDates() { try { if (!checked.value) fixedPrices.value = fixedPricesOriginalData.value; else { + rowsSelected.value = []; const { data } = await axios.get('FixedPrices/filter', { params: { showBadDates: checked.value, @@ -539,6 +566,9 @@ onUnmounted(() => (stateStore.rightDrawer = false)); style="width: 10px; margin-left: -20px" v-model="scope.selected" /> +