提交 f1c0ad15 作者: 龚洪江

修复:商城商品sku新增,编辑问题修复

上级 fc0118ea
...@@ -20,6 +20,7 @@ const EditableCell: React.FC< ...@@ -20,6 +20,7 @@ const EditableCell: React.FC<
uploadSuccess?: (record: any, result: any) => void; uploadSuccess?: (record: any, result: any) => void;
rules?: any; rules?: any;
maxLength?: number; maxLength?: number;
placeholder?: string;
} }
> = ({ > = ({
editing, editing,
...@@ -34,15 +35,16 @@ const EditableCell: React.FC< ...@@ -34,15 +35,16 @@ const EditableCell: React.FC<
children, children,
rules, rules,
maxLength, maxLength,
placeholder,
...restProps ...restProps
}) => { }) => {
const inputNode = () => { const inputNode = () => {
switch (inputType) { switch (inputType) {
case 'number': case 'number':
return <InputNumber placeholder={`请输入${title}`} maxLength={maxLength} />; return <InputNumber placeholder={`请输入${placeholder || title}`} maxLength={maxLength} />;
case 'select': case 'select':
return ( return (
<Select placeholder={`请选择${title}`} style={{ textAlign: 'start' }}> <Select placeholder={`请选择${placeholder || title}`} style={{ textAlign: 'start' }}>
{selectOption && {selectOption &&
selectOption.map((v) => ( selectOption.map((v) => (
<Select.Option value={v.id} key={v.id}> <Select.Option value={v.id} key={v.id}>
...@@ -73,9 +75,15 @@ const EditableCell: React.FC< ...@@ -73,9 +75,15 @@ const EditableCell: React.FC<
</Radio.Group> </Radio.Group>
); );
case 'textArea': case 'textArea':
return <Input.TextArea placeholder={`请输入${title}`} maxLength={maxLength} showCount />; return (
<Input.TextArea
placeholder={`请输入${placeholder || title}`}
maxLength={maxLength}
showCount
/>
);
default: default:
return <Input placeholder={`请输入${title}`} maxLength={maxLength} />; return <Input placeholder={`请输入${placeholder || title}`} maxLength={maxLength} />;
} }
}; };
return ( return (
......
...@@ -98,6 +98,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -98,6 +98,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
rules?: any; rules?: any;
maxLength?: number; maxLength?: number;
children?: any; children?: any;
placeholder?: string;
})[] })[]
>([ >([
{ {
...@@ -113,19 +114,27 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -113,19 +114,27 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
inputType: 'uploader', inputType: 'uploader',
}, },
{ {
title: 'sku编号', title: 'sku编号(料号)',
align: 'center', align: 'center',
editable: true, editable: true,
dataIndex: 'skuNo', dataIndex: 'skuNo',
maxLength: 30, maxLength: 30,
width: '15%',
}, },
{ {
title: '销售价', title: (
<div>
<span style={{ color: 'red' }}>*</span>
<span>销售价</span>
</div>
),
align: 'center', align: 'center',
editable: true, editable: true,
dataIndex: 'salePrice', dataIndex: 'salePrice',
rules: [{ required: true, validator: salePriceValidator }], rules: [{ required: true, validator: salePriceValidator }],
inputType: 'number', inputType: 'number',
onHeaderCell: () => ({ className: 'custom-header-cell' }),
placeholder: '销售价',
}, },
{ {
title: '渠道价', title: '渠道价',
...@@ -160,6 +169,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -160,6 +169,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
inputType: col.inputType, inputType: col.inputType,
uploadSuccess: col.inputType === 'uploader' ? uploadSuccess : undefined, uploadSuccess: col.inputType === 'uploader' ? uploadSuccess : undefined,
rules: col.rules, rules: col.rules,
placeholder: col.placeholder,
}), }),
}; };
}); });
...@@ -196,6 +206,8 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -196,6 +206,8 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
}; };
// 删除规格项目 // 删除规格项目
const deleteSpecificationClick = (index: number) => { const deleteSpecificationClick = (index: number) => {
console.log('数据-->', specificationFormList[index]);
form.setFieldValue(specificationFormList[index].name, undefined);
specificationFormList.splice(index, 1); specificationFormList.splice(index, 1);
combineSpecificationValue(); combineSpecificationValue();
setSpecificationFormList([...specificationFormList]); setSpecificationFormList([...specificationFormList]);
...@@ -205,9 +217,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -205,9 +217,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
specificationFormList[index].optionList = e.target.value specificationFormList[index].optionList = e.target.value
? [{ label: e.target.value, value: e.target.value }] ? [{ label: e.target.value, value: e.target.value }]
: []; : [];
const obj = Object.create(null); form.setFieldValue(specificationFormList[index].name, e.target.value);
obj[specificationFormList[index].name] = e.target.value || undefined;
form.setFieldsValue(obj);
setSpecificationFormList([...specificationFormList]); setSpecificationFormList([...specificationFormList]);
}; };
//规格值添加 //规格值添加
...@@ -248,25 +258,29 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -248,25 +258,29 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
const combineSpecificationValue = () => { const combineSpecificationValue = () => {
let combineSpecificationList: any = []; let combineSpecificationList: any = [];
let tableDataList: any = []; let tableDataList: any = [];
if (specificationFormList.length > 1) { //过滤规格值为空的
const combineList = specificationFormList.reduce((pre: any, cur, currentIndex) => { const filterSpecificationFormList = specificationFormList.filter(
(v) => v.specificationValueList.length,
);
if (filterSpecificationFormList.length > 1) {
const combineList = filterSpecificationFormList.reduce((pre: any, cur, currentIndex) => {
// 首次组合两个数据 // 首次组合两个数据
if (currentIndex === 0 && specificationFormList.length > 1) { if (currentIndex === 0 && filterSpecificationFormList.length > 1) {
combineSpecificationList = combineEvent( combineSpecificationList = combineEvent(
cur.specificationValueList, cur.specificationValueList,
specificationFormList[currentIndex + 1].specificationValueList, filterSpecificationFormList[currentIndex + 1].specificationValueList,
); );
//二维数组拆分为对象 //二维数组拆分为对象
combineSpecificationList = getCombineObj(combineSpecificationList); combineSpecificationList = getCombineObj(combineSpecificationList);
// 两个数据以上的组合 // 两个数据以上的组合
} else if ( } else if (
currentIndex < specificationFormList.length - 1 && currentIndex < filterSpecificationFormList.length - 1 &&
specificationFormList[currentIndex + 1].specificationValueList.length filterSpecificationFormList[currentIndex + 1].specificationValueList.length
) { ) {
// 上一次的组合作为下一次组合的参数 // 上一次的组合作为下一次组合的参数
combineSpecificationList = combineEvent( combineSpecificationList = combineEvent(
combineSpecificationList, combineSpecificationList,
specificationFormList[currentIndex + 1].specificationValueList, filterSpecificationFormList[currentIndex + 1].specificationValueList,
); );
//二维数组拆分为对象 //二维数组拆分为对象
combineSpecificationList = getCombineObj(combineSpecificationList); combineSpecificationList = getCombineObj(combineSpecificationList);
...@@ -291,9 +305,9 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -291,9 +305,9 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
}); });
return pre; return pre;
}, []); }, []);
} else { } else if (filterSpecificationFormList.length === 1) {
//当存在一个规格项时 //当存在一个规格项时
tableDataList = specificationFormList[0].specificationValueList.map((v) => { tableDataList = filterSpecificationFormList[0].specificationValueList.map((v) => {
const obj = Object.create(null); const obj = Object.create(null);
obj['name1'] = v.name; obj['name1'] = v.name;
obj['specificationName1'] = v.specificationName; obj['specificationName1'] = v.specificationName;
...@@ -306,10 +320,6 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -306,10 +320,6 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
}); });
} }
if (tableDataList.length) { if (tableDataList.length) {
//过滤规格值为空的
const filterSpecificationFormList = specificationFormList.filter(
(v) => v.specificationValueList.length,
);
setTableFormDefault(tableDataList); setTableFormDefault(tableDataList);
mergeTableRow(filterSpecificationFormList); mergeTableRow(filterSpecificationFormList);
} }
...@@ -391,11 +401,11 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -391,11 +401,11 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
form form
.validateFields() .validateFields()
.then(() => { .then(() => {
const specificationFormItemIndex = specificationFormList.findIndex( const specificationFormItem = specificationFormList.find(
(v) => !v.specificationValueList.length, (v) => !v.specificationValueList.length,
); );
if (specificationFormItemIndex !== -1) { if (specificationFormItem) {
return message.warning(`请为规格项${specificationFormItemIndex}添加规格值`); reject(`请为规格项${specificationFormItem.optionList[0].value}添加规格值`);
} else { } else {
//规格项数据转化 //规格项数据转化
const specAttrList = specificationFormList.map((v) => ({ const specAttrList = specificationFormList.map((v) => ({
...@@ -580,6 +590,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => { ...@@ -580,6 +590,7 @@ const SkuInfo = forwardRef<any, selfProps>(({ goodsDetailsInfo }, ref) => {
<Input <Input
placeholder='请输入规格值,按回车键完成' placeholder='请输入规格值,按回车键完成'
onPressEnter={(e) => specificationValuePressEnter(e, index)} onPressEnter={(e) => specificationValuePressEnter(e, index)}
maxLength={30}
/> />
) : ( ) : (
<Button <Button
......
...@@ -74,8 +74,8 @@ const GoodsAddOrEditOrDetail = () => { ...@@ -74,8 +74,8 @@ const GoodsAddOrEditOrDetail = () => {
.then(() => { .then(() => {
setTabSelectKeys((Number(tabSelectKeys) + 1).toString()); setTabSelectKeys((Number(tabSelectKeys) + 1).toString());
}) })
.catch(() => { .catch((error: any) => {
message.warning('请添加规格'); message.warning(error?.errorFields?.[0].errors[0] || error);
}); });
break; break;
case '3': case '3':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论