1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React, {PureComponent} from "react";
import {InputNumber, Select, Table} from "antd";
import Input from "antd/es/input";
const Option = Select.Option;
class SkuInputNumber extends PureComponent {
handleChange = value => {
// debugger;
const { dispatch, index, dataIndex } = this.props;
if (dataIndex === 'price') {
dispatch({
type: 'productSpuAddOrUpdate/inputSkuPrice',
payload: {
index: index,
price: value
},
});
} else if (dataIndex === 'quantity') {
dispatch({
type: 'productSpuAddOrUpdate/inputSkuQuantity',
payload: {
index: index,
quantity: value
},
});
}
}
render() {
const { value } = this.props;
return <InputNumber placeholder="请输入" value={value} onChange={this.handleChange} />
}
}
export default class ProductSkuAddOrUpdateTable extends PureComponent {
render() {
let that = this;
// debugger;
// console.log('ProductSkuAddOrUpdateTable');
const {attrTree, skus, dispatch} = this.props;
// 排除空选项的规格
let newAttrTree = [];
for (let i in attrTree) {
let attr = attrTree[i];
if (attr && attr.values && attr.values.length > 0) {
newAttrTree.push(attr);
}
}
let columns = [];
for (let i in newAttrTree) {
let attr = newAttrTree[i];
columns.push({
title: attr.name,
dataIndex: 'attrs[i]',
render(value, record) {
return record.attrs[i].name;
}
})
}
columns.push({
title: '价格',
dataIndex: 'price',
render(value, record, index) {
let props = {
record: record,
index: index,
dispatch: dispatch,
dataIndex: 'price',
value: record.price,
};
return <SkuInputNumber {...props} />;
}
});
columns.push({
title: '库存',
dataIndex: 'quantity',
render(value, record, index) {
let props = {
record: record,
index: index,
dispatch: dispatch,
dataIndex: 'quantity',
value: record.quantity,
};
return <SkuInputNumber {...props} />;
}
});
return <Table columns={columns} dataSource={skus} rowKey="index" pagination={false} />;
// return <div />;
}
}