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

fix: 商品编辑图片乱序

parent 292c5e8b
...@@ -23,7 +23,6 @@ const { Option } = Select ...@@ -23,7 +23,6 @@ const { Option } = Select
const LogisticsForm: React.FC<Iprops> = (props) => { const LogisticsForm: React.FC<Iprops> = (props) => {
const { onRef } = props const { onRef } = props
const logisticsFormRef = useRef() const logisticsFormRef = useRef()
const [logisticsForm] = Form.useForm() const [logisticsForm] = Form.useForm()
const [logisticsCompanyLists, setLogisticsCompanyLists] = useState<GetLogisticsSelectListCompanyResponse>() const [logisticsCompanyLists, setLogisticsCompanyLists] = useState<GetLogisticsSelectListCompanyResponse>()
...@@ -32,14 +31,20 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -32,14 +31,20 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
const [isTemplate, setIsTemplate] = useState<boolean>(false) const [isTemplate, setIsTemplate] = useState<boolean>(false)
const [deliveryType, setDeliveryType] = useState<number>(1) const [deliveryType, setDeliveryType] = useState<number>(1)
const [carriageType, setCarriageType] = useState<number>() const [carriageType, setCarriageType] = useState<number>()
const { productInfoByEdit } = ProductStore const flagRef = useRef<boolean>(false)
const { productInfoByEdit, selectCategoryId } = ProductStore
useEffect(()=>{ useEffect(()=>{
//传入ref给父级 //传入ref给父级
onRef(logisticsFormRef) onRef(logisticsFormRef)
if(history.location.query?.id) if(history.location.query?.id){
setDeliveryType(productInfoByEdit.logistics?.deliveryType) setDeliveryType(productInfoByEdit.logistics?.deliveryType)
logisticsForm.setFieldsValue(productInfoByEdit.logistics)
}else{
logisticsForm.setFieldsValue({deliveryType:1, carriageType:1})
}
// 获取发货地址 物流公司 运费模板 // 获取发货地址 物流公司 运费模板
PublicApi.getLogisticsSelectListShipperAddress().then(res=>{ PublicApi.getLogisticsSelectListShipperAddress().then(res=>{
...@@ -56,6 +61,16 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -56,6 +61,16 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
}, []) }, [])
useEffect(() => {
// 品类 变动清空form
if(history.location.query?.id && !flagRef.current) {
flagRef.current = true
} else {
logisticsForm.resetFields()
logisticsForm.setFieldsValue({deliveryType:1, carriageType:1})
}
}, [selectCategoryId])
const changeDeliveryType = (e) => { const changeDeliveryType = (e) => {
setDeliveryType(e.target.value) setDeliveryType(e.target.value)
setCarriageType(1) setCarriageType(1)
...@@ -77,7 +92,7 @@ const LogisticsForm: React.FC<Iprops> = (props) => { ...@@ -77,7 +92,7 @@ const LogisticsForm: React.FC<Iprops> = (props) => {
labelAlign="left" labelAlign="left"
ref={logisticsFormRef} ref={logisticsFormRef}
colon={false} colon={false}
initialValues={history.location.query?.id ? productInfoByEdit.logistics : {deliveryType:1, carriageType:1}} // initialValues={history.location.query?.id ? productInfoByEdit.logistics : {deliveryType:1, carriageType:1}}
autoComplete="off" autoComplete="off"
> >
<Form.Item <Form.Item
......
...@@ -24,14 +24,27 @@ const { TextArea } = Input ...@@ -24,14 +24,27 @@ const { TextArea } = Input
const OtherForm: React.FC<Iprops> = (props) => { const OtherForm: React.FC<Iprops> = (props) => {
const { onRef } = props const { onRef } = props
const otherFormRef = useRef() const otherFormRef = useRef()
const flagRef = useRef<boolean>(false)
const [otherForm] = Form.useForm() const [otherForm] = Form.useForm()
const { getOtherFormParamsByEdit } = ProductStore const { getOtherFormParamsByEdit, selectCategoryId } = ProductStore
useEffect(()=>{ useEffect(()=>{
//传入ref给父级 //传入ref给父级
onRef(otherFormRef) onRef(otherFormRef)
if(history.location.query?.id)
otherForm.setFieldsValue(getOtherFormParamsByEdit)
}, []) }, [])
useEffect(() => {
// 品类 变动清空form
if(history.location.query?.id && !flagRef.current) {
flagRef.current = true
} else {
otherForm.resetFields()
}
}, [selectCategoryId])
return (<> return (<>
<Form <Form
{...layout} {...layout}
...@@ -41,7 +54,6 @@ const OtherForm: React.FC<Iprops> = (props) => { ...@@ -41,7 +54,6 @@ const OtherForm: React.FC<Iprops> = (props) => {
ref={otherFormRef} ref={otherFormRef}
colon={false} colon={false}
autoComplete="off" autoComplete="off"
initialValues={history.location.query?.id ? getOtherFormParamsByEdit : {}}
> >
<Form.Item <Form.Item
name="isInvoice" name="isInvoice"
......
...@@ -43,8 +43,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -43,8 +43,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const updateFlag = useRef(true) // 是否第一次构建 const updateFlag = useRef(true) // 是否第一次构建
const [priceForm] = Form.useForm() const [priceForm] = Form.useForm()
const [setPriceForm] = Form.useForm() const [setPriceForm] = Form.useForm()
const [planPrice, setPlanPrice] = useState(1) //商品定价类型 ref替代 const [planPrice, setPlanPrice] = useState(1)
// const priceTypeRef = useRef<number>(1)
const [unitData, setUnitData] = useState<any>([]) const [unitData, setUnitData] = useState<any>([])
const [unitValue, setUnitValue] = useState(undefined) const [unitValue, setUnitValue] = useState(undefined)
const [setPriceModal, setSetPriceModal] = useState(false) const [setPriceModal, setSetPriceModal] = useState(false)
...@@ -56,6 +55,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -56,6 +55,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
const [attributeValObjArr, setAttributeValObjArr] = useState<any[]>([]) const [attributeValObjArr, setAttributeValObjArr] = useState<any[]>([])
const [minOrderNumber, setMinOrderNumber] = useState<number>() const [minOrderNumber, setMinOrderNumber] = useState<number>()
const [isBatchSetting, setIsBatchSetting] = useState<boolean>(false) //是否点击批量设置 const [isBatchSetting, setIsBatchSetting] = useState<boolean>(false) //是否点击批量设置
const flagRef = useRef<boolean>(false)
const [colums, setColumns] = useState<ColumnType<any>[]>() const [colums, setColumns] = useState<ColumnType<any>[]>()
const { ProductStore } = store const { ProductStore } = store
...@@ -63,12 +63,14 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -63,12 +63,14 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
productName, productName,
selectedGoods, selectedGoods,
productSelectAttribute, productSelectAttribute,
setProductSelectAttribute,
tableDataSource, tableDataSource,
setTableDataSource, setTableDataSource,
clearData, clearData,
setPriceAttributeParams, setPriceAttributeParams,
productInfoByEdit, productInfoByEdit,
getPriceAttributeFormParamsByEdit, getPriceAttributeFormParamsByEdit,
selectCategoryId,
} = ProductStore } = ProductStore
_tableDataSource = useMemo(() => tableDataSource, [tableDataSource]) // 保持最新值 _tableDataSource = useMemo(() => tableDataSource, [tableDataSource]) // 保持最新值
...@@ -77,9 +79,9 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -77,9 +79,9 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
onRef(priceFormRef) onRef(priceFormRef)
if(history.location.query?.id){ // 编辑情况下 用于判断价格类型和显示单位 if(history.location.query?.id){ // 编辑情况下 用于判断价格类型和显示单位
setPlanPrice(productInfoByEdit?.priceType) setPlanPrice(productInfoByEdit?.priceType)
// priceTypeRef.current = productInfoByEdit?.priceType
handleUnitSearch(getPriceAttributeFormParamsByEdit.unitName) handleUnitSearch(getPriceAttributeFormParamsByEdit.unitName)
setMinOrderNumber(productInfoByEdit?.minOrder) setMinOrderNumber(productInfoByEdit?.minOrder)
priceForm.setFieldsValue(getPriceAttributeFormParamsByEdit)
} }
return ()=>{ return ()=>{
console.log('价格属性组件卸载') console.log('价格属性组件卸载')
...@@ -87,6 +89,17 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -87,6 +89,17 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
} }
},[]) },[])
useEffect(() => {
// 品类 变动清空form和属性组合
if(history.location.query?.id && !flagRef.current) {
flagRef.current = true
} else {
setProductSelectAttribute([])
priceForm.resetFields()
priceForm.setFieldsValue({isMemberPrice: false, priceType: planPrice})
}
}, [selectCategoryId])
useEffect(()=>{ useEffect(()=>{
constructedCallback() constructedCallback()
// console.log(productSelectAttribute, 'productSelectAttribute') // console.log(productSelectAttribute, 'productSelectAttribute')
...@@ -300,10 +313,10 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -300,10 +313,10 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
_tableDataSource = _tableData _tableDataSource = _tableData
// 有前面tab变动引起的二次构建 需要清空价格数据 // 有前面tab变动引起的二次构建 需要清空价格数据
if(updateFlag.current){ if(updateFlag.current){
// *****bug编辑积分商品(非现货价格)会导致价格类型变动引发重复渲染***** // ***** bug编辑积分商品(非现货价格)会导致价格类型变动引发重复渲染 *****
updateFlag.current = false updateFlag.current = false
} else { } else {
// ***** 编辑情况下且是积分商品 不做清空单价处理***** // ***** 编辑情况下且是积分商品 不做清空单价处理 *****
if(!(productInfoByEdit?.id && planPrice === 3)) if(!(productInfoByEdit?.id && planPrice === 3))
_tableDataSource.map(item => item['单价'] = {}) _tableDataSource.map(item => item['单价'] = {})
} }
...@@ -552,7 +565,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => { ...@@ -552,7 +565,7 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
labelAlign="left" labelAlign="left"
ref={priceFormRef} ref={priceFormRef}
colon={false} colon={false}
initialValues={productInfoByEdit?.id ? getPriceAttributeFormParamsByEdit : {isMemberPrice: false, priceType: planPrice}} // initialValues={productInfoByEdit?.id ? getPriceAttributeFormParamsByEdit : {isMemberPrice: false, priceType: planPrice}}
autoComplete="off" autoComplete="off"
> >
<Form.Item <Form.Item
......
...@@ -15,12 +15,6 @@ const layout = { ...@@ -15,12 +15,6 @@ const layout = {
span: 12, span: 12,
}, },
} }
const tailLayout = {
wrapperCol: {
offset: 2,
span: 12,
},
}
export interface Iprops { export interface Iprops {
attributesData: any[]; attributesData: any[];
...@@ -36,7 +30,6 @@ let paramsArray = []; ...@@ -36,7 +30,6 @@ let paramsArray = [];
const ProductAttributeForm: React.FC<Iprops> = (props) => { const ProductAttributeForm: React.FC<Iprops> = (props) => {
const { attributesData, onRef } = props const { attributesData, onRef } = props
const [attributeParamsArray, setAttributeParamsArray] = useState<any>([])
const [isClearFormAndDataInEdit, setIsClearFormAndDataInEdit] = useState<boolean>(false) // 编辑情况下 是否要清空商品属性表单数据和页面全局数据 const [isClearFormAndDataInEdit, setIsClearFormAndDataInEdit] = useState<boolean>(false) // 编辑情况下 是否要清空商品属性表单数据和页面全局数据
const productAttributeFormRef = useRef() const productAttributeFormRef = useRef()
const [attributeForm] = Form.useForm() const [attributeForm] = Form.useForm()
......
import React, { useState, useEffect } from 'react' import React, { useState, useEffect, useRef } from 'react'
import {history} from 'umi' import {history} from 'umi'
import { Button, message, Upload } from 'antd' import { Button, message, Upload } from 'antd'
import cx from 'classnames' import cx from 'classnames'
import { Player } from 'video-react';
import styles from '../index.less' import styles from '../index.less'
import { PlusOutlined, DeleteOutlined } from '@ant-design/icons' import { PlusOutlined, DeleteOutlined } from '@ant-design/icons'
// import { PublicApi } from '@/services/api'
import { UPLOAD_TYPE } from '@/constants' import { UPLOAD_TYPE } from '@/constants'
export interface Iprops {
}
import { inject, observer } from 'mobx-react' import { inject, observer } from 'mobx-react'
import { store } from '@/store' import { store } from '@/store'
const ProductDescFormDefualt: React.FC<Iprops> = (props) => { const ProductDescFormDefualt: React.FC<{}> = (props) => {
const [fileImageList, setFileImageList] = useState<any>([]) const [fileImageList, setFileImageList] = useState<any>([])
const [videoList, setVideoList] = useState<any>([]) const [videoList, setVideoList] = useState<any>([])
const flagRef = useRef<boolean>(false)
const { ProductStore } = store const { ProductStore } = store
const { productInfoByEdit, setProductDescription } = ProductStore const { productInfoByEdit, setProductDescription, selectCategoryId } = ProductStore
useEffect(()=>{ useEffect(()=>{
if(history.location.query?.id){ // 编辑状态下 if(history.location.query?.id){ // 编辑状态下
...@@ -35,6 +30,18 @@ const ProductDescFormDefualt: React.FC<Iprops> = (props) => { ...@@ -35,6 +30,18 @@ const ProductDescFormDefualt: React.FC<Iprops> = (props) => {
}, []) }, [])
useEffect(() => { useEffect(() => {
// 品类 变动清空数据
// 编辑下 flag为false 不清空;编辑下 flag为true 新建清空
if(history.location.query?.id && !flagRef.current) {
flagRef.current = true
} else {
setFileImageList([])
setVideoList([])
}
}, [selectCategoryId])
useEffect(() => {
// 设置传输数据 // 设置传输数据
setProductDescription({ setProductDescription({
video: videoList, video: videoList,
......
import React, { useState, useEffect } from 'react' import React, { useState, useEffect, useRef } from 'react'
import {history} from 'umi' import {history} from 'umi'
import { Button, Form, Select, Checkbox, message, Input, Table, Modal, Row, Col, Alert, Upload, Radio } from 'antd' import { Button, Form, Select, Checkbox, message, Input, Table, Modal, Row, Col, Alert, Upload, Radio } from 'antd'
import { PlusOutlined } from '@ant-design/icons' import { PlusOutlined } from '@ant-design/icons'
...@@ -12,34 +12,44 @@ import { inject, observer } from 'mobx-react' ...@@ -12,34 +12,44 @@ import { inject, observer } from 'mobx-react'
// import { IStore } from '@/store'; // import { IStore } from '@/store';
import { store } from '@/store' import { store } from '@/store'
export interface Iprops { const ProductImageForm: React.FC<{}> = (props) => {
}
const layoutAdd = {
labelCol: { span: 4 },
wrapperCol: { span: 20 },
}
const ProductImageForm: React.FC<Iprops> = (props) => {
const [addTabsForm] = Form.useForm()
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)
const [previewImage, setPreviewImage] = useState('') const [previewImage, setPreviewImage] = useState('')
const [previewTitle, setPreviewTitle] = useState('') const [previewTitle, setPreviewTitle] = useState('')
const [setImageType, setSetImageType] = useState<boolean>(true) const [setImageType, setSetImageType] = useState<boolean>(true)
const flagRef = useRef<boolean>(false)
const { ProductStore } = store const { ProductStore } = store
const { priceAttributeParams, productInfoByEdit, setProductAttributeAndImageParams, setIsAllAttributePic } = ProductStore const { priceAttributeParams, productInfoByEdit, setProductAttributeAndImageParams, setIsAllAttributePic, selectCategoryId } = ProductStore
useEffect(() => {
if(history.location.query?.id){
setSetImageType(productInfoByEdit.isAllAttributePic)
}
}, [])
useEffect(() => {
// 品类 变动清空数据
// 编辑下 flag为false 不清空;编辑下 flag为true 新建清空
if(history.location.query?.id && !flagRef.current) {
flagRef.current = true
console.log('不清空')
} else {
// constructImageListByRender([])
// setSetImageType(true)
onChangeSetImageType({target: { value: true }})
console.log('清空')
}
}, [selectCategoryId])
useEffect(()=>{ useEffect(()=>{
if(priceAttributeParams.length > 0){ if(priceAttributeParams.length > 0){
console.log(priceAttributeParams, '对比') console.log(priceAttributeParams, '对比')
constructImageListByRender(priceAttributeParams) constructImageListByRender(priceAttributeParams)
}else if(history.location.query?.id){ }else if(history.location.query?.id){ // 不点击前面 直接进入图片tab
console.log(productInfoByEdit.unitPriceAndPicList, '对比') console.log(productInfoByEdit.unitPriceAndPicList, '对比')
constructImageListByRender(productInfoByEdit.unitPriceAndPicList) constructImageListByRender(productInfoByEdit.unitPriceAndPicList)
} }
...@@ -50,18 +60,28 @@ const ProductImageForm: React.FC<Iprops> = (props) => { ...@@ -50,18 +60,28 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
const constructImageListByRender = (priceAttributeParams?: any) => { const constructImageListByRender = (priceAttributeParams?: any) => {
let _priceAttributeParams: any = [] let _priceAttributeParams: any = []
if(productInfoByEdit?.id){ // id判断是否新增还是编辑 if(productInfoByEdit?.id){ // id判断是否新增还是编辑
setSetImageType(productInfoByEdit.isAllAttributePic) // setSetImageType(productInfoByEdit.isAllAttributePic)
setIsAllAttributePic(productInfoByEdit.isAllAttributePic) setIsAllAttributePic(productInfoByEdit.isAllAttributePic)
let _commodityPicList = productInfoByEdit.unitPriceAndPicList.map(_ => _.commodityPic)
_priceAttributeParams = priceAttributeParams.map((_item, _index) => { _priceAttributeParams = priceAttributeParams.map((_item, _index) => {
// 为图片字符串数组手动添加 uid 和 status // 为图片字符串数组手动添加 uid 和 status
let _commodityPicItem = Array.isArray(_commodityPicList[_index]) ? _commodityPicList[_index].map((__ele, __i) => { // console.log(_item, '_____')
// 查询编辑详情中属性值id相匹配的图片
let _pic = null
let _priceAndPicList = productInfoByEdit.unitPriceAndPicList
for(let i = 0; i < _priceAndPicList.length; i++) {
if(_priceAndPicList[i].attributeAndValueList.map(item => item.customerAttributeValue.id).sort().toString() == _item.attributeAndValueList.map(item => item.customerAttributeValue.id).sort().toString()){
_pic = _priceAndPicList[i].commodityPic
}
}
let _commodityPicItem = Array.isArray(_pic) ? _pic.map((__ele, __i) => {
return { return {
uid: __i * -1, uid: __i * -1,
status: 'done', status: 'done',
url: __ele, url: __ele,
} }
}) :[] }) : []
let _obj = {..._item} let _obj = {..._item}
_obj.commodityPic = _commodityPicItem _obj.commodityPic = _commodityPicItem
return _obj return _obj
...@@ -77,7 +97,7 @@ const ProductImageForm: React.FC<Iprops> = (props) => { ...@@ -77,7 +97,7 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
clickItemTab(0) clickItemTab(0)
setPriceAttributeParamsByRender(_priceAttributeParams) setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams) setProductAttributeAndImageParams(_priceAttributeParams)
console.log(_priceAttributeParams, priceAttributeParams, '_p') // 这里可能为空数组 ** 如果不到此页面 前一个是旧数据 后面的为新数据 // console.log(_priceAttributeParams, priceAttributeParams, '_p')
// 初始化若是按所有属性共用做显示处理 // 初始化若是按所有属性共用做显示处理
if(setImageType && _priceAttributeParams.length>0){ if(setImageType && _priceAttributeParams.length>0){
setCommonImageList(_priceAttributeParams[0].commodityPic) setCommonImageList(_priceAttributeParams[0].commodityPic)
......
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