forked from verdnatura/salix-front
Abstract repetitive returns in a function
This commit is contained in:
parent
5280a4fa2d
commit
2de02723ba
|
@ -27,28 +27,24 @@ const rowsSelected = ref([]);
|
|||
const entryBuysPaginateRef = ref(null);
|
||||
const packagingsOptions = ref(null);
|
||||
const originalRowDataCopy = ref(null);
|
||||
|
||||
const tableColumnComponents = computed(() => ({
|
||||
const tableColumnComponents = {
|
||||
item: {
|
||||
component: () => 'span',
|
||||
component: 'span',
|
||||
props: () => {},
|
||||
event: () => ({}),
|
||||
},
|
||||
quantity: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
class: 'input-number',
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
packagingFk: {
|
||||
component: () => VnSelectFilter,
|
||||
component: VnSelectFilter,
|
||||
props: () => ({
|
||||
'option-value': 'id',
|
||||
'option-label': 'id',
|
||||
|
@ -58,101 +54,78 @@ const tableColumnComponents = computed(() => ({
|
|||
'hide-selected': true,
|
||||
options: packagingsOptions.value,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'update:modelValue': () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
stickers: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
class: 'input-number',
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
weight: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
packing: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
grouping: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
buyingValue: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
price2: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
price3: {
|
||||
component: () => VnInput,
|
||||
component: VnInput,
|
||||
props: (col) => ({
|
||||
type: 'number',
|
||||
min: 0,
|
||||
label: col.label,
|
||||
}),
|
||||
event: (colField, props) => ({
|
||||
'keyup.enter': () => saveChange(colField, props),
|
||||
blur: () => saveChange(colField, props),
|
||||
}),
|
||||
event: (colField, props) => getInputEvents(colField, props),
|
||||
},
|
||||
import: {
|
||||
component: () => 'span',
|
||||
component: 'span',
|
||||
props: () => {},
|
||||
event: () => ({}),
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const entriesTableColumns = computed(() => {
|
||||
return [
|
||||
|
@ -231,6 +204,15 @@ const copyOriginalRowsData = (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 }) => {
|
||||
try {
|
||||
if (originalRowDataCopy.value[rowIndex][field] == row[field]) return;
|
||||
|
@ -352,7 +334,7 @@ const showLockIcon = (groupingMode, mode) => {
|
|||
</QTd>
|
||||
<QTd v-for="col in props.cols" :key="col.name">
|
||||
<component
|
||||
:is="tableColumnComponents[col.name].component()"
|
||||
:is="tableColumnComponents[col.name].component"
|
||||
v-bind="tableColumnComponents[col.name].props(col)"
|
||||
v-model="props.row[col.field]"
|
||||
v-on="
|
||||
|
@ -426,13 +408,16 @@ const showLockIcon = (groupingMode, mode) => {
|
|||
<QList dense>
|
||||
<QItem v-for="col in props.cols" :key="col.name">
|
||||
<component
|
||||
:is="tableColumnComponents[col.name].component()"
|
||||
:is="tableColumnComponents[col.name].component"
|
||||
v-bind="
|
||||
tableColumnComponents[col.name].props(col)
|
||||
"
|
||||
v-model="props.row[col.field]"
|
||||
v-on="
|
||||
tableColumnComponents[col.name].event(props)
|
||||
tableColumnComponents[col.name].event(
|
||||
col.field,
|
||||
props
|
||||
)
|
||||
"
|
||||
class="full-width"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue