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,54 +244,67 @@ const AddProducts: React.FC<{}> = (props) => { ...@@ -245,54 +244,67 @@ const AddProducts: React.FC<{}> = (props) => {
return e return e
} }
_params.unitPriceAndPicList = _productAttributeAndImageParams _params.unitPriceAndPicList = _productAttributeAndImageParams
} else { // 编辑 没有点击商品图片 } else { // 编辑时没有点击商品图片(新增没有点击也就没有数据)
_params.unitPriceAndPicList = productInfoByEdit.unitPriceAndPicList if(productInfoByEdit){
if (clickTabIndex.indexOf("4") !== -1) { // 没有点击图片单单修改了商品价格 取原有的图片和新的价格合成 _params.unitPriceAndPicList = productInfoByEdit.unitPriceAndPicList
_params.unitPriceAndPicList = priceAttributeParams.map((item, index) => { // 没有点击图片单单修改了商品价格 取原有的图片和新的价格合成
return { if (clickTabIndex.indexOf("4") !== -1) {
goods: { id: item.goodsId }, _params.unitPriceAndPicList = priceAttributeParams.map((item, index) => {
attributeAndValueList: item.attributeAndValueList, return {
// .map(_item => { goods: { id: item.goodsId },
// return { attributeAndValueList: item.attributeAndValueList,
// customerAttribute: { id: _item.customerAttributeId }, unitPrice: item.unitPrice,
// customerAttributeValue: { id: _item.id, value: _item.value } commodityPic: productInfoByEdit.unitPriceAndPicList[index].commodityPic
// } }
// }), })
unitPrice: item.unitPrice, }
commodityPic: productInfoByEdit.unitPriceAndPicList[index].commodityPic
}
})
} }
} }
if (clickTabIndex.indexOf("3") === -1) // 商品属性
_params.commodityAttributeList = productInfoByEdit.commodityAttributeList if(productInfoByEdit){ //(新增没有点击也就没有数据)
if (clickTabIndex.indexOf("4") === -1) { // 价格属性 if (clickTabIndex.indexOf("3") === -1) // 商品属性
_params.unitId = productInfoByEdit.unitId _params.commodityAttributeList = productInfoByEdit.commodityAttributeList
_params.unitName = productInfoByEdit.unitName if (clickTabIndex.indexOf("4") === -1) { // 价格属性
_params.minOrder = productInfoByEdit.minOrder _params.unitId = productInfoByEdit.unitId
_params.priceType = productInfoByEdit.priceType _params.unitName = productInfoByEdit.unitName
_params.isMemberPrice = productInfoByEdit.isMemberPrice _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) // 物流 try {
_params.logistics = productInfoByEdit.logistics if(!_params.commodityAttributeList.length && !_params?.unitId && typeof(_params.isInvoice) !== 'boolean' && !_params?.logistics?.weight){
if (clickTabIndex.indexOf("8") === -1) { // 其他 throw new Error('请完善商品其他信息!')
_params.isInvoice = productInfoByEdit.isInvoice }
_params.marks = productInfoByEdit.marks } catch (e) {
_params.packing = productInfoByEdit.packing return e
_params.afterService = productInfoByEdit.afterService
} }
// 校验价格 // 校验价格
try { try {
let hasPriceArray = _params.unitPriceAndPicList.map(item => item.unitPrice) if(_params.unitPriceAndPicList){
hasPriceArray.map(item => { let hasPriceArray = _params.unitPriceAndPicList.map(item => item.unitPrice)
if (JSON.stringify(item) === '{}' && _params.priceType !== 2) // 除价格需要询问类型 其他都需要校验价格或积分 hasPriceArray.map(item => {
throw new Error(_params.priceType === 1 ? '商品价格为必填项!' : '商品积分为必填项!') if (JSON.stringify(item) === '{}' && _params.priceType !== 2) // 除价格需要询问类型 其他都需要校验价格或积分
}) 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