0
0
Fork 0

perf: onRowchange

This commit is contained in:
Javier Segarra 2024-07-12 01:20:36 +02:00
parent e862a6534b
commit 68192e5074
1 changed files with 39 additions and 9 deletions

View File

@ -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"
/>
<!--:disable="
rowsSelected.length > 0 && rowsSelected[0].id !== scope.row.id
"-->
</template>
<template #header-selection="scope">
<QCheckbox style="margin-left: -15px" v-model="scope.selected" />