OrderItem.js 1.3 KB
Newer Older
1 2
import React from 'react';
import { Select, Input, InputNumber, Button } from 'antd';
徐立's avatar
徐立 committed
3 4 5
const Option = Select.Option;

export default class OrderItem extends React.Component {
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
	constructor(props) {
		super(props);
		const value = props.value || {};
		this.state = {
			stringX: value.stringX,
		};
	}

	componentWillReceiveProps(nextProps) {
		// Should be a controlled component.
		if ('value' in nextProps) {
			const value = nextProps.value;
			this.setState(value);
		}
	}

	triggerChange = (changedValue) => {
		// Should provide an event to pass value to Form.
		const onChange = this.props.onChange;
		if (onChange) {
			onChange(Object.assign({}, this.state, changedValue));
		}
	};

	changeStringX = (e) => {
		if (!('value' in this.props)) {
			this.setState({ stringX: e });
		}
		this.triggerChange({ stringX: e });
	};
徐立's avatar
徐立 committed
36

37 38
	render() {
		const { stringX } = this.state;
徐立's avatar
徐立 committed
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
		return (
			<div>
				<span style={{ padding: '0px 10px' }}>
					<Select onChange={this.changeStringX} value={stringX} style={{ width: 200 }}>
						<Option value="desc" key="desc">
							降序
						</Option>
						<Option value="asc" key="asc">
							升序
						</Option>
					</Select>
				</span>
				<span style={{ paddingLeft: 100 }}>
					<Button type="danger" onClick={this.props.deleteOrder}>
						删除
					</Button>
				</span>
			</div>
		);
	}
徐立's avatar
徐立 committed
60
}