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

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

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

    componentWillUnmount() {
        this.props.hrmUsedemand.resetTable();
    }

    reRenderColumns = (columns) => {
        columns.map((c, i) => {
            if (c.dataIndex == 'count') { //TODO
                c.render = (t, r) => {
                    const {
                        count,
                        total
                    } = r;

                    return (<WeaProgress ecId={`${this && this.props && this.props.ecId || ''}_WeaProgress@ql62j4@${i}`} 
                                percent={count/total*100} 
                                format={() => count}
                                strokeColor={'#6FBCEA'}
                            />)
                }
            }
        })
    }

    render() {
        const {
            hrmUsedemand,
        } = this.props, {
            table,
        } = hrmUsedemand, {
            tableStore
        } = table;

        return (
            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@7dfr7d`} 
                comsWeaTableStore={tableStore}
                hasOrder={true}
                needScroll={true}
                getColumns={this.reRenderColumns}
            />
        )

    }
}