import React from 'react';
import Header from '../../components/CommonComponent/HeaderComponent/HeaderComponent';
import LeftContainer from '../LeftContainer/LeftContainer';
import RightContainer from '../RightContainer/RightContainer';
import RecovertyFirstPage from '../../components/RecoveryComponent/RecoveryFirstPage/RecoveryFirstPage'
import RecoverySecondPage from '../../components/RecoveryComponent/RecoverySecondPage/RecoverySecondPage'
require('./index.css');

const recoveryPageIndex = {
    1 : "boxRecovery",
    2 : "shelfRecovery"
}

export default class RecoveryContainer extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            showPage : recoveryPageIndex[1] //展示回收箱页面
        };
        this.getFirstPage = this.getFirstPage.bind(this); //展示第一页
        this.getSecondPage = this.getSecondPage.bind(this); //展示第二页
        this.getPage = this.getPage.bind(this); //获取要展示的页面
        this.finishBoxRecovery = this.finishBoxRecovery.bind(this); //完成回收箱商品回收
    }

    componentWillMount() {
        let props = this.props;
        console.log("props ",this.props);
        let {headerInfo = {}} = props;
        let {taskList = {}} = headerInfo;
        if(taskList && !taskList.whetherType){
            console.log("没有回收箱物品")
            //没有回收箱物品
            this.setState({
                showPage : recoveryPageIndex[2]
            })

        }
    }

    componentWillReceiveProps(nextProps){

    }

    finishBoxRecovery(){
        //完成回收箱物品回收
        let props = this.props;
        props.getTaskName()
        this.setState({
            showPage : recoveryPageIndex[2]
        })
    }

    getFirstPage(){
        return (
            <RecovertyFirstPage finishBoxRecovery={()=>this.finishBoxRecovery()}/>
        )
    }
    getSecondPage(){
        let props = this.props;
        return (
            <RecoverySecondPage {...props}/>
        )
    }

    getPage(){
        console.log("getPage ",this.state.showPage)
        switch (this.state.showPage){
            case recoveryPageIndex[1]:
                return this.getFirstPage();
            case recoveryPageIndex[2]:
                return this.getSecondPage();
        }
    }

    render(){
        let dom = this.getPage();
        let props = this.props;
        return(
            <div className={"recoveryContainer page"}>
                {
                    props.headerInfo && props.headerInfo.storeInfo ?
                        <Header headerInfo={props.headerInfo}/> : null
                }

                <LeftContainer leftInfo={props.headerInfo}/>
                <RightContainer>
                    {
                        dom
                    }
                </RightContainer>
            </div>
        )
    }
}
