Commit 438c5643 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix:新建商品无属性无货品下异常

parent 43a1de49
...@@ -31,6 +31,7 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -31,6 +31,7 @@ const AddProducts: React.FC<{}> = (props) => {
const { ProductStore } = store const { ProductStore } = store
const { const {
productSelectAttribute, productSelectAttribute,
priceAttributeParams,
productAttributeAndImageParams, productAttributeAndImageParams,
areaOption, areaOption,
productDescription, productDescription,
...@@ -131,9 +132,9 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -131,9 +132,9 @@ const AddProducts: React.FC<{}> = (props) => {
if(productAttributeAndImageParams.length>0){ if(productAttributeAndImageParams.length>0){
productAttributeAndImageParams.map(_item => { productAttributeAndImageParams.map(_item => {
console.log(_item, '_item') console.log(_item, '_item')
if(_item.attributeAndValueList.length>0){ _item.goods = { id: _item.goodsId } // id为0表示无货品
_item.goods = { id: _item.goodsId }
delete _item.goodsId delete _item.goodsId
if(_item.attributeAndValueList.length>0){
_item.attributeAndValueList.map(__item => { _item.attributeAndValueList.map(__item => {
delete __item.customerAttributeName delete __item.customerAttributeName
// **** 新字段结构变更 // **** 新字段结构变更
...@@ -154,8 +155,7 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -154,8 +155,7 @@ const AddProducts: React.FC<{}> = (props) => {
throw new Error('每项请至少上传一张商品图片!') throw new Error('每项请至少上传一张商品图片!')
} }
}) })
} }else{
else{
throw new Error('每项请至少上传一张商品图片!') throw new Error('每项请至少上传一张商品图片!')
} }
}catch(e){ }catch(e){
......
...@@ -197,10 +197,12 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -197,10 +197,12 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
</> </>
}) })
}else if(history.location.query?.id){ // 此时没有货品并且处于编辑状态 取接口返回的数据 }else if(history.location.query?.id){ // 此时没有货品并且处于编辑状态 取接口返回的数据
let goodsInApi: any = Object.values(productInfoByEdit.unitPriceAndPicList.map(_ => _.goods).reduce((item, next)=>{ let _goods: any[] = Object.values(productInfoByEdit.unitPriceAndPicList.map(_ => _.goods))
if(_goods.indexOf(null)===-1){
let goodsInApi : any = _goods.reduce((item, next)=>{
item[next.id] = next item[next.id] = next
return item return item
},{})) },{})
_col.push({ _col.push({
title: '对应货品', title: '对应货品',
...@@ -218,6 +220,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -218,6 +220,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
</> </>
}) })
} }
}
if(_attributeNameArr.length>0){ if(_attributeNameArr.length>0){
_attributeNameArr.map( _attr => { _attributeNameArr.map( _attr => {
......
...@@ -41,6 +41,7 @@ const SelectGoodsForm: React.FC<Iprops> = (props) => { ...@@ -41,6 +41,7 @@ const SelectGoodsForm: React.FC<Iprops> = (props) => {
item[next.id] = next; item[next.id] = next;
return item return item
},{})) },{}))
console.log(goodsArr, 'goods')
if(goodsArr.length>0){ if(goodsArr.length>0){
setIsChecked(true) setIsChecked(true)
setIsSelectGoods(true) setIsSelectGoods(true)
......
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