import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaInputNumber,
} from 'ecCom'
import {
	i18n
} from '../../public/i18n';
import {
	WeaTableNew
} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;

@inject('hrmSalaryItemsSet')
@observer
export default class StandardSet extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillUnmount() {
		this.props.hrmSalaryItemsSet.resetStandardSet()
	}

	reRenderColumns = (columns) => {
		columns.map(c => {
			if (c.dataIndex === 'resourcePay') {
				c.render = (text, record, index) => {
					const {
						resourcePayspan,
						randomFieldId,
					} = record;

					return <WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@gvxhge@${index}`} defaultValue={resourcePayspan} precision={2} onChange={cb => this.handleChange(cb,randomFieldId)}/>
				}
			}
		});
	}

	handleChange = (val, id) => {
		this.props.hrmSalaryItemsSet.setPersonalStandardModifyDatas(`${id}_${val}`);
	}

	render() {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			salary,
		} = hrmSalaryItemsSet, {
			tableStore,
		} = salary;

		return (
			<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@frpojm`} 
				comsWeaTableStore={tableStore}
				hasOrder={true}
				needScroll={true}
				scroll={{y: 600}}
				getColumns={columns => this.reRenderColumns(columns)}
			/>
		)


	}
}