Commit 2451c572 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix:处理新增商品仅填写某些选项卡后点击保存的错误提示

parent aa850a8d
...@@ -154,12 +154,11 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -154,12 +154,11 @@ const AddProducts: React.FC<{}> = (props) => {
_itme.customerAttribute = { id: _itme.customerAttributeId } _itme.customerAttribute = { id: _itme.customerAttributeId }
delete _itme.attributeName delete _itme.attributeName
delete _itme.isPrice delete _itme.isPrice
// delete _itme.customerAttributeId
}) })
let _bacsicForm = { ...values[0] } let _bacsicForm = { ...values[0] }
if (values.length > 0) { if (values.length > 0) {
for (let i = 0; i < values.length; i++) { for (let i = 0; i < values.length; i++) {
// 过滤出物流form // 过滤出物流表单
if (values[i].deliveryType) { if (values[i].deliveryType) {
_bacsicForm = { ..._bacsicForm, logistics: { ...values[i] } } _bacsicForm = { ..._bacsicForm, logistics: { ...values[i] } }
} else { } else {
...@@ -168,7 +167,7 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -168,7 +167,7 @@ const AddProducts: React.FC<{}> = (props) => {
} }
} }
_bacsicForm.customerCategoryId = _bacsicForm.customerCategoryId[_bacsicForm.customerCategoryId.length - 1] _bacsicForm.customerCategoryId = _bacsicForm.customerCategoryId[_bacsicForm.customerCategoryId.length - 1]
// 移除描述中的[] // 移除描述中的空数组[]
let _productDescription = { ...productDescription } let _productDescription = { ...productDescription }
for(let i in _productDescription){ for(let i in _productDescription){
if(_productDescription[i]?.length === 0){ if(_productDescription[i]?.length === 0){
...@@ -245,25 +244,24 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -245,25 +244,24 @@ const AddProducts: React.FC<{}> = (props) => {
return e return e
} }
_params.unitPriceAndPicList = _productAttributeAndImageParams _params.unitPriceAndPicList = _productAttributeAndImageParams
} else { // 编辑 没有点击商品图片 } else { // 编辑时没有点击商品图片(新增没有点击也就没有数据)
if(productInfoByEdit){
_params.unitPriceAndPicList = productInfoByEdit.unitPriceAndPicList _params.unitPriceAndPicList = productInfoByEdit.unitPriceAndPicList
if (clickTabIndex.indexOf("4") !== -1) { // 没有点击图片单单修改了商品价格 取原有的图片和新的价格合成 // 没有点击图片单单修改了商品价格 取原有的图片和新的价格合成
if (clickTabIndex.indexOf("4") !== -1) {
_params.unitPriceAndPicList = priceAttributeParams.map((item, index) => { _params.unitPriceAndPicList = priceAttributeParams.map((item, index) => {
return { return {
goods: { id: item.goodsId }, goods: { id: item.goodsId },
attributeAndValueList: item.attributeAndValueList, attributeAndValueList: item.attributeAndValueList,
// .map(_item => {
// return {
// customerAttribute: { id: _item.customerAttributeId },
// customerAttributeValue: { id: _item.id, value: _item.value }
// }
// }),
unitPrice: item.unitPrice, unitPrice: item.unitPrice,
commodityPic: productInfoByEdit.unitPriceAndPicList[index].commodityPic commodityPic: productInfoByEdit.unitPriceAndPicList[index].commodityPic
} }
}) })
} }
} }
}
if(productInfoByEdit){ //(新增没有点击也就没有数据)
if (clickTabIndex.indexOf("3") === -1) // 商品属性 if (clickTabIndex.indexOf("3") === -1) // 商品属性
_params.commodityAttributeList = productInfoByEdit.commodityAttributeList _params.commodityAttributeList = productInfoByEdit.commodityAttributeList
if (clickTabIndex.indexOf("4") === -1) { // 价格属性 if (clickTabIndex.indexOf("4") === -1) { // 价格属性
...@@ -283,16 +281,30 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -283,16 +281,30 @@ const AddProducts: React.FC<{}> = (props) => {
_params.packing = productInfoByEdit.packing _params.packing = productInfoByEdit.packing
_params.afterService = productInfoByEdit.afterService _params.afterService = productInfoByEdit.afterService
} }
}
// 校验属性单位重量是否提供发票
try {
if(!_params.commodityAttributeList.length && !_params?.unitId && typeof(_params.isInvoice) !== 'boolean' && !_params?.logistics?.weight){
throw new Error('请完善商品其他信息!')
}
} catch (e) {
return e
}
// 校验价格 // 校验价格
try { try {
if(_params.unitPriceAndPicList){
let hasPriceArray = _params.unitPriceAndPicList.map(item => item.unitPrice) let hasPriceArray = _params.unitPriceAndPicList.map(item => item.unitPrice)
hasPriceArray.map(item => { hasPriceArray.map(item => {
if (JSON.stringify(item) === '{}' && _params.priceType !== 2) // 除价格需要询问类型 其他都需要校验价格或积分 if (JSON.stringify(item) === '{}' && _params.priceType !== 2) // 除价格需要询问类型 其他都需要校验价格或积分
throw new Error(_params.priceType === 1 ? '商品价格为必填项!' : '商品积分为必填项!') throw new Error(_params.priceType === 1 ? '商品价格为必填项!' : '商品积分为必填项!')
}) })
}
} catch (e) { } catch (e) {
return e return e
} }
// 移除混入的id数字类的键值项 // 移除混入的id数字类的键值项
let numberKeys = Object.keys(_params).map(_ => Number(_)).filter(Boolean) let numberKeys = Object.keys(_params).map(_ => Number(_)).filter(Boolean)
if (numberKeys.length > 0) if (numberKeys.length > 0)
...@@ -310,20 +322,20 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -310,20 +322,20 @@ const AddProducts: React.FC<{}> = (props) => {
}).then(e => { }).then(e => {
if (e) { if (e) {
setIsDisableSaveBtn(false) setIsDisableSaveBtn(false)
message.error(e.message) message.error(e.message || '请完善商品其他信息!')
} }
console.log(e, 'e') console.log(e, 'e')
}).catch(error => { }).catch(error => {
console.log(error, '_error') console.log(error, '_error')
setIsDisableSaveBtn(false) setIsDisableSaveBtn(false)
if (error.messge) if (error.messge)
message.error(error.message) message.error(error.message || '请完善商品其他信息!')
else else
message.error(error.errorFields[0].errors.toString()) message.error(error.errorFields[0].errors.toString())
}) })
} catch (e) { } catch (e) {
setIsDisableSaveBtn(false) setIsDisableSaveBtn(false)
message.error(e.message) message.error(e.message || '请完善商品其他信息!')
console.log(e, 'error') console.log(e, 'error')
} }
......
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