if (type === 'p') {
this.selectedOptions[type] = {
count: optionCount,
name: optionName,
info: optionChars,
price: optionPrice
};
}
if (type === 'c') {
this.selectedOptions[type] = {
count: optionCount,
name: optionName,
info: optionChars,
price: optionPrice
};
}
if (type === 'm') {
this.selectedOptions[type] = {
value: optionValue,
price: optionPrice
};
}
if (type === 'disk') {
this.selectedOptions[type+t.diskNumber] = {
count: optionCount,
name: optionName,
price: optionPrice
};
}
if (type === 'radio') {
this.selectedOptions[type] = {
name: optionName,
price: optionPrice
};
}
if (type === 'button') {
this.selectedOptions[type] = {
value: optionValue,
price: optionPrice
};
}
if (type === 'checkbox') {
var c = `check${data.checkId}`;
this.selectedOptions[type][c] = {
name: optionName,
price: optionPrice
};
}
const opts = this.selectedOptions;
const data = {
count: optionCount || 0, // значения по умолчанию
name : optionName || '',
info : optionChars || '',
price: optionPrice || '',
value: optionValue || '',
}
switch (type) {
case 'p':
case 'c':
case 'm':
case 'radio':
case 'button':
opts[type] = data;
break;
case 'disk':
opts[type + t.diskNumber] = data;
break;
case 'checkbox':
opts[type][`check${data.checkId}`] = data;
}
const types = {
p: ['count', 'name', 'info', 'price'],
c: ['count', 'name', 'info', 'price'],
m: ['value', 'price'],
disk: ['count', 'name', 'price'],
radio: ['name', 'price'],
button: ['value', 'price'],
checkbox: ['name', 'price']
};
const values = {
name: optionName,
price: optionPrice,
value: optionValue,
count: optionCount,
info: optionChars
};
const result = types[type].reduce((acc, curr) => ({...acc, [curr]: values[curr]}), {});
if (type === 'checkbox') {
this.selectedOptions[type][`check${data.checkId}`] = result;
} else {
this.selectedOptions[type === 'disk' ? type + t.diskNumber : type] = result;
}