import React from 'react';
import HeaderComponent from '../../components/CommonComponent/HeaderComponent/HeaderComponent'
import Button from '../../components/CommonComponent/ButtonComponent/ButtonComponent'
import PopModel from '../../components/CommonComponent/PopupComponent/PopupChildComponent'
require('./index.css');

export default class HomePageContainer extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            text : ''
        }
        this.logout = this.logout.bind(this)
        this.showLogoutPopup = this.showLogoutPopup.bind(this)
    }

    componentWillMount(){
        let text = '';
        let hour = parseInt(new Date().getHours());
        switch (true){
            case hour >= 0 && hour < 11:
                text = '上午好，';
                break;
            case hour >= 11 && hour < 13:
                text = '中午好，';
                break;
            case hour >= 13 && hour < 18:
                text = '下午好，';
                break;
            case hour >= 18 && hour < 24:
                text = '晚上好，';
                break;
        }
        this.setState({
            text:text
        })
    }

    logout(){
        this.props.tempLogout()
    }

    showLogoutPopup(){
        let {showPopup,hidePopup} = this.props;
        let btnDom1 = <Button btnContainer={"headerLogoutBtn backff775c colfff font32 font32 "} key={"headerLogoutBtn1"} text={"确定退出？"} option={this.logout}/>
        let btnDom2 = <Button btnContainer={"headerLogoutBtn btne5 font32"} key={"headerLogoutBtn2"} text={"取消"} option={hidePopup}/>
        let popDom =
            <PopModel popupTitle={"是否退出登录"} classContainer={"headerLogout"}>
                <div className={"icon iconfont icon-exclamation font150 colf5a623"} />
                <div className={"text font40 col000"} style={{lineHeight:'1.6'}}>
                    <p>此步临时添加，可用作测试退出登录</p>
                    <p>重新扫码开门，不必重启服务</p>
                </div>
                <div className={"btn"}>
                    {btnDom1}
                    {btnDom2}
                </div>
            </PopModel>;
        showPopup({popupChild:popDom});
    }

    render(){
        let props = this.props;
        let {headerInfo={}} = props;
        let {taskInfo={}} = headerInfo;
        let marginTop = UTILPATH.getRemByPx(77);
        let marginTop50 = UTILPATH.getRemByPx(50);
        let marginTop20 = UTILPATH.getRemByPx(20);
        let padding = UTILPATH.getRemByPx(8);
        let marginTop160 = UTILPATH.getRemByPx(160);
        let imgStyle =  taskInfo.area ? {marginTop: marginTop160} : {};
        let buttonStyle={background:'#ff775c',margin:"0 auto",marginTop:marginTop};
        return(
            <div>
                <HeaderComponent
                    showHeader={CONFIG.headerStatus[1]}
                    headerInfo={headerInfo}
                    showLogoutPopup={this.showLogoutPopup}
                />
                <div className={"homeContainer"} >
                    <img className={"homeIcon"} style={imgStyle} src={UTILPATH.localImg.homePage} alt=""/>
                    {
                        taskInfo.area ? <div className={'homeWelcom font30 clo333'} style={{marginTop:marginTop50}}>欢迎来到<span className="homeArea font50 colff775c" style={{padding:`0 ${padding}`}}>{taskInfo.area || ''}</span>区</div>
                            : null
                    }
                    <div className={"homeText font42"} style={{fontWeight:'800',marginTop:marginTop20}}>{this.state.text}你辛苦了！</div>
                    <Button text={'开始工作'} btnContainer={'colfff font30'} style={buttonStyle} option={this.start.bind(this)}/>
                </div>
            </div>

        )
    }
    start(){
        console.log('执行 开始工作了')
        let props=this.props;
        props.getTaskList();
    }
 
}

HomePageContainer.propTypes = {
};

HomePageContainer.defaultProps = {
}