import React, {
	Component
} from 'react';
import {
	observer
} from 'mobx-react';
import {
	WeaYear,
	WeaNewScroll,
	WeaDialog
} from 'ecCom';
import {
	WeaTableNew
} from 'comsMobx';
import AddData from './AddData';
const WeaTable = WeaTableNew.WeaTable;

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

	componentDidMount() {}

	componentWillReceiveProps(nextProps) {}

	openDialog = id => {
		const {
			store
		} = this.props;
		store.create({
			id
		})
	}

	doDel = id => {
		const {
			store
		} = this.props;
		store.remove({
			id: id
		});
	}

	onOperatesClick = (record, index, operate) => {
		const {
			store
		} = this.props;
		const func = operate.href ? operate.href.split(':')[1].split('(')[0] : '';
		const id = record.id ? record.id : '';
		if(func === 'onLog')
			store.showLog({logSmallType: store.logTypeDef.HRM_ENGINE_PUBLIC, targetId: id}); //日志
		else
			this[func] && this[func](id);
	}

	render() {
		const {
			store
		} = this.props;
		const {
			displayType,
			currDate,
			yearDateCellRender,
			onDateSelect,
			calendarData,
			table,
		} = store;

		return (
			<div className='dataList'>
				{
					displayType === 'calendar' ?
					<WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@9hgjbt`} height={'100%'}>
						<WeaYear ecId={`${this && this.props && this.props.ecId || ''}_WeaYear@li76pm`} 
							value={currDate}
				            dateCellRender={yearDateCellRender}
				            onDateSelect={onDateSelect}/>
		            </WeaNewScroll>
					:
					<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@8xfyn3`} needScroll={true} hasOrder={true} comsWeaTableStore={table} onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}/>
				}
				<AddData ecId={`${this && this.props && this.props.ecId || ''}_AddData@emjb0j`} store={store}/>
			</div>
		)
	}
}