perf: minor clean code
This commit is contained in:
parent
754f047943
commit
53e6c67ff9
|
@ -263,8 +263,6 @@ const updateMinPrice = async (value, props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const upsertPrice = async ({ row }, resetMinPrice = false) => {
|
const upsertPrice = async ({ row }, resetMinPrice = false) => {
|
||||||
// if (!validations(row, rowIndex, col)) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (resetMinPrice) row.hasMinPrice = 0;
|
if (resetMinPrice) row.hasMinPrice = 0;
|
||||||
row = await upsertFixedPrice(row);
|
row = await upsertFixedPrice(row);
|
||||||
|
@ -272,6 +270,7 @@ const upsertPrice = async ({ row }, resetMinPrice = false) => {
|
||||||
console.error('Error editing price', err);
|
console.error('Error editing price', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function upsertFixedPrice(row) {
|
async function upsertFixedPrice(row) {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
|
const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
|
||||||
|
@ -280,6 +279,7 @@ async function upsertFixedPrice(row) {
|
||||||
console.error('Error editing price', err);
|
console.error('Error editing price', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveOnRowChange(row) {
|
async function saveOnRowChange(row) {
|
||||||
if (rowsSelected.value.length > 1) return;
|
if (rowsSelected.value.length > 1) return;
|
||||||
if (rowsSelected.value[0]?.id === row.id) return;
|
if (rowsSelected.value[0]?.id === row.id) return;
|
||||||
|
@ -298,11 +298,9 @@ function checkLastVisibleRow() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (lastVisibleRow) {
|
|
||||||
console.log('Última fila visible:', lastVisibleRow);
|
|
||||||
}
|
|
||||||
return lastVisibleRow;
|
return lastVisibleRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
const addRow = (original = null) => {
|
const addRow = (original = null) => {
|
||||||
let copy = null;
|
let copy = null;
|
||||||
if (!original) {
|
if (!original) {
|
||||||
|
@ -340,8 +338,10 @@ const addRow = (original = null) => {
|
||||||
};
|
};
|
||||||
return { original, copy };
|
return { original, copy };
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTableRows = () =>
|
const getTableRows = () =>
|
||||||
document.getElementsByClassName('q-table')[0].querySelectorAll('tr.cursor-pointer');
|
document.getElementsByClassName('q-table')[0].querySelectorAll('tr.cursor-pointer');
|
||||||
|
|
||||||
function highlightNewRow({ $index: index }) {
|
function highlightNewRow({ $index: index }) {
|
||||||
const row = getTableRows()[index];
|
const row = getTableRows()[index];
|
||||||
if (row) {
|
if (row) {
|
||||||
|
@ -354,10 +354,12 @@ function highlightNewRow({ $index: index }) {
|
||||||
const openEditTableCellDialog = () => {
|
const openEditTableCellDialog = () => {
|
||||||
editTableCellDialogRef.value.show();
|
editTableCellDialogRef.value.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onEditCellDataSaved = async () => {
|
const onEditCellDataSaved = async () => {
|
||||||
rowsSelected.value = [];
|
rowsSelected.value = [];
|
||||||
tableRef.value.reload();
|
tableRef.value.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeFuturePrice = async () => {
|
const removeFuturePrice = async () => {
|
||||||
try {
|
try {
|
||||||
rowsSelected.value.forEach(({ id }) => {
|
rowsSelected.value.forEach(({ id }) => {
|
||||||
|
@ -368,6 +370,7 @@ const removeFuturePrice = async () => {
|
||||||
console.error('Error removing price', err);
|
console.error('Error removing price', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function confirmRemove(item, isFuture) {
|
function confirmRemove(item, isFuture) {
|
||||||
const promise = async () =>
|
const promise = async () =>
|
||||||
isFuture ? removeFuturePrice(item.id) : removePrice(item.id);
|
isFuture ? removeFuturePrice(item.id) : removePrice(item.id);
|
||||||
|
@ -380,6 +383,7 @@ function confirmRemove(item, isFuture) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const removePrice = async (id) => {
|
const removePrice = async (id) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`FixedPrices/${id}`);
|
await axios.delete(`FixedPrices/${id}`);
|
||||||
|
@ -389,6 +393,13 @@ const removePrice = async (id) => {
|
||||||
console.error('Error removing price', err);
|
console.error('Error removing price', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const dateStyle = (date) =>
|
||||||
|
date
|
||||||
|
? {
|
||||||
|
'bg-color': 'warning',
|
||||||
|
'is-outlined': true,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
function handleOnDataSave({ CrudModelRef }) {
|
function handleOnDataSave({ CrudModelRef }) {
|
||||||
const { original, copy } = addRow(CrudModelRef.formData[checkLastVisibleRow()]);
|
const { original, copy } = addRow(CrudModelRef.formData[checkLastVisibleRow()]);
|
||||||
|
@ -566,14 +577,7 @@ function handleOnDataSave({ CrudModelRef }) {
|
||||||
:show-event="true"
|
:show-event="true"
|
||||||
v-model="props.row.started"
|
v-model="props.row.started"
|
||||||
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
||||||
v-bind="
|
v-bind="dateStyle(isBigger(props.row.started))"
|
||||||
isBigger(props.row.started)
|
|
||||||
? {
|
|
||||||
'bg-color': 'warning',
|
|
||||||
'is-outlined': true,
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
|
@ -584,14 +588,7 @@ function handleOnDataSave({ CrudModelRef }) {
|
||||||
:show-event="true"
|
:show-event="true"
|
||||||
v-model="props.row.ended"
|
v-model="props.row.ended"
|
||||||
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
||||||
v-bind="
|
v-bind="dateStyle(isLower(props.row.started))"
|
||||||
isLower(props.row.started)
|
|
||||||
? {
|
|
||||||
'bg-color': 'warning',
|
|
||||||
'is-outlined': true,
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
|
@ -617,7 +614,7 @@ function handleOnDataSave({ CrudModelRef }) {
|
||||||
color="primary"
|
color="primary"
|
||||||
@click.stop="
|
@click.stop="
|
||||||
openConfirmationModal(
|
openConfirmationModal(
|
||||||
t('This row will be removed'),
|
t('globals.rowWillBeRemoved'),
|
||||||
t('Do you want to clone this item?'),
|
t('Do you want to clone this item?'),
|
||||||
() => removePrice(row.id, rowIndex)
|
() => removePrice(row.id, rowIndex)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue