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) => { const upsertPrice = async ({ row, col, rowIndex }, resetMinPrice = false) => {
if (!validations(row, rowIndex, col)) return; if (!validations(row, rowIndex, col)) return;
try { try {
if (resetMinPrice) row.hasMinPrice = 0; if (resetMinPrice) row.hasMinPrice = 0;
row = await upsertFixedPrice(row);
const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
row = data;
fixedPricesOriginalData.value[rowIndex][col.field] = row[col.field]; fixedPricesOriginalData.value[rowIndex][col.field] = row[col.field];
} catch (err) { } catch (err) {
console.error('Error editing price', err); console.error('Error editing price', err);
} }
}; };
const lastRow = ref(null);
async function saveOnRowChange(_, row) { async function saveOnRowChange(_, row) {
if (lastRow.value && lastRow.value !== row.id) { if (rowsSelected.value.length > 1) return;
console.log('update'); if (rowsSelected.value[0]?.id === row.id) return;
// await upsertPrice(row); else if (rowsSelected.value.length === 1)
} await upsertFixedPrice(rowsSelected.value[0]);
lastRow.value = row.id;
rowsSelected.value = [row]; 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(); const tableRef = ref();
function checkLastVisibleRow() { function checkLastVisibleRow() {
const tableBody = tableRef.value.$el.querySelector('tbody'); const tableBody = tableRef.value.$el.querySelector('tbody');
@ -370,6 +396,7 @@ async function showBadDates() {
try { try {
if (!checked.value) fixedPrices.value = fixedPricesOriginalData.value; if (!checked.value) fixedPrices.value = fixedPricesOriginalData.value;
else { else {
rowsSelected.value = [];
const { data } = await axios.get('FixedPrices/filter', { const { data } = await axios.get('FixedPrices/filter', {
params: { params: {
showBadDates: checked.value, showBadDates: checked.value,
@ -539,6 +566,9 @@ onUnmounted(() => (stateStore.rightDrawer = false));
style="width: 10px; margin-left: -20px" style="width: 10px; margin-left: -20px"
v-model="scope.selected" v-model="scope.selected"
/> />
<!--:disable="
rowsSelected.length > 0 && rowsSelected[0].id !== scope.row.id
"-->
</template> </template>
<template #header-selection="scope"> <template #header-selection="scope">
<QCheckbox style="margin-left: -15px" v-model="scope.selected" /> <QCheckbox style="margin-left: -15px" v-model="scope.selected" />