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

fix: 处理新增商品直接点图片上传页面异常问题

parent cae4295a
...@@ -13,7 +13,7 @@ import { inject, observer } from 'mobx-react' ...@@ -13,7 +13,7 @@ import { inject, observer } from 'mobx-react'
import { store } from '@/store' import { store } from '@/store'
const ProductImageForm: React.FC<{}> = (props) => { const ProductImageForm: React.FC<{}> = (props) => {
const [defaultChecked, setDefaultChecked] = useState(-1) const [defaultChecked, setDefaultChecked] = useState(-1)
const [priceAttributeParamsByRender, setPriceAttributeParamsByRender] = useState<any[]>([]) const [priceAttributeParamsByRender, setPriceAttributeParamsByRender] = useState<any[]>([])
const [commonImageList, setCommonImageList] = useState<any>([]) const [commonImageList, setCommonImageList] = useState<any>([])
const [previewVisible, setPreviewVisible] = useState(false) const [previewVisible, setPreviewVisible] = useState(false)
...@@ -30,13 +30,13 @@ const ProductImageForm: React.FC<{}> = (props) => { ...@@ -30,13 +30,13 @@ const ProductImageForm: React.FC<{}> = (props) => {
const editRowIndexRef = useRef<number>(0) const editRowIndexRef = useRef<number>(0)
const { ProductStore } = store const { ProductStore } = store
const { const {
priceAttributeParams, priceAttributeParams,
productInfoByEdit, productInfoByEdit,
setProductAttributeAndImageParams, setProductAttributeAndImageParams,
setIsAllAttributePic, setIsAllAttributePic,
selectCategoryId, selectCategoryId,
tabClickItem tabClickItem
} = ProductStore } = ProductStore
// 再次点击tab 选中置为0 // 再次点击tab 选中置为0
...@@ -209,17 +209,22 @@ const ProductImageForm: React.FC<{}> = (props) => { ...@@ -209,17 +209,22 @@ const ProductImageForm: React.FC<{}> = (props) => {
uploadFileSelectRef.current = {} uploadFileSelectRef.current = {}
} }
setCommonImageList(fileList) setCommonImageList(fileList)
// @5.10 commodityPic字段异常 表明前面商品信息未完善 使用trycatch捕获
_priceAttributeParams[index||editRowIndexRef.current].commodityPic = fileList try {
if(!file?.status && file?.status !== 'done'){ _priceAttributeParams[index||editRowIndexRef.current].commodityPic = fileList
let ttt = _priceAttributeParams[index||editRowIndexRef.current].commodityPic.filter(_ => _.status === 'done') if(!file?.status && file?.status !== 'done'){
_priceAttributeParams[index||editRowIndexRef.current].commodityPic = ttt let ttt = _priceAttributeParams[index||editRowIndexRef.current].commodityPic.filter(_ => _.status === 'done')
setCommonImageList(ttt) _priceAttributeParams[index||editRowIndexRef.current].commodityPic = ttt
setCommonImageList(ttt)
}
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
// 保留上传的数据在页面状态 用于处理前面价格变动后不重新更新图片数据
setMaintainImageData(_priceAttributeParams.map(item => item.commodityPic))
} catch(error) {
console.log(error)
// message.error('请先完善前面商品相关信息')
} }
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
// 保留上传的数据在页面状态 用于处理前面价格变动后不重新更新图片数据
setMaintainImageData(_priceAttributeParams.map(item => item.commodityPic))
} }
const onChangeSetImageType = (e) => { const onChangeSetImageType = (e) => {
...@@ -261,10 +266,10 @@ const ProductImageForm: React.FC<{}> = (props) => { ...@@ -261,10 +266,10 @@ const ProductImageForm: React.FC<{}> = (props) => {
<span>所有属性共用&nbsp;<i style={{color:'red'}}>*</i></span> <span>所有属性共用&nbsp;<i style={{color:'red'}}>*</i></span>
</li> </li>
} }
{ !setImageType && { !setImageType &&
priceAttributeParamsByRender?.length>0 && priceAttributeParamsByRender.map( priceAttributeParamsByRender?.length>0 && priceAttributeParamsByRender.map(
(item, index) => { (item, index) => {
return Array.isArray(item.attributeAndValueList) && return Array.isArray(item.attributeAndValueList) &&
<li key={index} className={defaultChecked == index ? styles.activedLi : ""} onClick={()=>clickItemTab(index)}> <li key={index} className={defaultChecked == index ? styles.activedLi : ""} onClick={()=>clickItemTab(index)}>
<span> <span>
{ {
...@@ -281,7 +286,7 @@ const ProductImageForm: React.FC<{}> = (props) => { ...@@ -281,7 +286,7 @@ const ProductImageForm: React.FC<{}> = (props) => {
<Col span={20} style={{ padding: 24 }} id="uploadBox"> <Col span={20} style={{ padding: 24 }} id="uploadBox">
{ {
!setImageType ? !setImageType ?
(priceAttributeParamsByRender?.length>0 && priceAttributeParamsByRender[0]?.attributeAndValueList?.length!=0 ? priceAttributeParamsByRender.map((item, index) => (priceAttributeParamsByRender?.length>0 && priceAttributeParamsByRender[0]?.attributeAndValueList?.length!=0 ? priceAttributeParamsByRender.map((item, index) =>
<div key={index+100} style={defaultChecked == index ? {display: 'block'} : {display: 'none'}}> <div key={index+100} style={defaultChecked == index ? {display: 'block'} : {display: 'none'}}>
<div className={styles.pictureCardBox}> <div className={styles.pictureCardBox}>
<div className="clearfix"> <div className="clearfix">
...@@ -364,4 +369,4 @@ const ProductImageForm: React.FC<{}> = (props) => { ...@@ -364,4 +369,4 @@ const ProductImageForm: React.FC<{}> = (props) => {
</div>) </div>)
} }
export default observer(ProductImageForm) export default observer(ProductImageForm)
\ No newline at end of file
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