Abstract repetitive returns in a function
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
William Buezas 2024-02-05 09:31:12 -03:00
parent 5280a4fa2d
commit 2de02723ba
1 changed files with 37 additions and 52 deletions

View File

@ -27,28 +27,24 @@ const rowsSelected = ref([]);
const entryBuysPaginateRef = ref(null); const entryBuysPaginateRef = ref(null);
const packagingsOptions = ref(null); const packagingsOptions = ref(null);
const originalRowDataCopy = ref(null); const originalRowDataCopy = ref(null);
const tableColumnComponents = {
const tableColumnComponents = computed(() => ({
item: { item: {
component: () => 'span', component: 'span',
props: () => {}, props: () => {},
event: () => ({}), event: () => ({}),
}, },
quantity: { quantity: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
class: 'input-number', class: 'input-number',
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
packagingFk: { packagingFk: {
component: () => VnSelectFilter, component: VnSelectFilter,
props: () => ({ props: () => ({
'option-value': 'id', 'option-value': 'id',
'option-label': 'id', 'option-label': 'id',
@ -58,101 +54,78 @@ const tableColumnComponents = computed(() => ({
'hide-selected': true, 'hide-selected': true,
options: packagingsOptions.value, options: packagingsOptions.value,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'update:modelValue': () => saveChange(colField, props),
}),
}, },
stickers: { stickers: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
class: 'input-number', class: 'input-number',
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
weight: { weight: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
packing: { packing: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
grouping: { grouping: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
buyingValue: { buyingValue: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
price2: { price2: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
price3: { price3: {
component: () => VnInput, component: VnInput,
props: (col) => ({ props: (col) => ({
type: 'number', type: 'number',
min: 0, min: 0,
label: col.label, label: col.label,
}), }),
event: (colField, props) => ({ event: (colField, props) => getInputEvents(colField, props),
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
}),
}, },
import: { import: {
component: () => 'span', component: 'span',
props: () => {}, props: () => {},
event: () => ({}), event: () => ({}),
}, },
})); };
const entriesTableColumns = computed(() => { const entriesTableColumns = computed(() => {
return [ return [
@ -231,6 +204,15 @@ const copyOriginalRowsData = (rows) => {
originalRowDataCopy.value = JSON.parse(JSON.stringify(rows)); originalRowDataCopy.value = JSON.parse(JSON.stringify(rows));
}; };
const getInputEvents = (colField, props) => {
return colField === 'packagingFk'
? { 'update:modelValue': () => saveChange(colField, props) }
: {
'keyup.enter': () => saveChange(colField, props),
blur: () => saveChange(colField, props),
};
};
const saveChange = async (field, { rowIndex, row }) => { const saveChange = async (field, { rowIndex, row }) => {
try { try {
if (originalRowDataCopy.value[rowIndex][field] == row[field]) return; if (originalRowDataCopy.value[rowIndex][field] == row[field]) return;
@ -352,7 +334,7 @@ const showLockIcon = (groupingMode, mode) => {
</QTd> </QTd>
<QTd v-for="col in props.cols" :key="col.name"> <QTd v-for="col in props.cols" :key="col.name">
<component <component
:is="tableColumnComponents[col.name].component()" :is="tableColumnComponents[col.name].component"
v-bind="tableColumnComponents[col.name].props(col)" v-bind="tableColumnComponents[col.name].props(col)"
v-model="props.row[col.field]" v-model="props.row[col.field]"
v-on=" v-on="
@ -426,13 +408,16 @@ const showLockIcon = (groupingMode, mode) => {
<QList dense> <QList dense>
<QItem v-for="col in props.cols" :key="col.name"> <QItem v-for="col in props.cols" :key="col.name">
<component <component
:is="tableColumnComponents[col.name].component()" :is="tableColumnComponents[col.name].component"
v-bind=" v-bind="
tableColumnComponents[col.name].props(col) tableColumnComponents[col.name].props(col)
" "
v-model="props.row[col.field]" v-model="props.row[col.field]"
v-on=" v-on="
tableColumnComponents[col.name].event(props) tableColumnComponents[col.name].event(
col.field,
props
)
" "
class="full-width" class="full-width"
> >