import React, {Component} from 'react';
import {observer} from 'mobx-react';
import {WeaRightMenu} from 'ecCom';
import {
	WeaTableNew
} from 'comsMobx';
import classnames from 'classnames';
import findIndex from 'lodash/findIndex';
import Edit from './Edit';
const {
	WeaTable
} = WeaTableNew;

@observer
export default class Content extends Component{
    doEdit = id => this.props.store.doEdit(id, '1');

    personalizedEdit = id => this.props.store.doEdit(id, '2');

    doDelete = id => this.props.store.doDelete({ids: id});

    showLog = id => this.props.store.showLog({logSmallType: this.props.store.logTypeDef.HRM_ENGINE_SHIFTMANAGER, targetId: id}); //日志

    onOperatesClick = (record, index, operate) => {
		const func = operate.href ? operate.href.split(':')[1].split('(')[0] : '';
		const id = record.id ? record.id : '';
		this[func] && this[func](id);
	}

	renderCol = (cols) => {
        const idx = findIndex(cols, item => item.dataIndex === 'serial');
        idx != -1 && (cols[idx].render = (text, record) => {
			return <a onClick={() => this.doEdit(record.id)}>{record.serialspan}</a>
		});
    }
    
    render(){
        const {
			store
        } = this.props;
        const className = classnames({
			['tabPane']: true,
			['tabPane-include']: store.containerInitFinished.detachable
		})
        
        return (
            <div className={className}>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@6y6ajw`} datas={this.props.rightMenu}>
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@u2sw59`}
                        comsWeaTableStore={store.table}
                        hasOrder={true}
                        needScroll={true}
                        onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}
                        getColumns={cols => this.renderCol(cols)}
                    />
                </WeaRightMenu>
                <Edit ecId={`${this && this.props && this.props.ecId || ''}_Edit@q9rrik`} store={store} />
            </div>
        )
    }
}