Commit 1f43df86 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix: 处理新增商品提交异常、处理新增商品再次变动价格图片清空问题

parent b0ba0430
......@@ -195,6 +195,8 @@ const BasicInfoForm: React.FC<Iprops> = (props) => {
})
callback()
}
}else{
callback()
}
} catch (err) {
callback(err)
......@@ -323,8 +325,8 @@ const BasicInfoForm: React.FC<Iprops> = (props) => {
<Select
mode="tags"
placeholder="请输入并选择商品卖点"
// maxTagCount={3}
// maxTagTextLength={8}
maxTagCount={3}
maxTagTextLength={8}
tagRender={tagRender}
/>
</Form.Item>
......
......@@ -20,6 +20,8 @@ const ProductImageForm: React.FC<{}> = (props) => {
const [previewImage, setPreviewImage] = useState('')
const [previewTitle, setPreviewTitle] = useState('')
const [setImageType, setSetImageType] = useState<boolean>(true)
// 处理新增二次变更价格保留图片数据
const [maintainImageData, setMaintainImageData] = useState<any>([])
const [openFileDialogFlag, setOpenFileDialogFlag] = useState<boolean>(false)
const flagRef = useRef<boolean>(false)
......@@ -60,10 +62,8 @@ const ProductImageForm: React.FC<{}> = (props) => {
useEffect(()=>{
if(priceAttributeParams.length > 0){
// console.log(priceAttributeParams, '对比')
constructImageListByRender(priceAttributeParams)
}else if(history.location.query?.id){ // 不点击前面 直接进入图片tab
// console.log(productInfoByEdit.unitPriceAndPicList, '对比')
constructImageListByRender(productInfoByEdit.unitPriceAndPicList)
}
},[priceAttributeParams])
......@@ -78,7 +78,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
_priceAttributeParams = priceAttributeParams.map((_item, _index) => {
// 为图片字符串数组手动添加 uid 和 status
// console.log(_item, '_____')
// 查询编辑详情中属性值id相匹配的图片
let _pic = null
let _priceAndPicList = productInfoByEdit.unitPriceAndPicList
......@@ -100,9 +99,11 @@ const ProductImageForm: React.FC<{}> = (props) => {
return _obj
})
}else{
_priceAttributeParams = priceAttributeParams.map(_item=>{
_priceAttributeParams = priceAttributeParams.map((_item, _i) => {
let _obj = {..._item}
_obj.commodityPic = []
// ****这里 新增情况下 价格属性参数变动引起constructImageListByRender数据构建 []会清空之前已经上传的图片
// _obj.commodityPic = []
_obj.commodityPic = maintainImageData[_i] || []
return _obj
})
}
......@@ -110,7 +111,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
clickItemTab(0)
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
// console.log(_priceAttributeParams, priceAttributeParams, '_p')
// 初始化若是按所有属性共用做显示处理
if(setImageType && _priceAttributeParams.length>0){
setCommonImageList(_priceAttributeParams[0].commodityPic)
......@@ -118,7 +118,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
}
const clickItemTab = (_index: number) => {
// console.log(_index, '点击项')
setDefaultChecked(_index)
}
......@@ -184,14 +183,12 @@ const ProductImageForm: React.FC<{}> = (props) => {
const handleChange = ({ file, fileList }, index) => {
let _priceAttributeParams = [...priceAttributeParamsByRender]
// console.log(fileList, file, index, editRowIndexRef, '响应')
// console.log(uploadFileSelectRef.current)
const selectUuid = uploadFileSelectRef.current.uid
if (selectUuid) {
// 点了图片编辑
const editPicIndex = fileList.findIndex(v => v.uid === selectUuid)
// console.log(editPicIndex)
fileList.splice(editPicIndex, 1, file)
if (fileList.length > 1) {
fileList.pop()
......@@ -200,7 +197,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
}
setCommonImageList(fileList)
// console.log(index||editRowIndexRef.current, fileList, '132456')
_priceAttributeParams[index||editRowIndexRef.current].commodityPic = fileList
if(!file?.status && file?.status !== 'done'){
let ttt = _priceAttributeParams[index||editRowIndexRef.current].commodityPic.filter(_ => _.status === 'done')
......@@ -209,6 +205,8 @@ const ProductImageForm: React.FC<{}> = (props) => {
}
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
// 保留上传的数据在页面状态 用于处理前面价格变动后不重新更新图片数据
setMaintainImageData(_priceAttributeParams.map(item => item.commodityPic))
}
const onChangeSetImageType = (e) => {
......@@ -226,7 +224,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
}
const handlefileEdit = (file, index) => {
// console.log(file, index)
const uploadEle = document.querySelector(`#uploadEle${index}`) as any
uploadFileSelectRef.current = (file)
editRowIndexRef.current = index
......
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