forked from verdnatura/salix-front
perf: onRowchange
This commit is contained in:
parent
e862a6534b
commit
68192e5074
|
@ -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" />
|
||||||
|
|
Loading…
Reference in New Issue