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

fix:修改渠道商品异常处理

parent e6554d4b
......@@ -60,7 +60,7 @@ const SetPrice:React.FC<IProps> = (props) => {
const [isBatchSetting, setIsBatchSetting] = useState<boolean>(false)
const [curretSetPriceRow, setCurrentSetPriceRow] = useState<any>()
const [ladderPrice, setLadderPrice] = useState(false)
const [loading, setLoading] = useState<boolean>(false)
const { ChannelProudctStore } = store
const {
......@@ -87,6 +87,7 @@ const SetPrice:React.FC<IProps> = (props) => {
// 获取商品规格列表
const fetchSpecData = (params?: any) => {
setLoading(true)
PublicApi.getProductChannelCommodityGetCommodityUnitPrice({id: productSelectRowInStore.id + '', source: selectedSource + ''}).then(res => {
const { data } = res
setOriginTableData(data)
......@@ -162,6 +163,7 @@ const SetPrice:React.FC<IProps> = (props) => {
})
})
setSpecTableData(_tableData)
setLoading(false)
}
const rowSelectionSetSpec = {
......@@ -259,8 +261,13 @@ const SetPrice:React.FC<IProps> = (props) => {
let _data = selectData.map(item => {
let price = priceTableData.filter(_i => _i.id === item.id)[0]['单价']
delete item.id
return {...item, unitPrice: price}
let params: any = {
...item,
unitPrice: price,
commodityUnitPriceAndPicId: item.id
}
delete params.id
return params
})
setTableDataInSetPrice(_data) // 设置传输数据
......@@ -515,6 +522,7 @@ const SetPrice:React.FC<IProps> = (props) => {
dataSource={specTableData}
columns={specColumn}
rowKey="id"
loading={loading}
rowSelection={{
type: 'checkbox',
...rowSelectionSetSpec,
......
......@@ -150,17 +150,16 @@ const ProductImageForm: React.FC<Iprops> = (props) => {
const handleChange = ({ file, fileList }, index) => {
let _priceAttributeParams = [...priceAttributeParamsByRender]
// console.log(_priceAttributeParams, index, '图片更改初始数据')
console.log(fileList, file?.response?.data, '响应')
setCommonImageList(fileList)
if(file?.response?.data){ // 服务端是否响应正常url字符
// if(file?.response?.data){ // 服务端是否响应正常url字符
_priceAttributeParams[index].commodityPic = fileList
}
// }
if(!file?.status && file?.status !== 'done'){
let ttt = _priceAttributeParams[index].commodityPic.filter(_ => _.status === 'done')
_priceAttributeParams[index].commodityPic = ttt
setCommonImageList(ttt)
}
// console.log(_priceAttributeParams, '图片更改之后数据')
setPriceAttributeParamsByRender(_priceAttributeParams)
setProductAttributeAndImageParams(_priceAttributeParams)
}
......
......@@ -7,9 +7,7 @@ import {
SaveOutlined,
SettingOutlined,
MinusOutlined,
CodeSandboxCircleFilled,
} from '@ant-design/icons'
import { ColumnType } from 'antd/lib/table/interface';
import ReutrnEle from '@/components/ReturnEle';
import styles from './index.less'
......@@ -56,6 +54,8 @@ const ModifyDirectChannel:React.FC<{}> = () => {
const [submitParams, setSubmitParams] = useState<any>()
const flagRef = useRef(false) // 价格数据是否被模态框替换
const priceTypeRef = useRef<number>()
const [originHasIds, setOriginHasIds] = useState<number[]>([])
const [loading, setLoading] = useState<boolean>(false)
useEffect(() => {
......@@ -69,6 +69,8 @@ const ModifyDirectChannel:React.FC<{}> = () => {
priceTypeRef.current = data.channelCommodity.commodity.priceType
formPrice.setFieldsValue({isMemberPrice: data?.isMemberPrice})
structureTable(data.unitPriceAndPicList, data.channelCommodity.commodity, true) // 初始已有规格
let hasIds = data.unitPriceAndPicList.map(item => item.id)
setOriginHasIds(hasIds)
}
})
}, [])
......@@ -82,23 +84,27 @@ const ModifyDirectChannel:React.FC<{}> = () => {
}, [specColumn])
useEffect(() => {
setSelectedSpecRowKeys([])
if(visibleAddSpec)
fetchSpecData()
}, [visibleAddSpec])
// 获取商品规格列表
const fetchSpecData = () => {
setLoading(true)
PublicApi.getProductChannelCommodityGetCommodityUnitPriceByChannel({id: history.location.query.id}).then(res => {
const { data } = res
setOriginTableData(data)
if(data.length > 0)
structureTable(data)
// let hasIds = priceTableData.map(item => item.id)
// setOriginHasIds(hasIds)
let _data = data.filter(item => !originHasIds.includes(item.id))
setOriginTableData(_data)
if(_data.length > 0)
structureTable(_data)
})
}
/** name<string>商品名称 noModal<boolean>不执行规格modla的操作 */
const structureTable = (data: any, commodity?: any, noModal?: boolean) => {
console.log(data,'structureTableData')
// 构建规格弹框table 列columns
let col: any = []
let temp: any = []
......@@ -113,7 +119,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
{
title: 'GoodsId',
dataIndex: 'goodsId',
key: 'id',
key: 'goodsId',
className: 'commonHide'
},
{
......@@ -123,6 +129,12 @@ const ModifyDirectChannel:React.FC<{}> = () => {
className: 'commonHide'
},
{
title: 'commodityUnitPriceAndPicId',
dataIndex: 'commodityUnitPriceAndPicId',
key: 'commodityUnitPriceAndPicId',
className: 'commonHide'
},
{
title: '商品名称',
dataIndex: '商品名称',
key: '商品名称'
......@@ -156,6 +168,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
"id": item.id, // 行数据id
"goodsId": item.goods?.id || '', // 货品ID 可能为null
"索引": index,
'commodityUnitPriceAndPicId': item?.commodityUnitPriceAndPicId,
"商品名称": commodity?.name || channelDetails?.channelCommodity?.commodity?.name,
"对应货品": item.goods?.name || '',
...temp,
......@@ -167,6 +180,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
}else{
setSpecTableData(_tableData)
}
setLoading(false)
}
const rowSelectionSetSpec = {
......@@ -194,7 +208,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
})
setPriceColumn(tempColumn)
if(!noModal){
setPriceTableData(selectSpecRow)
setPriceTableData([...priceTableData, ...selectSpecRow])
setVisibleAddSpec(false)
flagRef.current = true
}
......@@ -207,6 +221,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
const clickSetPrice = (record: any) => {
setIsBatchSetting(false) // 点击行操作批量置为false
console.log(record, 'record')
setCurrentSetPriceRow(record)
setModifyModal(true)
setPriceForm.resetFields() // 先清空
......@@ -241,28 +256,28 @@ const ModifyDirectChannel:React.FC<{}> = () => {
}
let _row = { ...curretSetPriceRow, 单价: _priceRange }
let newTabeData = [...priceTableData]
let newTabeData = [...priceTableData], _newTabeData
if(isBatchSetting){ // 判断是否批量设置价格
newTabeData.map(_item => _item['单价'] = _priceRange)
_newTabeData = newTabeData.map(item => {
item['单价'] = _priceRange
return item
})
}else{
newTabeData[curretSetPriceRow['索引']] = _row
_newTabeData = newTabeData.map(item => {
if(item.id === curretSetPriceRow.id){
return _row
} else return item
})
// newTabeData[curretSetPriceRow['索引']] = _row
}
setPriceTableData(newTabeData)
console.log(curretSetPriceRow, _row, _newTabeData, newTabeData, 'option')
setPriceTableData(_newTabeData)
constructedPrarams()
})
}
/** 生成传输数据 */
const constructedPrarams = () => {
// 从原data中过滤出选择的数据,覆写价格
// let ids = priceTableData.map(item => item.id)
// let selectData = originTableData.filter(item => { return ids.includes(item.id) })
// let _data = selectData.map(item => {
// let price = priceTableData.filter(_i => _i.id === item.id)[0]['单价']
// return {...item, unitPrice: price}
// })
// 重新构建参数
let _data: any[] = []
let _priceTableData = JSON.parse(JSON.stringify(priceTableData))
......@@ -271,6 +286,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
_temp.unitPrice = item['单价']
_temp.goods = { id: item['goodsId'] }
_temp.id = item['id']
_temp.commodityUnitPriceAndPicId = item['commodityUnitPriceAndPicId']
// 移除item行数据的多余字段 余下属性
delete item.goodsId
delete item['索引']
......@@ -278,6 +294,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
delete item['商品名称']
delete item['对应货品']
delete item['单价']
delete item['commodityUnitPriceAndPicId']
let _attributeAndValueList: any[] = []
Object.values(item).map( _ => {
......@@ -293,14 +310,14 @@ const ModifyDirectChannel:React.FC<{}> = () => {
})
setSubmitParams(_data)
// console.log(priceTableData, _priceTableData, _data, 'params')
console.log(priceTableData, _priceTableData, _data, 'params')
}
const clickDelete = (record: any) => {
setPriceTableData(priceTableData => [...priceTableData].filter(item => item.id != record.id))
setSelectedSpecRowKeys(selectedSpecRowKeys => [...selectedSpecRowKeys].filter(item => item != record.id))
// setSelectedSpecRowKeys(selectedSpecRowKeys => [...selectedSpecRowKeys].filter(item => item != record.id))
if(!flagRef.current){
PublicApi.postProductChannelCommodityDeleteChannelCommodityPrice({id: record.id})
PublicApi.postProductChannelCommodityDeleteChannelCommodityPrice({id: record.id},{ctlType: 'none'})
}
}
......@@ -339,16 +356,22 @@ const ModifyDirectChannel:React.FC<{}> = () => {
}
const onSave = () => {
console.log(submitParams ,'提交数据')
setIsDisabledSave(true)
console.log(originHasIds,'originHasIds')
let params: any = {
id: channelDetails.id,
isMemberPrice: formPrice.getFieldValue('isMemberPrice'),
unitPriceAndPicList: submitParams
unitPriceAndPicList: submitParams.map(item => {
if(!originHasIds.includes(item.id)){
item.commodityUnitPriceAndPicId = item.id
delete item.id
}
return item
})
}
PublicApi.postProductChannelCommodityUpdatePriceChannelCommodity(params).then(res => {
setIsDisabledSave(false)
if(res.code)
if(res.code === 1000)
history.goBack()
})
}
......@@ -593,6 +616,7 @@ const ModifyDirectChannel:React.FC<{}> = () => {
dataSource={specTableData}
columns={specColumn}
rowKey="id"
loading={loading}
rowSelection={{
type: 'checkbox',
...rowSelectionSetSpec,
......
......@@ -45,26 +45,26 @@ export const checkRegExp = (str:string, type:string) => {
}
/**
* 区别校验 汉字 和 字符 长度
* @param rule
* @param value 表单输入的值
* @param callback
* @param maxByte:number 最大字符数
*/
export const validatorByte = (rule, value, callback, maxByte: number) => {
try {
if(value){
let str = value
str = str.replace(/[\u4e00-\u9fa5]/g, 'OO')
if(str.length > maxByte)
throw new Error(`最多输入${maxByte}个字符,${Math.floor(maxByte / 2)}个汉字`);
else
callback()
} else {
/**
* 区别校验 汉字 和 字符 长度
* @param rule
* @param value 表单输入的值
* @param callback
* @param maxByte:number 最大字符数
*/
export const validatorByte = (rule, value, callback, maxByte: number) => {
try {
if(value){
let str = value
str = str.replace(/[\u4e00-\u9fa5]/g, 'OO')
if(str.length > maxByte)
throw new Error(`最多输入${maxByte}个字符,${Math.floor(maxByte / 2)}个汉字`);
else
callback()
}
} catch (err) {
callback(err)
} else {
callback()
}
}
\ No newline at end of file
} catch (err) {
callback(err)
}
}
\ 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