import React from 'react';
import store from '@store';
import styles from './index.less';
import ReactDom from "react-dom";
import sort from "./img/sort.png"
import close from "./img/close.png";
import PreviewBody from '@components/PreviewBody';
import Empty from '@components/Empty'
import { dragBox } from '@utils/tools';


class HistoryCaseContainer extends React.Component {
    constructor(props){
        super(props);
    }
    componentDidMount(){
      dragBox('hisWrapMove','closeHis')
    }
    render(){
        const { items,handleCaseClick,handleQuoteClick,handleSortClick,showHistoryBox,activeHistory,preInfo } = this.props;
        let baseList = store.getState();
        let baseObj = baseList.historyTemplates.activeHistory;
        let dataJson,dataStr;
        if(baseObj){
            dataJson = JSON.stringify(baseObj) == "{}" ? {} : JSON.parse(baseList.historyTemplates.activeHistory.dataJson);
            dataStr = JSON.stringify(baseObj) == "{}" ? [] : baseObj.detailList;
        }
        const getAllDataStringList = () =>{           //获取所有模块文本的数据
            let jsonDataString = {};
            jsonDataString.lis = {};
            jsonDataString.chief = dataStr[0].content || '';      //主诉
            jsonDataString.present = dataStr[1].content || '';     //现病史
            jsonDataString.other = dataStr[2].content || '';      //其他史
            jsonDataString.vital = dataStr[3].content || '';    //查体
            jsonDataString.lis = dataStr[4].content || '';      //化验导入填写
            jsonDataString.pacs = dataStr[5].content || '';     //辅检
            jsonDataString.diag = dataStr[6].content || '';      //诊断
            jsonDataString.advice = dataStr[7].content || '';       //医嘱
            return jsonDataString;
        }
        return (
            <div className={styles.mainHistory} id="hisWrapMove">
                <div className={`${styles.closeHis} drag-title`} id="closeHis">
                    <img className={styles.close} src={close} alt="关闭历史病历" onClick={showHistoryBox}/>
                </div>
                <div className={styles.mainHistoryLeft}>
                    <div className={styles.title}>
                        <span className={styles.his}>历史病历</span>
                        <span className={styles.sort} onClick={handleSortClick}>排序 <img src={sort} alt="排序"/></span>
                    </div>
                    <div className={styles.lists}>
                        <ul>
                            {
                                (items && items.length > 0)? items.map((val,idx)=>{
                                    return <li key={val.id} className={val.id == activeHistory.id?styles.bgc:''} onClick={(e)=>{handleCaseClick(e,idx)}}>
                                        <span title={val.diagnose}>{val.diagnose}</span>
                                        {/* <span className={val.id == activeHistory.id?`${styles.time} ${styles.quoteHide}`:styles.time}>{val.inquiryDate}</span>
                                        <button 
                                            className={val.id == activeHistory.id?`${styles.quote} ${styles.quoteShow}`:styles.quote} 
                                            onClick={(e)=>{handleQuoteClick(e,val)}}
                                        >引 用</button> */}
                                        <button 
                                            className={styles.quote} 
                                            onClick={(e)=>{handleQuoteClick(e,val,idx)}}
                                        >引 用</button>
                                        <span className={styles.time}>{val.inquiryDate}</span>
                                    </li>
                                }):<Empty message={'无历史病历'}></Empty>
                            }
                        </ul>
                    </div>
                </div>
                <div className={styles.mainHistoryRight}>
                    {
                        baseObj == undefined || JSON.stringify(baseObj) == "{}" ? null :
                        <PreviewBody
                            preInfo={preInfo}
                            dataJson={dataJson}
                            baseObj={baseObj}
                            dataStr={dataStr.length > 0?getAllDataStringList(dataStr):[]}
                            show={false}
                            flg={true}
                            showAssessBtn={true}
                        ></PreviewBody>
                    }
                </div>
            </div>
        )
    }
}

export default HistoryCaseContainer;