import {connect} from 'react-redux';
import Emergency from '@components/Emergency';
import {getAllHis,getFilterHis,downloadData,addSecondDiag} from '@store/async-actions/fetchModules.js';
import { downloadExportedData } from '@utils/tools.js';
import {CLEAR_RECORD} from '@store/types/emergencyHis.js';
import { getSearchList } from '@store/async-actions/diagnosticSearch';
import {Notify} from '@commonComp';

const mapStateToProps = function(state){
  const {emergencyHis,patInfo} = state;
  return {
    data:emergencyHis.allHisRecord,
    total:emergencyHis.total,
    params:emergencyHis.params,
    preInfo : state.patInfo.message,
    searchData:emergencyHis.searchData,
    info:patInfo.message
  }
}

const mapDispatchToProps = function(dispatch){
  return {
    getNextPage(item){
      dispatch(getAllHis(item));
    },
    filterData(obj){
      dispatch(getFilterHis(obj))
    },
    async getDownload(obj){
      let resData = await downloadData(obj.ids);
      downloadExportedData(resData.data,obj.info.hospitalDeptName+"病历.xls");
    },
    clearHisRecord(){
      dispatch({type:CLEAR_RECORD})
    },
    handleChangeValue(val){
      dispatch(getSearchList(val,true))
    },
    async addSecond(obj){
      let resData = await addSecondDiag(obj.item);
      if(resData&&resData.data.code==0){
        Notify.info("添加成功");
        // dispatch(getFilterHis({flag:-1}));
        dispatch(getFilterHis({flag:obj.flag}));
      }
      
    }
  }
}

export default connect(mapStateToProps,mapDispatchToProps)(Emergency);