import {
	observer
} from 'mobx-react';
import {
	WeaTableNew
} from 'comsMobx';
import {
	WeaInputNumber
} from 'ecCom';
const WeaTable = WeaTableNew.WeaTable;

@observer
export default class Table extends React.Component {
	constructor(props) {
		super(props);
	}

	reRenderColumns = (columns) => {
		const {
			store
		} = this.props
		const {
			onDsporderChange
		} = store;

		columns.map((c, i) => {
			if (c.dataIndex === 'dsporder') {
				c.render = function(text, record) {
					const {
						randomFieldId,
						dsporder,
					} = record;

					return (
						<WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@1s2o1q@${i}`}
				            defaultValue = {dsporder}
				            onChange = {val => onDsporderChange(val,randomFieldId)}
          				/>
					)
				}
			}
		});
	}

	onOperatesClick = (record, rIndex, operate) => {
		const {
			store
		} = this.props
		const {
			randomFieldId
		} = record, {
			index
		} = operate;

		const {
			del,
		} = store;

		if (index === '0') {
			del(randomFieldId);
		}
	}

	render() {
		const {
			store
		} = this.props, {
			TABLE,
			table
		} = store;

		return (
			<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@ert152`} 
				{...TABLE}
				{...table}
				scroll={{y:300}}
				getColumns={this.reRenderColumns}
				onOperatesClick={this.onOperatesClick}
			/>
		);
	}
}