Commit f61bb2a3 authored by 武广's avatar 武广

fix: 优化属性

parent 1c90ec04
......@@ -387,6 +387,18 @@ class goodsManage extends Component {
});
};
deal = attr => {
try {
const json = JSON.parse(attr);
if (typeof json === 'object' && this.checkInAttrList(json.attributeValueId)) {
return json;
}
return { attributeValueName: json };
} catch {
return { attributeValueName: attr };
}
};
// 最终提交
confirm = async isContinue => {
const {
......@@ -430,6 +442,7 @@ class goodsManage extends Component {
});
const attributeApplyList = [];
let isMaxLength = false;
if (values.attributeApplyList && values.attributeApplyList.length) {
values.attributeApplyList.forEach(item => {
const key = Object.keys(item)[0];
......@@ -437,44 +450,22 @@ class goodsManage extends Component {
if (Array.isArray(item[key])) {
attrs = [];
item[key].forEach(attr => {
try {
const json = JSON.parse(attr);
if (typeof json === 'object') {
if (this.checkInAttrList(json.attributeValueId)) {
attrs.push(json);
}
} else {
if (`${json}` && `${json}`.length > 30) {
isMaxLength = true;
}
attrs.push({ attributeValueName: json });
}
} catch {
if (attr && attr.length > 30) {
isMaxLength = true;
}
attrs.push({ attributeValueName: attr });
const json = this.deal(attr);
if (!json) {
return;
}
// eslint-disable-next-line no-unused-expressions
json.attributeValueName.length > 30 && (isMaxLength = true);
attrs.push(json);
});
} else {
try {
const json = JSON.parse(item[key]);
if (typeof json === 'object') {
if (this.checkInAttrList(json.attributeValueId)) {
attrs = [json];
}
} else {
if (`${json}` && `${json}`.length > 30) {
isMaxLength = true;
}
attrs.push({ attributeValueName: json });
}
} catch {
if (item[key] && item[key].length > 30) {
isMaxLength = true;
}
attrs = [{ attributeValueName: item[key] }];
const json = this.deal(item[key]);
if (!json) {
return;
}
// eslint-disable-next-line no-unused-expressions
json.attributeValueName.length > 30 && (isMaxLength = true);
attrs = [json];
}
attributeApplyList.push({
attributeId: key.replace('attr', ''),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment