import React from 'react';
import { connect } from 'react-redux';
import DiagnosticList from '@components/DiagnosticList';
import { ADD_DIAGNOSTIC,  DEL_DIAGNOSTIC, UP_DIAGNOSTIC, DOWN_DIAGNOSTIC, GET_DIAGNOSTIC_STR, GET_IS_FIRST, HIDE_REFER_RECORD, SHOW_HISTORY_CASE,HIDE_HISTORY_CASE } 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, getTips} from '../store/async-actions/pushMessage';
import {keepPushData} from '@store/actions/tabTemplate';
import { showHistory,sortHistory,activeHistory,visibleHistory } from '@store/actions/historyTemplates'
import {CURRENT_CHRONIC} from '@store/types/currentIll';
import {autoFillModules} from '@store/async-actions/fetchModules';
import { initItemList } from '@store/async-actions/historyTemplates';
import {MODI_LOADING} from '@store/types/homePage.js';

function mapStateToProps(state) {
    return {
        list: state.diagnosticList.diagnosticList,
        treatment: state.treat.show,
        isFirst: state.diagnosticList.isFirst,
        diagnosticStr: state.diagnosticList.diagnosticStr,
        showReferRecord: state.diagnosticList.showReferRecord,
        showHistoryCase: state.diagnosticList.showHistoryCase,
        items:state.historyTemplates.items,
        chronicMagItem: state.diagnosticList.chronicMagItem,
        typeConfig: state.typeConfig.typeConfig,
    }
}

function mapDispatchToProps(dispatch) {
    return {
        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
            });
        },
        getSearchResult:() => {
            dispatch(getSearchResult)
        },
        showTreat: () => {
            dispatch({
                type: SHOW_TREAT,
            })
        },
        getTreatResult: (item) => {
            dispatch({type:MODI_LOADING,flag:true});
            dispatch(getTreatResult(item));
        },
        getTips: (diagItem) => {
            dispatch(getTips(diagItem))
        },
        getBilling: () => {
            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;

