import React from 'react';
import { connect } from 'react-redux';
import DiagnosticList from '@components/DiagnosticList';
import { DEL_DIAGNOSTIC, UP_DIAGNOSTIC, DOWN_DIAGNOSTIC, GET_DIAGNOSTIC_STR, HIDE_REFER_RECORD, SHOW_HISTORY_CASE,HIDE_HISTORY_CASE ,SHOW_LOADING,ADDDIAGMSG,EDITDIAGMSG} from '@store/types/diagnosticList'; 
import {SHOW_TIPS_DETAILS,HIDE_TIPS_DETAILS} from '@store/types/pushMessage';
import { SHOW_TCM_SEARCH,HIDE_TCM_SEARCH} from '@store/types/diagnosticSearch';
import { getTreatResult } from '@store/async-actions/treat';
import { SHOW_TREAT, DEL_REACT, DEL_FOLLOW_UP } from '@store/types/treat.js';
import {embedPush, getAllConceptDetail, getConceptDetail, getMRAnalyse} from '../store/async-actions/pushMessage';
import {keepPushData} from '@store/actions/tabTemplate';
import { visibleHistory } from '@store/actions/historyTemplates'
import {autoFillModules} from '@store/async-actions/fetchModules';
import {SET_ASSESS_DATA} from '@types/assessResult';
import {didPushParamChange} from '@utils/tools';

function mapStateToProps(state) {//console.log(state)
    const {diagnosticList,assessResult,pushMessage } = state;
    let diagnC = diagnosticList.chronicMagItem;
    return {
        pushMessage: pushMessage,
        list: diagnosticList.diagnosticList,
        tcmList:diagnosticList.tcmList,
        treatment: state.treat.show,
        isFirst: diagnosticList.isFirst,
        diagnosticStr: diagnosticList.diagnosticStr,
        showReferRecord: diagnosticList.showReferRecord,
        showHistoryCase: diagnosticList.showHistoryCase,
        items:state.historyTemplates.items,
        chronicMagItem: diagnC?diagnC:state.mainSuit.chronicDesease,
        typeConfig: state.typeConfig.mode,
      //wholeResults:assessResult.wholeResults,
        scaleInfo: pushMessage.scaleInfo,//量表内容
        showHide: pushMessage.showHide,
        loading: diagnosticList.loading&&!state.copyRight.loading,
        windowWidth: state.homePage.windowWidth
    }
}

function mapDispatchToProps(dispatch) {
    return {
      editDiagName(idx,name,isTcm){        //获取评估内容数据
        dispatch({
          type:EDITDIAGMSG,
          idx:idx,
          name:name,
          isTcm
        });
        dispatch({
            type: GET_DIAGNOSTIC_STR
        });
      },
      setAssess(data,disName){        //获取评估内容数据
        dispatch({
          type:SET_ASSESS_DATA,
          data:data,
          name:disName
        });
        dispatch({
            type: GET_DIAGNOSTIC_STR
        });
      },
        showTcmSearch:(flag)=>{
          if(flag){
              dispatch({
                  type: SHOW_TCM_SEARCH
              })
          }else{
              dispatch({
                  type: HIDE_TCM_SEARCH
              })
          }
        },
        showSymSearch:(flag)=>{
            dispatch({
                type: 'SHOW_SYM_SEARCH',
                show:flag
            })
        },
        delDiagnostic: (item,idx,isTcm) => {
            dispatch({
                type: DEL_DIAGNOSTIC,
                item: item,
                idx:idx,
                isTcm
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR,
                isTcm
            });
            dispatch(embedPush({action: "diag",isTcm}))
        },
        delReact: (item) => {
            dispatch({
                type: DEL_REACT,
                item: item
            })
        },
        delFollowUp:(delItem) => {
            dispatch({
                type: DEL_FOLLOW_UP,
                delItem: delItem
            })
        },
        upDiagnostic: (index,isTcm) => {
            dispatch({
                type: UP_DIAGNOSTIC,
                index: index,
                isTcm
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        downDiagnostic: (index,isTcm) => {
            dispatch({
                type: DOWN_DIAGNOSTIC,
                index: index,
                isTcm
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        showTreat: () => {
            dispatch({
                type: SHOW_TREAT,
            })
        },
        getTreatResult: (item,idx,isTcm) => {
            dispatch({
                type:ADDDIAGMSG,
                item:item,
                idx:idx,
                isTcm
            });
        },
        getTips: (item) => {
          dispatch(getAllConceptDetail(item))
        },
        showTipsDetailsModal: () => {
          dispatch({
            type: SHOW_TIPS_DETAILS
          })
        },
        hideTipsDetailsModal: () => {
          dispatch({
            type: HIDE_TIPS_DETAILS
          })
        },
        getBilling: (obj) => {
          if (didPushParamChange()) {
            obj.action ='diag'
            dispatch(embedPush(obj))
          }
        },
        hideReferRecord: ()=>{
            dispatch({
                type: HIDE_REFER_RECORD
            })
        },
        showHistoryCaseModal: ()=> {
            dispatch({
                type: SHOW_HISTORY_CASE
            })
        },
        hideHistoryCaseModal: ()=> {
            dispatch({
                type: HIDE_HISTORY_CASE
            })
        },
        handleQuoteClick(data){   
            dispatch(keepPushData(data,'his'))      //历史病历引用
            // dispatch(activeHistory(idx))
            dispatch(visibleHistory(true))
        },
        autoFillModules(){
            dispatch(autoFillModules())//自动分发模板
        },
    }
}

const diagnosticListContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(DiagnosticList)

export default diagnosticListContainer;

