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

fix: 处理商品编辑下编辑按属性设置图片重置到第一项的问题、处理资金账户详情缺少状态报错问题

parent e366904d
......@@ -134,6 +134,7 @@ const AddGoods = () => {
onFinish={onFinish}
colon={false}
autoComplete="off"
labelAlign="left"
>
<Form.Item
name="code"
......
......@@ -31,6 +31,7 @@ const AddProducts: React.FC<{}> = (props) => {
const [responseId, setReponseId] = useState<number>(null)
const [attributeList, setAttributeList] = useState<any[]>([])
const [clickTabIndex, setClickTabIndex] = useState<string[]>(['1'])
const [clickCurrentIndex, setClickCurrentIndex] = useState<string>('1')
const [isDisableSaveBtn, setIsDisableSaveBtn] = useState<boolean>(false)
const [currentTemplateName, setCurrentTemplateName] = useState<string>()
let [formRefs, setFormRefs] = useState([]) //子form的ref数组
......@@ -337,8 +338,8 @@ const AddProducts: React.FC<{}> = (props) => {
}
const callback = (key: any) => {
setClickCurrentIndex(key)
setClickTabIndex([...clickTabIndex, key])
// 点击项存入store 用于后续编辑步骤判断 是直接点击进去某个子模块还是已经进入子模块 从而采用缓存数据还是采用接口返回的编辑数据
setTabClickItem([...clickTabIndex, key])
}
......
......@@ -37,7 +37,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const { onRef } = props
const priceFormRef = useRef()
const updateFlag = useRef(true) // 是否第一次构建
const updateAttributeFlag = useRef(true) // 是否第一次商品属性变动的构建
const clearPrice = useRef(false)
const [priceForm] = Form.useForm()
const [setPriceForm] = Form.useForm()
const [planPrice, setPlanPrice] = useState(1)
......@@ -56,17 +56,6 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const [combineAttributeChangeFatories, setCombineAttributeChangeFatories] = useState<number>(0)
const memoizedValue = useMemo(() => {
let len = combineAttributeArray.length
console.log(len, combineAttributeChangeFatories)
if(len === combineAttributeChangeFatories){
return false
}else{
setCombineAttributeChangeFatories(len)
return true
}
} , [combineAttributeArray.length]) // 监听属性组合是否有变动(由属性组合引发数据构建清空价格)
const [colums, setColumns] = useState<ColumnType<any>[]>()
const { ProductStore } = store
const {
......@@ -85,6 +74,45 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
tabClickItem
} = ProductStore
// const memoizedValue = useMemo(() => {
// let len = combineAttributeArray.length
// console.log(len, combineAttributeChangeFatories)
// // 第一次构建先和编辑数据比对
// // if(updateFlag){
// // if(len === productInfoByEdit?.unitPriceAndPicList.length){
// // return false
// // } else {
// // return true
// // }
// // }
// if(len === combineAttributeChangeFatories){
// return false
// }else{
// setCombineAttributeChangeFatories(len)
// return true
// }
// } , [combineAttributeArray.length]) // 监听属性组合是否有变动(由属性组合引发数据构建清空价格)
// // *bug* 不点击本页面之前就变更了价格属性 这里的属性组合监听就失效了
useEffect(() => {
let len = combineAttributeArray.length
// 第一次构建先和编辑数据比对
if(updateFlag){
if(len === productInfoByEdit?.unitPriceAndPicList.length){
clearPrice.current = false
} else {
clearPrice.current = true
}
}
if(len === combineAttributeChangeFatories){
clearPrice.current = false
}else{
setCombineAttributeChangeFatories(len)
clearPrice.current = true
}
// console.log(len, combineAttributeChangeFatories, `是否初次构建|${updateFlag.current}`, clearPrice.current, '监听前后属性条目的变动')
}, [combineAttributeArray.length])
_tableDataSource = useMemo(() => tableDataSource, [tableDataSource]) // 保持最新值
useEffect(() => {
......@@ -113,9 +141,21 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
}
}, [selectCategoryId])
/**
* 添加clearPrice.current依赖,处理在未渲染价格属性前已经变动了价格属性组合,此时需要清空价格数据
* bug: 在不改变那价格属性组合情况下修改价格可以保留,当属性组合变动之后,修改价格再做其他修改时会清空价格(原因:clearPrice.current始终为true)
* 添加 tabClickItem
* 价格属性变动引发的构建,清空价格(仅清空一次)之后置为false
*/
useEffect(()=>{
constructedCallback()
},[productName, selectedGoods, productSelectAttribute, planPrice, tabClickItem])
},[productName, selectedGoods, productSelectAttribute, planPrice, clearPrice.current])
useEffect(()=>{
if(clearPrice.current){
constructedCallback()
clearPrice.current = false
}
},[clearPrice.current])
/* 生成建表所需要的属性 属性值等数组数据 */
const generateNeedData = (hasAttribute: IProductSelectAttribute[]) => {
......@@ -291,13 +331,14 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
}
}else{
_tempObj['对应货品'] = selectedGoods.length > 0 ? selectedGoods[0].id : 0
// _tempObj['单价'] = {}
_tempObj['单价'] = _tableDataSource[i] && tableDataSource[i]['单价'] || {}
}
// 价格属性变动引发的构建清空价格
if(memoizedValue){ _tempObj['单价'] = {} }
// 价格属性变动引发的构建清空价格(仅清空一次)
if(clearPrice.current){
_tempObj['单价'] = {}
}
// selectedGoods数据是前面表格选择的数组
console.log(_tableDataSource , selectedGoods, '构建表格单价数据', memoizedValue)
// console.log(_tableDataSource , selectedGoods, '构建表格单价数据', `是否初次构建|${updateFlag.current}`, clearPrice.current)
_tableData.push(_tempObj)
})
}else{ // length不存在,默认只有商品名称一行(无价格属性组合)只有一行的情况下单价可能有,可能阶梯价,也可能没有
......
import React, { useState, useEffect, useRef } from 'react'
import React, { useState, useEffect, useRef, useImperativeHandle } from 'react'
import {history} from 'umi'
import { message, Modal, Row, Col, Alert, Upload, Radio, Button } from 'antd'
import { EditOutlined, PlusOutlined } from '@ant-design/icons'
......@@ -13,7 +13,6 @@ import { inject, observer } from 'mobx-react'
import { store } from '@/store'
const ProductImageForm: React.FC<{}> = (props) => {
const fff = useRef<number>(0)
const [defaultChecked, setDefaultChecked] = useState(-1)
const [priceAttributeParamsByRender, setPriceAttributeParamsByRender] = useState<any[]>([])
const [commonImageList, setCommonImageList] = useState<any>([])
......@@ -31,7 +30,14 @@ const ProductImageForm: React.FC<{}> = (props) => {
const editRowIndexRef = useRef<number>(0)
const { ProductStore } = store
const { priceAttributeParams, productInfoByEdit, setProductAttributeAndImageParams, setIsAllAttributePic, selectCategoryId } = ProductStore
const { priceAttributeParams, productInfoByEdit, setProductAttributeAndImageParams, setIsAllAttributePic, selectCategoryId, tabClickItem } = ProductStore
// 再次点击tab 选中置为0
useEffect(() => {
if(tabClickItem.filter(i => i === '5').length > 1){
clickItemTab(0)
}
}, [tabClickItem])
useEffect(() => {
if(history.location.query?.id){
......@@ -57,6 +63,7 @@ const ProductImageForm: React.FC<{}> = (props) => {
return _commodityPicItem
})
setMaintainImageData(o)
clickItemTab(0)
}
}, [])
......@@ -99,7 +106,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
_priceAttributeParams = priceAttributeParams.map((_item, _index) => {
let _obj = {..._item}
_obj.commodityPic = maintainImageData[_index] || []
// _obj.commodityPic = _commodityPicItem
return _obj
})
}else{
......@@ -109,8 +115,6 @@ const ProductImageForm: React.FC<{}> = (props) => {
return _obj
})
}
setDefaultChecked(0)
clickItemTab(0)
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
// 初始化若是按所有属性共用做显示处理
......
......@@ -101,7 +101,8 @@ export const CREDIT_INNER_STATUS_BADGE_MAP = {
'4': { title: '提现成功', type: 'success' },
'5': { title: '提现失败', type: 'danger' },
'6': { title: '支付中', type: 'processing' },
'7': { title: '确认到账', type: 'success' },
'7': { title: '支付失败', type: 'danger' },
'8': { title: '确认到账', type: 'success' },
}
// 流转状态
......
......@@ -114,7 +114,7 @@ const Trademark: React.FC<{}> = () => {
</Dropdown>
</> :
<>
<Button type='link' onClick={()=>history.push(`/memberCenter/commodityAbility/trademark/addBrand?id=${record.id}`)}>修改</Button>
<Button type='link' onClick={()=>history.push(`/memberCenter/commodityAbility/trademark/add?id=${record.id}`)}>修改</Button>
<Button onClick={() => handelDelete(record)} type='link'>删除</Button>
</>
}
......
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