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} from '@store/types/diagnosticList'; 
import { getTreatResult } from '@store/async-actions/treat';
import { SHOW_TREAT, DEL_REACT, DEL_FOLLOW_UP } from '@store/types/treat.js';
import {billing, getConceptDetail} 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) {
    const {diagnosticList,assessResult,pushMessage } = state;
    let diagnC = diagnosticList.chronicMagItem;
    return {
        list: diagnosticList.diagnosticList,
        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,
        windowWidth: state.homePage.windowWidth
    }
}

function mapDispatchToProps(dispatch) {
    return {
      setAssess(data,disName){        //获取评估内容数据
        dispatch({
          type:SET_ASSESS_DATA,
          data:data,
          name:disName
        });
      },
        delDiagnostic: (item) => {
            dispatch({
                type: DEL_DIAGNOSTIC,
                item: item
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        delReact: (item) => {
            dispatch({
                type: DEL_REACT,
                item: item
            })
        },
        delFollowUp:(delItem) => {
            dispatch({
                type: DEL_FOLLOW_UP,
                delItem: delItem
            })
        },
        upDiagnostic: (index, id) => {
            dispatch({
                type: UP_DIAGNOSTIC,
                index: index
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        downDiagnostic: (index, id) => {
            dispatch({
                type: DOWN_DIAGNOSTIC,
                index: index
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        showTreat: () => {
            dispatch({
                type: SHOW_TREAT,
            })
        },
        getTreatResult: (item) => {
            // dispatch({type:MODI_LOADING,flag:true});
            // dispatch({type:SHOW_LOADING,flag:true});
            dispatch(getTreatResult(item));
        },
        getTips: (item,noTips,noDetails,noNotify) => {
            dispatch(getConceptDetail(item,noTips,noDetails,noNotify))
        },
        getBilling: () => {
          if (didPushParamChange()) {
            dispatch(billing())
          }
        },
        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;

