|
@@ -20,15 +20,6 @@ const options = [{
|
|
}];
|
|
}];
|
|
|
|
|
|
export default class RBSingleSelectTable extends PureComponent {
|
|
export default class RBSingleSelectTable extends PureComponent {
|
|
- constructor(props) {
|
|
|
|
- super(props);
|
|
|
|
- this.state = {
|
|
|
|
- selectRowKey: props.value,
|
|
|
|
- searchSelectKey: 'code',
|
|
|
|
- searchInputValue: '',
|
|
|
|
- selectRowName: props.currentName,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
static propTypes = {
|
|
static propTypes = {
|
|
dataSource: PropTypes.array,
|
|
dataSource: PropTypes.array,
|
|
loading: PropTypes.bool,
|
|
loading: PropTypes.bool,
|
|
@@ -41,50 +32,24 @@ export default class RBSingleSelectTable extends PureComponent {
|
|
columns: [],
|
|
columns: [],
|
|
pagination: {},
|
|
pagination: {},
|
|
};
|
|
};
|
|
|
|
+ constructor(props) {
|
|
|
|
+ super(props);
|
|
|
|
+ this.state = {
|
|
|
|
+ selectRowKey: props.value,
|
|
|
|
+ searchSelectKey: 'code',
|
|
|
|
+ searchInputValue: '',
|
|
|
|
+ selectRowName: props.currentName,
|
|
|
|
+ };
|
|
|
|
+ }
|
|
componentWillReceiveProps(nextProps) {
|
|
componentWillReceiveProps(nextProps) {
|
|
- let stateProps = {};
|
|
|
|
|
|
+ const stateProps = {};
|
|
if (nextProps.value && (nextProps.value !== this.props.value)) {
|
|
if (nextProps.value && (nextProps.value !== this.props.value)) {
|
|
stateProps.selectRowKey = nextProps.value;
|
|
stateProps.selectRowKey = nextProps.value;
|
|
}
|
|
}
|
|
if (nextProps.currentName && (nextProps.currentName !== this.props.currentName)) {
|
|
if (nextProps.currentName && (nextProps.currentName !== this.props.currentName)) {
|
|
stateProps.selectRowName = nextProps.currentName;
|
|
stateProps.selectRowName = nextProps.currentName;
|
|
}
|
|
}
|
|
- this.setState({...stateProps});
|
|
|
|
- }
|
|
|
|
- handleSelectChange = (value) => {
|
|
|
|
- this.setState({ searchSelectKey: value });
|
|
|
|
- }
|
|
|
|
- handleInputChange = (e) => {
|
|
|
|
- this.setState({ searchInputValue: e.target.value });
|
|
|
|
- }
|
|
|
|
- handleFilterOperation = (kv) => {
|
|
|
|
- const { searchSelectKey, searchInputValue } = this.state;
|
|
|
|
- this.props.onFilterClick({
|
|
|
|
- [searchSelectKey]: searchInputValue,
|
|
|
|
- ...kv,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- handleOnRowClick = (record) => {
|
|
|
|
- this.setState({
|
|
|
|
- selectRowKey: record.key,
|
|
|
|
- selectRowName: record.name,
|
|
|
|
- });
|
|
|
|
- if (this.props.onChange) {
|
|
|
|
- this.props.onChange(record.key);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- handleSearchBtnClick = () => {
|
|
|
|
- this.handleFilterOperation();
|
|
|
|
- }
|
|
|
|
- handleTableChange = (pagination) => {
|
|
|
|
- const { current } = pagination;
|
|
|
|
- this.handleFilterOperation({ pageNo: current });
|
|
|
|
- }
|
|
|
|
- handleListPageChange = (page, pageSize) => {
|
|
|
|
- this.handleFilterOperation({
|
|
|
|
- pageSize,
|
|
|
|
- pageNo: page,
|
|
|
|
- });
|
|
|
|
|
|
+ this.setState({ ...stateProps });
|
|
}
|
|
}
|
|
getListHeader = () => {
|
|
getListHeader = () => {
|
|
const { pagination } = this.props;
|
|
const { pagination } = this.props;
|
|
@@ -93,7 +58,7 @@ export default class RBSingleSelectTable extends PureComponent {
|
|
pageSize: pagination.pageSize,
|
|
pageSize: pagination.pageSize,
|
|
total: pagination.totalSize,
|
|
total: pagination.totalSize,
|
|
onChange: this.handleListPageChange,
|
|
onChange: this.handleListPageChange,
|
|
- showTotal: (total) => `共 ${total} 条`,
|
|
|
|
|
|
+ showTotal: total => `共 ${total} 条`,
|
|
};
|
|
};
|
|
return (
|
|
return (
|
|
<div className={styles.header}>
|
|
<div className={styles.header}>
|
|
@@ -152,11 +117,46 @@ export default class RBSingleSelectTable extends PureComponent {
|
|
</span>
|
|
</span>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+ handleSelectChange = (value) => {
|
|
|
|
+ this.setState({ searchSelectKey: value });
|
|
|
|
+ }
|
|
|
|
+ handleInputChange = (e) => {
|
|
|
|
+ this.setState({ searchInputValue: e.target.value });
|
|
|
|
+ }
|
|
|
|
+ handleFilterOperation = (kv) => {
|
|
|
|
+ const { searchSelectKey, searchInputValue } = this.state;
|
|
|
|
+ this.props.onFilterClick({
|
|
|
|
+ [searchSelectKey]: searchInputValue,
|
|
|
|
+ ...kv,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ handleOnRowClick = (record) => {
|
|
|
|
+ this.setState({
|
|
|
|
+ selectRowKey: record.key,
|
|
|
|
+ selectRowName: record.name,
|
|
|
|
+ });
|
|
|
|
+ if (this.props.onChange) {
|
|
|
|
+ this.props.onChange(record.key);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ handleSearchBtnClick = () => {
|
|
|
|
+ this.handleFilterOperation();
|
|
|
|
+ }
|
|
|
|
+ handleTableChange = (pagination) => {
|
|
|
|
+ const { current } = pagination;
|
|
|
|
+ this.handleFilterOperation({ pageNo: current });
|
|
|
|
+ }
|
|
|
|
+ handleListPageChange = (page, pageSize) => {
|
|
|
|
+ this.handleFilterOperation({
|
|
|
|
+ pageSize,
|
|
|
|
+ pageNo: page,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
render() {
|
|
render() {
|
|
const { columns, dataSource, loading } = this.props;
|
|
const { columns, dataSource, loading } = this.props;
|
|
- const addColumnOnFirst = (columns) => {
|
|
|
|
- const newColumns = [...columns];
|
|
|
|
|
|
+ const addColumnOnFirst = (cols) => {
|
|
|
|
+ const newColumns = [...cols];
|
|
newColumns.unshift({
|
|
newColumns.unshift({
|
|
key: '-1',
|
|
key: '-1',
|
|
dataIndex: 'key',
|
|
dataIndex: 'key',
|
|
@@ -168,15 +168,15 @@ export default class RBSingleSelectTable extends PureComponent {
|
|
checked={this.state.selectRowKey === text}
|
|
checked={this.state.selectRowKey === text}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
- }
|
|
|
|
|
|
+ },
|
|
});
|
|
});
|
|
return newColumns;
|
|
return newColumns;
|
|
- }
|
|
|
|
|
|
+ };
|
|
const onRowClick = (record) => {
|
|
const onRowClick = (record) => {
|
|
return {
|
|
return {
|
|
onClick: () => this.handleOnRowClick(record),
|
|
onClick: () => this.handleOnRowClick(record),
|
|
};
|
|
};
|
|
- }
|
|
|
|
|
|
+ };
|
|
return (
|
|
return (
|
|
<Table
|
|
<Table
|
|
bordered={false}
|
|
bordered={false}
|