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) => {
|
||||
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" />
|
||||
|
|
Loading…
Reference in New Issue