import React, {
	Component
} from 'react';
import {
	observer
} from 'mobx-react';
import {
	WeaInput
} from 'ecCom';
import {
	WeaTableNew
} from 'comsMobx';
import {
	message
} from 'antd';
import findIndex from 'lodash/findIndex';
const WeaTable = WeaTableNew.WeaTable;

@observer
export default class DataList extends Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {}

	componentWillReceiveProps(nextProps) {}

	renderCol = (cols) => {
		const {
			store
		} = this.props;
		const {
			onAnnualDayBlur,
			filter,
			renderKeys
		} = store;
		renderKeys.map((key, i) => {
			let idx = findIndex(cols, item => item.dataIndex === key);
			idx != -1 && (cols[idx].render = (text, record) => {
				return <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@wo0p6p@${i}`} value={record[`${key}span`]} onBlur={(val) => onAnnualDayBlur(record.id, {[key]: val}) } />
			});
		})
	}

	render() {
		const {
			store
		} = this.props;
		const {
			table
		} = store;
		return (
			<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@d8wq9n`} comsWeaTableStore={table} needScroll={true} hasOrder={true}
				getColumns={cols => this.renderCol(cols)}
                onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}/>
		)
	}
}