import React from 'react';
import styles from './index.less';
import ReactDom from "react-dom";
import HistoryList from "./HistoryList";
import {initItemList} from "@store/async-actions/historyTemplates";
import {visibleHistory,showHistory} from "@store/actions/historyTemplates";
import store from '@store';
import { ConfirmModal } from '@commonComp';
import { pushAllDataList } from '@utils/tools';
import { CONFIRM_TYPE } from "@store/types/typeConfig";
import {billing} from '@store/async-actions/pushMessage';

class HistoryCaseContainer extends React.Component {
    constructor(props){
        super(props);
        this.close = this.close.bind(this);
    }
    componentDidMount(){
        // store.dispatch(initItemList());
    }
    makeSure(){
        let baseList = store.getState();
        let baseObj = baseList.historyTemplates.activeHistory;
        store.dispatch(visibleHistory(false))
        store.dispatch(showHistory(false))
        store.dispatch({type: CONFIRM_TYPE, confirmType: baseObj.sign});
        pushAllDataList(baseObj.sign,'push',baseObj,'history')       //引用
        store.dispatch(billing())
    }
    close(){
      store.dispatch(visibleHistory(false));
    }
    render(){
        const { visible,showHistoryCases,showHistoryBox,items,handleCaseClick,handleQuoteClick,handleSortClick,activeHistory,preInfo } = this.props;
        const domNode = document.getElementById('root');
        return ReactDom.createPortal(
            <div className={styles.historyCaseWrap} style={{display:showHistoryCases?'block':'none'}}>
                <div className={styles.maskHistory} onClick={showHistoryBox}></div>
                <HistoryList 
                    items={items}
                    activeHistory={activeHistory}
                    showHistoryBox={showHistoryBox}
                    handleCaseClick={handleCaseClick}
                    handleQuoteClick={handleQuoteClick}
                    handleSortClick={handleSortClick}
                    preInfo={preInfo}
                ></HistoryList>
                <ConfirmModal
                    visible={visible}
                    confirm={this.makeSure}
                    close={this.close}
                    cancel={this.close}
                    okText={"引用"}
                    okBorderColor={'#3B9ED0'}
                    okColor={'#fff'}
                    oKBg={'#3B9ED0'}
                >
                    <p className={styles['center']}>确认引用该病历？</p>
                </ConfirmModal>
            </div>
        ,domNode)
    }
}

export default HistoryCaseContainer;