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

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

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