0
0
Fork 0

perf: refs #7404 #7679 improve create

This commit is contained in:
Javier Segarra 2024-10-02 14:58:02 +02:00
parent 90853396ba
commit 40f7ccf42b
2 changed files with 84 additions and 41 deletions

View File

@ -246,7 +246,7 @@ function getChanges() {
for (const [i, row] of formData.value.entries()) {
if (!row[pk]) {
creates.push(row);
} else if (originalData.value) {
} else if (originalData.value[i]) {
const data = getDifferences(originalData.value[i], row);
if (!isEmpty(data)) {
updates.push({

View File

@ -150,6 +150,14 @@ const columns = computed(() => [
icon: 'delete',
action: (row) => confirmRemove(row),
isPrimary: true,
// show: (row) => !validations({ row }),
// },
// {
// title: t('save'),
// icon: 'save',
// action: (row) => upsertFixedPrice(row),
// isPrimary: true,
// show: (row) => validations({ row }),
},
],
},
@ -221,13 +229,41 @@ const updateMinPrice = async (value, props) => {
});
};
const validations = ({ row, rowIndex, col }) => {
const isNew = !row.id;
// Si la row no tiene id significa que fue agregada con addRow y no se ha guardado en la base de datos
// Si isNew es falso no se checkea si el valor es igual a la original
if (!isNew)
// if (fixedPricesOriginalData.value[rowIndex][col.field] == row[col.field])
return false;
const requiredFields = [
'itemFk',
'started',
'ended',
'rate2',
'rate3',
'warehouseFk',
];
const isValid = requiredFields.every(
(field) => row[field] !== null && row[field] !== undefined
);
return isValid;
};
const upsertPrice = async (props, resetMinPrice = false) => {
try {
const { row } = props;
if (tableRef.value.CrudModelRef.getChanges().updates.length > 0) {
if (resetMinPrice) row.hasMinPrice = 0;
await upsertFixedPrice(row);
const isValid = validations({ ...props });
if (!isValid) {
// notify(t('globals.fillRequiredFields'), 'negative');
return;
}
const { row } = props;
const changes = tableRef.value.CrudModelRef.getChanges();
if (changes?.updates?.length > 0) {
if (resetMinPrice) row.hasMinPrice = 0;
}
const data = await upsertFixedPrice(row);
tableRef.value.CrudModelRef.formData[props.rowIndex] = data;
} catch (err) {
console.error('Error editing price', err);
}
@ -264,7 +300,7 @@ function checkLastVisibleRow() {
const addRow = (original = null) => {
let copy = null;
if (!original) {
// if (!original) {
const today = Date.vnNew();
const millisecsInDay = 86400000;
const daysInWeek = 7;
@ -277,26 +313,26 @@ const addRow = (original = null) => {
hasMinPrice: 0,
$index: 0,
};
} else
copy = {
$index: original.$index - 1,
itemFk: original.itemFk,
name: original.name,
subName: original.subName,
value5: original.value5,
value6: original.value6,
value7: original.value7,
value8: original.value8,
value9: original.value9,
value10: original.value10,
warehouseFk: original.warehouseFk,
rate2: original.rate2,
rate3: original.rate3,
hasMinPrice: original.hasMinPrice,
minPrice: original.minPrice,
started: Date.vnNew(),
ended: Date.vnNew(),
};
// } else
// copy = {
// $index: original.$index - 1,
// itemFk: original.itemFk,
// name: original.name,
// subName: original.subName,
// value5: original.value5,
// value6: original.value6,
// value7: original.value7,
// value8: original.value8,
// value9: original.value9,
// value10: original.value10,
// warehouseFk: original.warehouseFk,
// rate2: original.rate2,
// rate3: original.rate3,
// hasMinPrice: original.hasMinPrice,
// minPrice: original.minPrice,
// started: Date.vnNew(),
// ended: Date.vnNew(),
// };
return { original, copy };
};
@ -436,10 +472,6 @@ function handleOnDataSave({ CrudModelRef }) {
auto-load
:is-editable="true"
:right-search="false"
:table="{
'row-key': 'id',
selection: 'multiple',
}"
:crud-model="{
paginate: false,
}"
@ -585,7 +617,18 @@ function handleOnDataSave({ CrudModelRef }) {
</QIcon>
</template>
</VnTable>
<!-- <QPageSticky v-if="rowsSelected" :offset="[20, 80]" style="z-index: 2">
<QBtn
@click="makeInvoice(selectedRows)"
color="primary"
fab
icon="vn:invoice-in"
/>
<QTooltip>
{{ t('ticketList.createInvoice') }}
</QTooltip>
</QPageSticky>-->
<QDialog ref="editTableCellDialogRef">
<EditTableCellValueForm
edit-url="FixedPrices/editFixedPrice"