import {connect} from 'react-redux';
import CheckBody from '@components/CheckBody';
import {getModule,getInitData} from '@store/async-actions/fetchModules.js';
import {HIDE,RESET,SETDROPSHOW} from '@store/types/homePage.js';
import {SELECTSEARCHDATA} from "@store/types/checkBody";
import {billing} from '@store/async-actions/pushMessage';

function mapStateToProps(state){ 
  const {homePage,mainSuit,checkBody} = state;
  const hasMain = mainSuit.saveText.join('')||mainSuit.data.length;
  return {
    data:checkBody.data,
    update:checkBody.update,   //用于触发更新
    showArr:homePage.showDrop,
    totalHide:homePage.totalHide,
    saveText:checkBody.saveText,
    searchData:checkBody.searchData,    //延迟搜索结果
    hasMain,//主诉选中的数据
    focusTextIndex:checkBody.focusIndex,    //聚焦的自由文本标签index
    span:checkBody.span,
    selecteds:checkBody.selecteds       //普通多选选中状态
  }
}

function mapDispatchToProps(dispatch,state){
  return {
    getInit(){
      dispatch(getInitData());
    },
    fetchModules(param){
      const {id,name,index,span} = param;
      getModule(id).then((res)=>{
        if(res.data.code=='0'){
          dispatch({
            type:SELECTSEARCHDATA,
            index,
            name,
            data: res.data.data,
            span,
            isReplace:false
          })
        }
      });
    },
    //右侧推送
    fetchPushInfos(){
      //调右侧推送
      dispatch(billing);
    },
  }
}

const CheckBodyCont = connect(mapStateToProps,mapDispatchToProps)(CheckBody);

export default CheckBodyCont;