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

fix:品类属性新建、商品单独修改价格异常

parent 81dcc4b2
......@@ -28,15 +28,9 @@ export interface ShopInfo {
url: string;
}
export interface OrderMode {
value: number;
label: string;
platformType: number;
}
export interface Web {
shopInfo: ShopInfo[];
orderMode: OrderMode[];
orderMode: any[];
}
export interface CountryList {
......
......@@ -91,24 +91,20 @@ const AddAtttribute: React.FC<{}> = () => {
{
title: 'ID',
dataIndex: 'id',
align: 'center',
key: 'id',
},
{
title: '属性名称',
dataIndex: 'name',
align: 'center',
key: 'name',
},
{
title: '属性组名',
dataIndex: 'groupName',
align: 'center',
key: 'groupName',
},
{
title: '展示方式',
align: 'center',
dataIndex: 'type',
key: 'type',
render: (text:number) => {
......@@ -118,7 +114,6 @@ const AddAtttribute: React.FC<{}> = () => {
},
{
title: '是否必填',
align: 'center',
dataIndex: 'isEmpty',
key: 'isEmpty',
render: (text: boolean) => text?'是':'否'
......@@ -343,6 +338,7 @@ const AddAtttribute: React.FC<{}> = () => {
onCancel={()=>setRoleVisible(false)}
okText="确认"
cancelText="取消"
width={704}
>
<StandardTable
columns={columns}
......
......@@ -57,13 +57,13 @@ const CategoryAttributes: React.FC<{}> = () => {
// 获取选中项的关联属性列表
useEffect(() => {
if (selectKey)
ref.current.reload({ current: 1, pageSize: 10, name: '', categoryId: selectKey })
ref.current.reload({ current: 1, pageSize: 10, name: '', categoryId: selectKey, isByCategory: true })
}, [selectKey])
const fetchLinkAttributeData = (params: any) => {
console.log(params, 'params')
return new Promise((resolve, reject) => {
PublicApi.getProductCustomerGetCustomerCategoryAttributeList({...params, categoryId: selectKey, name: params.name || ''}).then(res=>{
PublicApi.getProductCustomerGetCustomerCategoryAttributeList({...params, categoryId: selectKey, name: params.name || '', isByCategory: true}).then(res=>{
resolve(res.data)
setLinkTableRowData(res.data.data)
})
......@@ -74,7 +74,10 @@ const CategoryAttributes: React.FC<{}> = () => {
const fetchAttributeData = (params: any) => {
console.log(params, 'params')
return new Promise((resolve, reject) => {
PublicApi.getProductCustomerGetCustomerAttributeList({ ...params, name: params.name || '' }).then(res=>{
// PublicApi.getProductCustomerGetCustomerAttributeList({ ...params, name: params.name || '' }).then(res=>{
// resolve(res.data)
// })
PublicApi.getProductCustomerGetCustomerCategoryAttributeList({...params, categoryId: selectKey, name: params.name || '', isByCategory: false}).then(res=>{
resolve(res.data)
})
})
......@@ -86,12 +89,10 @@ const CategoryAttributes: React.FC<{}> = () => {
const handleSelectOk = () => {
setRoleVisible(false)
// if (goodsRowCtl.selectRow.length) {
PublicApi.postProductCustomerSaveCustomerCategoryAttribute({ customerCategoryId: selectKey, customerAttributeIds: goodsRowCtl.selectedRowKeys }).then(res=>{
if(res.code === 1000)
setTimeout(() => ref.current.reload(), 500)
})
// }
PublicApi.postProductCustomerSaveCustomerCategoryAttribute({ customerCategoryId: selectKey, customerAttributeIds: goodsRowCtl.selectedRowKeys }).then(res=>{
if(res.code === 1000)
setTimeout(() => ref.current.reload(), 500)
})
}
const handleSelectCancel = () => {
setRoleVisible(false)
......@@ -102,26 +103,22 @@ const CategoryAttributes: React.FC<{}> = () => {
{
title: 'ID',
dataIndex: 'id',
align: 'center',
key: 'id',
},
{
title: '属性名称',
dataIndex: 'name',
align: 'center',
key: 'name',
render: (text: any, record: any) => <span className="commonPickColor" onClick={() => handleSee(record)}>{text}&nbsp;<EyeOutlined /></span>
},
{
title: '属性组名称',
dataIndex: 'groupName',
align: 'center',
key: 'groupName',
},
{
title: '展示方式',
dataIndex: 'type',
align: 'center',
key: 'type',
render: (text: any, record: any) => {
let _txt: string = ''
......@@ -138,13 +135,11 @@ const CategoryAttributes: React.FC<{}> = () => {
{
title: '是否必填',
dataIndex: 'isEmpty',
align: 'center',
key: 'isEmpty',
render: (text: any, record: any) => (<>{text ? '是' : '否'}</>)
},
{
title: '状态',
align: 'center',
dataIndex: 'isEnable',
key: 'isEnable',
render: (text: any, record: any) => text ? '有效' : '无效'
......@@ -152,7 +147,6 @@ const CategoryAttributes: React.FC<{}> = () => {
{
title: '操作',
dataIndex: 'option',
align: 'center',
render: (text: any, record: any) => {
return (
<>
......@@ -167,25 +161,21 @@ const CategoryAttributes: React.FC<{}> = () => {
{
title: 'ID',
dataIndex: 'id',
align: 'center',
key: 'id',
},
{
title: '属性名称',
dataIndex: 'name',
align: 'center',
key: 'name',
},
{
title: '属性组名称',
dataIndex: 'groupName',
align: 'center',
key: 'groupName',
},
{
title: '展示方式',
dataIndex: 'type',
align: 'center',
key: 'type',
render: (text: any, record: any) => {
let _txt: string = ''
......@@ -202,7 +192,6 @@ const CategoryAttributes: React.FC<{}> = () => {
{
title: '是否必填',
dataIndex: 'isEmpty',
align: 'center',
key: 'isEmpty',
render: (text: any, record: any) => (<>{text ? '是' : '否'}</>)
}
......@@ -325,6 +314,7 @@ const CategoryAttributes: React.FC<{}> = () => {
okText="确认"
cancelText="取消"
destroyOnClose={true}
width={704}
>
<StandardTable
columns={columnsLink}
......
......@@ -27,6 +27,7 @@ const AddProducts: React.FC<{}> = (props) => {
const [responseId, setReponseId] = useState<number>(null)
const [attributeList, setAttributeList] = useState<any[]>([])
const [clickTabIndex, setClickTabIndex] = useState<string[]>(['1'])
const [isDisableSaveBtn, setIsDisableSaveBtn] = useState<boolean>(false)
let [formRefs, setFormRefs] = useState([]) //子form的ref数组
const { ProductStore } = store
const {
......@@ -64,6 +65,7 @@ const AddProducts: React.FC<{}> = (props) => {
}, [])
const onSave = () => {
setIsDisableSaveBtn(true)
const { id } = history.location.query
if(formRefs.length > 0){
try{
......@@ -128,29 +130,36 @@ const AddProducts: React.FC<{}> = (props) => {
/** 没有点击tab项做修改处理时 */
// 如果没有点击商品图片第"5"项 不做校验
if(clickTabIndex.indexOf("5") !== -1){
let _productAttributeAndImageParams = [...productAttributeAndImageParams]
try{
if(productAttributeAndImageParams.length>0){
productAttributeAndImageParams.map(_item => {
if(_productAttributeAndImageParams.length>0){
_productAttributeAndImageParams.map(_item => {
console.log(_item, '_item')
_item.goods = { id: _item.goodsId } // id为0表示无货品
delete _item.goodsId
if(_item.attributeAndValueList.length>0){
_item.attributeAndValueList.map(__item => {
delete __item.customerAttributeName
// **** 新字段结构变更
__item.customerAttribute = { id: __item.customerAttributeId }
__item.customerAttributeValue = { id: __item.id, value: __item.value }
delete __item.id
delete __item.value
delete __item.customerAttributeId
})
}
// if(_item.attributeAndValueList.length>0){
// _item.attributeAndValueList.map(__item => {
// delete __item.customerAttributeName
// // **** 新字段结构变更
// __item.customerAttribute = { id: __item.customerAttributeId }
// __item.customerAttributeValue = { id: __item.id, value: __item.value }
// delete __item.id
// delete __item.value
// delete __item.customerAttributeId
// })
// }
if(_item.commodityPic.length>0){
// 编辑情况下兼顾手动添加图片列表属性
console.log('不一定')
_item.commodityPic = _item.commodityPic.map(__item => __item?.response?.data || __item?.url)
// 多种属性组合 所有属性共用的情况下 每一行都是用第一项
if(isAllAttributePic)
_item.commodityPic = _productAttributeAndImageParams[0].commodityPic
}else{
if(isAllAttributePic && productAttributeAndImageParams[0].commodityPic.length>0) //处理所有属性共用
_item.commodityPic = productAttributeAndImageParams[0].commodityPic
if(isAllAttributePic && _productAttributeAndImageParams[0].commodityPic.length>0){ //处理所有属性共用
console.log('所有属性共用')
_item.commodityPic = _productAttributeAndImageParams[0].commodityPic
}
else
throw new Error('每项请至少上传一张商品图片!')
}
......@@ -161,9 +170,26 @@ const AddProducts: React.FC<{}> = (props) => {
}catch(e){
return e
}
_params.unitPriceAndPicList = productAttributeAndImageParams
_params.unitPriceAndPicList = _productAttributeAndImageParams
}else{ // 编辑 没有点击商品图片
_params.unitPriceAndPicList = productInfoByEdit.unitPriceAndPicList
if(clickTabIndex.indexOf("4") !== -1){ // 没有点击图片单单修改了商品价格 取原有的图片和新的价格合成
console.log('仅修改商品价格')
_params.unitPriceAndPicList = priceAttributeParams.map((item, index) => {
return {
goods: { id: item.goodsId },
attributeAndValueList: item.attributeAndValueList,
// .map(_item => {
// return {
// customerAttribute: { id: _item.customerAttributeId },
// customerAttributeValue: { id: _item.id, value: _item.value }
// }
// }),
unitPrice: item.unitPrice,
commodityPic: productInfoByEdit.unitPriceAndPicList[index].commodityPic
}
})
}
}
if(clickTabIndex.indexOf("3")===-1) // 商品属性
_params.commodityAttributeList = productInfoByEdit.commodityAttributeList
......@@ -194,10 +220,16 @@ const AddProducts: React.FC<{}> = (props) => {
}catch(e){
return e
}
// 移除混入的id数字类的键值项
let numberKeys = Object.keys(_params).map(_ => Number(_)).filter(Boolean)
if(numberKeys.length>0)
numberKeys.map(item => delete _params[item])
console.log(_params, 'params')
PublicApi.postProductCommoditySaveOrUpdateCommodity(_params).then(res => {
if(res.code === 1000){
setIsEnableCheck(false)
setIsDisableSaveBtn(false)
setReponseId(res.data)
history.goBack()
}
......@@ -234,7 +266,7 @@ const AddProducts: React.FC<{}> = (props) => {
title={history.location.query.id?'编辑商品':'新建商品'}
extra={[
<Button key="2" disabled={isEnableCheck} onClick={handleApplyCheck}>直接提交审核</Button>,
<Button key="1" type="primary" icon={<SaveOutlined />} onClick={onSave}>
<Button key="1" type="primary" icon={<SaveOutlined />} onClick={onSave} disabled={isDisableSaveBtn}>
保存
</Button>,
]}
......
......@@ -199,11 +199,11 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
}else if(history.location.query?.id){ // 此时没有货品并且处于编辑状态 取接口返回的数据
let _goods: any[] = Object.values(productInfoByEdit.unitPriceAndPicList.map(_ => _.goods))
if(_goods.indexOf(null)===-1){
let goodsInApi : any = Object.values(_goods).reduce((item, next)=>{
let goodsInApi : any = Object.values(_goods.reduce((item, next)=>{
item[next.id] = next
return item
},{})
},{}))
_col.push({
title: '对应货品',
dataIndex: '对应货品',
......@@ -312,17 +312,34 @@ const PriceAttributeForm: React.FC<Iprops> = (props) => {
let _tempArr: any = []
Array.isArray(item) ? item.map((_item, _index) => {
let _tempObject: any = {};
_tempObject.customerAttributeId = attributeObjArr[_index].customerAttributeId
_tempObject.customerAttributeName = attributeObjArr[_index].attributeName
// _tempObject.id = attributeValObjArr[_index].find(__item=>__item.value===item[_index]).id /** 解决原有 若属性或者属性值顺序错乱无法找到正确值的问题 */
_tempObject.id = attributeValObjArr.map(item =>item.find(_ => _.value===_item)).filter(__ => __)[0].id
_tempObject.value = item[_index]
// _tempObject.customerAttributeId = attributeObjArr[_index].customerAttributeId
// _tempObject.customerAttributeName = attributeObjArr[_index].attributeName
// _tempObject.id = attributeValObjArr.map(item =>item.find(_ => _.value===_item)).filter(__ => __)[0].id
// _tempObject.value = item[_index]
/* 新格式 */
_tempObject.customerAttribute = {
id: attributeObjArr[_index].customerAttributeId,
name: attributeObjArr[_index].attributeName
}
_tempObject.customerAttributeValue = {
id: attributeValObjArr.map(item =>item.find(_ => _.value===_item)).filter(__ => __)[0].id,
value: item[_index]
}
_tempArr.push(_tempObject)
}) : _tempArr.push({
customerAttributeId: attributeObjArr[0].customerAttributeId,
customerAttributeName: attributeObjArr[0].attributeName,
id: attributeValObjArr[0][0].id,
value: item.toString()
// customerAttributeId: attributeObjArr[0].customerAttributeId,
// customerAttributeName: attributeObjArr[0].attributeName,
// id: attributeValObjArr[0][0].id,
// value: item.toString()
/* 新格式 */
customerAttribute: {
id: attributeObjArr[0].customerAttributeId,
name: attributeObjArr[0].attributeName
},
customerAttributeValue: {
id: attributeValObjArr[0][0].id,
value: item.toString()
}
})
_paramsArray.push({goodsId: _tableDataSource[index] ? _tableDataSource[index]['对应货品'] : 0, attributeAndValueList: _tempArr, unitPrice: _tableDataSource[index]&&_tableDataSource[index]['单价']}) /*带上货品id 带上单价*/
}) : _paramsArray.push({goodsId: _tableDataSource[0] ? _tableDataSource[0]['对应货品'] : 0, attributeAndValueList: [], unitPrice: _tableDataSource[0]&&_tableDataSource[0]['单价']}) /*带上货品id 带上单价*/
......
......@@ -26,20 +26,7 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
const [defaultChecked, setDefaultChecked] = useState(-1)
const [priceAttributeParamsByRender, setPriceAttributeParamsByRender] = useState<any[]>([])
const [commonImageList, setCommonImageList] = useState<any>([
// {
// uid: '-1',
// name: 'image.png',
// status: 'done',
// url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
// },
// {
// uid: '-2',
// name: 'image.png',
// status: 'done',
// url: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
// },
])
const [commonImageList, setCommonImageList] = useState<any>([])
const [previewVisible, setPreviewVisible] = useState(false)
const [previewImage, setPreviewImage] = useState('')
const [previewTitle, setPreviewTitle] = useState('')
......@@ -48,8 +35,19 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
const { ProductStore } = store
const { priceAttributeParams, productInfoByEdit, setProductAttributeAndImageParams, setIsAllAttributePic } = ProductStore
/* 给数据添加图片字段 */
useEffect(()=>{
if(priceAttributeParams.length > 0){
console.log(priceAttributeParams, '对比')
constructImageListByRender(priceAttributeParams)
}else if(history.location.query?.id){
console.log(productInfoByEdit.unitPriceAndPicList, '对比')
constructImageListByRender(productInfoByEdit.unitPriceAndPicList)
}
},[priceAttributeParams])
/* 给数据添加图片字段 */
/* 直接进入商品图片编辑的时候 参数为空数组 但是没有价格属性的时候 也可能为空数组 区别在于是否有url id */
const constructImageListByRender = (priceAttributeParams?: any) => {
let _priceAttributeParams: any = []
if(productInfoByEdit?.id){ // id判断是否新增还是编辑
setSetImageType(productInfoByEdit.isAllAttributePic)
......@@ -75,14 +73,8 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
return _obj
})
}
// console.log('???', _priceAttributeParams)
// if(_priceAttributeParams?.length>0 && _priceAttributeParams[0]?.goodsCustomerAttributeList?.length!=0){
setDefaultChecked(0)
clickItemTab(0)
// }else{
// setDefaultChecked(-1)
// clickItemTab(-1)
// }
setDefaultChecked(0)
clickItemTab(0)
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
console.log(_priceAttributeParams, priceAttributeParams, '_p') // 这里可能为空数组 ** 如果不到此页面 前一个是旧数据 后面的为新数据
......@@ -90,13 +82,11 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
if(setImageType && _priceAttributeParams.length>0){
setCommonImageList(_priceAttributeParams[0].commodityPic)
}
},[priceAttributeParams])
}
const clickItemTab = (_index: number) => {
console.log(_index, '点击项')
setDefaultChecked(_index)
// console.log(priceAttributeParams, 'params')
}
const uploadButton = (
......@@ -161,23 +151,12 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
const handleChange = ({ file, fileList }, index) => {
let _priceAttributeParams = [...priceAttributeParamsByRender]
console.log(_priceAttributeParams, index, '图片更改初始数据')
// if(index===-1){ // -1表示所有属性共用 也表示表格只有默认的一行 // 无需判断 不管是共用还是不共用都需要逐条写入fileList
setCommonImageList(fileList)
// _priceAttributeParams[0].commodityPic = fileList
// }else{
_priceAttributeParams[index].commodityPic = fileList
// }
setCommonImageList(fileList)
_priceAttributeParams[index].commodityPic = fileList
if(!file?.status && file?.status !== 'done'){
// 不符合要求的 移除没有'done'状态的图片
// if(index === -1){
// let ttt = _priceAttributeParams[0].commodityPic.filter(_ => _.status === 'done')
// setCommonImageList(ttt)
// _priceAttributeParams[0].commodityPic = ttt
// }else{
let ttt = _priceAttributeParams[index].commodityPic.filter(_ => _.status === 'done')
_priceAttributeParams[index].commodityPic = ttt
setCommonImageList(ttt)
// }
let ttt = _priceAttributeParams[index].commodityPic.filter(_ => _.status === 'done')
_priceAttributeParams[index].commodityPic = ttt
setCommonImageList(ttt)
}
console.log(_priceAttributeParams, '图片更改之后数据')
setPriceAttributeParamsByRender(_priceAttributeParams)
......@@ -187,10 +166,7 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
const onChangeSetImageType = (e) => {
setSetImageType(e.target.value)
setIsAllAttributePic(e.target.value)
// if(e.target.value)
// clickItemTab(-1)
// else
clickItemTab(0)
clickItemTab(0)
// 切换 清空图片数组
let _priceAttributeParams = [...priceAttributeParamsByRender]
_priceAttributeParams.map(item => {
......@@ -225,7 +201,7 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
<li key={index} className={defaultChecked == index ? styles.activedLi : ""} onClick={()=>clickItemTab(index)}>
<span>
{
item.attributeAndValueList.map((_item, _index)=>_item.value).join('/')
item.attributeAndValueList.map((_item, _index)=>_item.customerAttributeValue.value).join('/')
}
</span>
</li>
......
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