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')
_item.goods = { id: _item.goodsId } // id为0表示无货品
delete _item.goodsId
if(_item.attributeAndValueList.length>0){ if(_item.attributeAndValueList.length>0){
_item.goods = { id: _item.goodsId }
delete _item.goodsId
_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,26 +197,29 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -197,26 +197,29 @@ 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))
item[next.id] = next if(_goods.indexOf(null)===-1){
return item let goodsInApi : any = _goods.reduce((item, next)=>{
},{})) item[next.id] = next
return item
_col.push({ },{})
title: '对应货品',
dataIndex: '对应货品', _col.push({
key: '对应货品', title: '对应货品',
width: 360, dataIndex: '对应货品',
render: (text: any, record: any) => <> key: '对应货品',
<Select style={{width:'100%'}} defaultValue={text} onChange={(v)=> {tableSelelctChange(v, record) }}> width: 360,
{ render: (text: any, record: any) => <>
goodsInApi.length>0 && goodsInApi.map(_item => ( <Select style={{width:'100%'}} defaultValue={text} onChange={(v)=> {tableSelelctChange(v, record) }}>
<Option key={_item.id} value={_item.id}>{_item.code}/{_item.name}/{_item.type}/¥{_item.costPrice}</Option> {
)) goodsInApi.length>0 && goodsInApi.map(_item => (
} <Option key={_item.id} value={_item.id}>{_item.code}/{_item.name}/{_item.type}/¥{_item.costPrice}</Option>
</Select> ))
</> }
}) </Select>
</>
})
}
} }
if(_attributeNameArr.length>0){ if(_attributeNameArr.length>0){
......
...@@ -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