提交 f1c0ad15 作者: 龚洪江

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

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