import React from 'react';
import { connect } from 'react-redux';
import { getSearchList } from '@store/async-actions/medicalInfo';
import MedicalInfo from '@components/MedicalInfo';
import {getAllConceptDetail, getScaleInfo} from '../store/async-actions/pushMessage';
import {getMedicalFilters} from '../store/async-actions/fetchModules';
import {CLEAR_SCALE_SEARCH_LIST} from '@types/scaleSearch';
import {CLEAR_INFO_SEARCH_LIST,SET_FILTER_LIST} from '@types/medicalInfo';
import {SHOW_TABLE_LIST} from '@store/types/pushMessage';

function mapStateToProps(state) {
    const {medicalInfo,pushMessage,print} = state;
    return{
        searchResult: medicalInfo.searchResult,
        filterList:medicalInfo.filterList,
        formulaResult: pushMessage.formulaResult,
        scaleInfo: pushMessage.scaleInfo,//量表内容
        clearSearch:print.clearSearch,
    }
}

function mapDispatchToProps(dispatch) {
    return {
        handleChangeValue(val,types){
            dispatch(getSearchList(val,types))
        },
        getAllConceptDetail(item) {
            dispatch(getAllConceptDetail(item))
        },
        clearResult(){
              dispatch({
                type:CLEAR_INFO_SEARCH_LIST
              })
        },
        showScaleFn(item){
          dispatch({
            type:SHOW_TABLE_LIST,
            name:'showTable',
            value:true,
            item:Object.assign({},item)
          });
        },
        getScale(item) {
          dispatch(getScaleInfo(item))
        },
        getFilters(){
              getMedicalFilters().then((res)=>{
                  if(res.data.code=='0'){
                      dispatch({
                        type:SET_FILTER_LIST,
                        list:res.data.data[7]
                      })
                  }
              });
        }
    }
}
const MedicalInfoContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(MedicalInfo);

export default MedicalInfoContainer
