import {
    WeaDialog,
    WeaMoreButton,
} from 'ecCom'

import {
    Button,
} from 'antd'

import {
    WeaTableNew
} from 'comsMobx';

import {
    jumpToHrmCard
} from '../../public/pulic-func';

import {
    i18n
} from '../../public/i18n';

const WeaTable = WeaTableNew.WeaTable;

export default class ImportHistory extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            width: 870,
            height: 510,
        }
    }

    reRenderColumns(c) {
        const {
            jumpToImportResult
        } = this.props;

        c.forEach(item => {
            if (item.dataIndex == 'operator') {
                item.render = function(text, record) {
                    return <span><a onClick={ () => jumpToHrmCard(record.operator)}>{record.operatorspan}</a></span>
                }
            }
            if (item.dataIndex == 'allnum') {
                item.render = function(text, record) {
                    return <span><a onClick={ () => jumpToImportResult(record.randomFieldId)}>{record.allnumspan}</a></span>
                }
            }
        });
    }

    getButtons() {
        const {
            loading,
            importLogQuery
        } = this.props;

        return [
            (<Button type="primary" disabled={loading} onClick={() => importLogQuery()}>{i18n.button.queryImportLog()}</Button>),
            (<WeaMoreButton />)
        ];
    }

    render() {
        const {
            title,
            visible,
            onCancel,
            tableStore,
        } = this.props, {
            width,
            height
        } = this.state;

        return (
            <WeaDialog
                title={title}
                icon="icon-coms-hrm"
                iconBgcolor="#217346"
                visible={visible}
                closable={true}
                hasScroll
                onCancel={() => onCancel()}
                buttons={this.getButtons()}
                style={{width: width, height: height}}
                onChangeHeight={(h) => this.setState({height: h})}
            >
                <WeaTable 
                    comsWeaTableStore={tableStore}
                    hasOrder={true}
                    needScroll={true}
                    scroll={{y: 430}}
                    rowKey={(record,index) => index}
                    getColumns={c => this.reRenderColumns(c)}
                />
            </WeaDialog>
        )
    }
}