Commit 9939024c authored by 武广's avatar 武广

fix: 修改属性失效校验

parent 1d2f86f1
...@@ -69,6 +69,7 @@ class goodsManage extends Component { ...@@ -69,6 +69,7 @@ class goodsManage extends Component {
productType: 1, productType: 1,
confirmLoading: false, confirmLoading: false,
afterAddressList: {}, afterAddressList: {},
isAttrLoading: false,
categoryAttrs: [], // 获取类目下属性 categoryAttrs: [], // 获取类目下属性
}; };
...@@ -79,7 +80,10 @@ class goodsManage extends Component { ...@@ -79,7 +80,10 @@ class goodsManage extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.visible && this.state.categoryAttrs.length < 1) { if (nextProps.visible && !this.state.isAttrLoading) {
this.setState({
isAttrLoading: true,
});
const { initData = {} } = this.props; const { initData = {} } = this.props;
const isEdit = Object.keys(initData).length !== 0; const isEdit = Object.keys(initData).length !== 0;
if (isEdit) { if (isEdit) {
...@@ -217,9 +221,7 @@ class goodsManage extends Component { ...@@ -217,9 +221,7 @@ class goodsManage extends Component {
// 获取属性 // 获取属性
getAttribute = async categoryId => { getAttribute = async categoryId => {
console.log('categoryId :>> ', categoryId);
const res = await apiGetAttribute(categoryId); const res = await apiGetAttribute(categoryId);
console.log('res :>> ', res);
let categoryAttrs = []; let categoryAttrs = [];
if (res && res.data && res.data.length) { if (res && res.data && res.data.length) {
categoryAttrs = res.data; categoryAttrs = res.data;
...@@ -231,7 +233,6 @@ class goodsManage extends Component { ...@@ -231,7 +233,6 @@ class goodsManage extends Component {
treeChange = value => { treeChange = value => {
const cid = value[value.length - 1]; const cid = value[value.length - 1];
console.log('cid :>> ', cid);
this.setState({ categoryId: cid, initCascader: value }); this.setState({ categoryId: cid, initCascader: value });
this.getAttribute(cid); this.getAttribute(cid);
}; };
...@@ -425,16 +426,23 @@ class goodsManage extends Component { ...@@ -425,16 +426,23 @@ class goodsManage extends Component {
const key = Object.keys(item)[0]; const key = Object.keys(item)[0];
let attrs = item[key]; let attrs = item[key];
if (Array.isArray(item[key])) { if (Array.isArray(item[key])) {
attrs = item[key].map(attr => { attrs = [];
item[key].forEach(attr => {
try { try {
return JSON.parse(attr); const json = JSON.parse(attr);
if (this.checkInAttrList(json.attributeId)) {
attrs.push(json);
}
} catch { } catch {
return { attributeValueName: attr }; attrs.push({ attributeValueName: attr });
} }
}); });
} else { } else {
try { try {
attrs = [JSON.parse(item[key])]; const json = JSON.parse(item[key]);
if (this.checkInAttrList(json.attributeId)) {
attrs = [json];
}
} catch { } catch {
attrs = [{ attributeValueName: item[key] }]; attrs = [{ attributeValueName: item[key] }];
} }
...@@ -464,7 +472,6 @@ class goodsManage extends Component { ...@@ -464,7 +472,6 @@ class goodsManage extends Component {
attributeApplyList, attributeApplyList,
}, },
})); }));
console.log('this.state.createData :>> ', this.state.createData);
const data = initData.id const data = initData.id
? await editGoods(this.state.createData) ? await editGoods(this.state.createData)
: await addGoods(this.state.createData); : await addGoods(this.state.createData);
...@@ -547,13 +554,16 @@ class goodsManage extends Component { ...@@ -547,13 +554,16 @@ class goodsManage extends Component {
return 'default'; return 'default';
}; };
// 验证是否失效属性(已失效的商品不显示)
checkInAttrList = id =>
this.state.categoryAttrs.some(item => item.valueList.some(v => +v.id === +id));
getInitAttrValue = (id, supportCustomValue, optionType) => { getInitAttrValue = (id, supportCustomValue, optionType) => {
console.log('id :>> ', id, supportCustomValue.code, optionType.code);
const skuAttr = this.props.initData.productAttributeApplyList?.productAttributeApplyList || []; const skuAttr = this.props.initData.productAttributeApplyList?.productAttributeApplyList || [];
const v = skuAttr.filter(item => id === item.productAttributeId); const v = skuAttr.filter(item => id === item.productAttributeId);
if (v.length) { if (v.length) {
const values = v[0].productAttributeApplyValueList.map(attr => { const values = v[0].productAttributeApplyValueList.map(attr => {
if (+attr.attributeValueId) { if (+attr.attributeValueId && this.checkInAttrList(attr.attributeValueId)) {
return JSON.stringify({ return JSON.stringify({
attributeValueId: attr.attributeValueId, attributeValueId: attr.attributeValueId,
attributeValueName: attr.attributeValueName, attributeValueName: attr.attributeValueName,
...@@ -579,7 +589,6 @@ class goodsManage extends Component { ...@@ -579,7 +589,6 @@ class goodsManage extends Component {
if (+optionType.code === 2) { if (+optionType.code === 2) {
return []; return [];
} }
console.log('111 :>> ', 111);
return ''; return '';
}; };
...@@ -883,14 +892,27 @@ class goodsManage extends Component { ...@@ -883,14 +892,27 @@ class goodsManage extends Component {
</Col> </Col>
))} ))}
</Row> </Row>
<Row> {skuOldAttr.length > 0 && (
{skuOldAttr.length > 0 && <div>
skuOldAttr.map(s => ( <Row>注:以下商品属性已失效,请使用新的属性</Row>
<FormItem label={s.productAttributeName} required={false} key={s.id}> <Row>
{s.value} {skuOldAttr.map(s => (
</FormItem> <Col span={12} key={s.id}>
))} <FormItem
</Row> label={s.productAttributeName}
{...formItemAttr}
required={false}
key={s.id}
>
{s.productAttributeApplyValueList
.map(item => item.attributeValueName)
.join('')}
</FormItem>
</Col>
))}
</Row>
</div>
)}
</Card> </Card>
<Card className={styles.card} bordered={false}> <Card className={styles.card} bordered={false}>
......
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