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

@inject('hrmRecruitInfo') //todo
@observer
export default class MainTable extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.props.hrmRecruitInfo.getTableInfo();
    }

    componentDidUpdate(prevProps, prevState) {
        const {
            setSelectedRowKeys,
            hrmRecruitInfo
        } = this.props, {
            main
        } = hrmRecruitInfo, {
            id
        } = main;

        id && setSelectedRowKeys([]);
    }

    reRenderColumns = (columns) => {
        const {
            hrmRecruitInfo
        } = this.props, {
            openDialog,
        } = hrmRecruitInfo;

        columns.map(c => {
            if (c.dataIndex == 'careername') { //todo
                c.render = (t, r) => {
                    const {
                        randomFieldId,
                        careername,
                        careernamespan
                    } = r;
                    return <a onClick={() => openDialog('1',randomFieldId)}>{careernamespan}</a>
                }
            }
        })
    }

    render() {
        const {
            hrmRecruitInfo,
            setSelectedRowKeys
        } = this.props, {
            main,
            mainTable,
            onOperatesClick,
        } = hrmRecruitInfo, {
            tableStore,
        } = mainTable, {
            id,
        } = main;

        return (
            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@15gq6x`} 
                comsWeaTableStore={tableStore}
                hasOrder={true}
                needScroll={true}
                rowSelection={id && {
                    onChange: selectedRowKeys => setSelectedRowKeys(selectedRowKeys)
                }}
                getColumns={columns => this.reRenderColumns(columns)}
                onOperatesClick={(record, rowIndex, operate) => onOperatesClick(record, rowIndex, operate)}
            />
        )

    }
}