Commit f61bb2a3 authored by 武广's avatar 武广

fix: 优化属性

parent 1c90ec04
...@@ -387,6 +387,18 @@ class goodsManage extends Component { ...@@ -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 => { confirm = async isContinue => {
const { const {
...@@ -430,6 +442,7 @@ class goodsManage extends Component { ...@@ -430,6 +442,7 @@ class goodsManage extends Component {
}); });
const attributeApplyList = []; const attributeApplyList = [];
let isMaxLength = false; let isMaxLength = false;
if (values.attributeApplyList && values.attributeApplyList.length) { if (values.attributeApplyList && values.attributeApplyList.length) {
values.attributeApplyList.forEach(item => { values.attributeApplyList.forEach(item => {
const key = Object.keys(item)[0]; const key = Object.keys(item)[0];
...@@ -437,44 +450,22 @@ class goodsManage extends Component { ...@@ -437,44 +450,22 @@ class goodsManage extends Component {
if (Array.isArray(item[key])) { if (Array.isArray(item[key])) {
attrs = []; attrs = [];
item[key].forEach(attr => { item[key].forEach(attr => {
try { const json = this.deal(attr);
const json = JSON.parse(attr); if (!json) {
if (typeof json === 'object') { return;
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 });
} }
// eslint-disable-next-line no-unused-expressions
json.attributeValueName.length > 30 && (isMaxLength = true);
attrs.push(json);
}); });
} else { } else {
try { const json = this.deal(item[key]);
const json = JSON.parse(item[key]); if (!json) {
if (typeof json === 'object') { return;
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] }];
} }
// eslint-disable-next-line no-unused-expressions
json.attributeValueName.length > 30 && (isMaxLength = true);
attrs = [json];
} }
attributeApplyList.push({ attributeApplyList.push({
attributeId: key.replace('attr', ''), 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