import {HIDE,RESET,SETINITDATA,SETDROPSHOW,SETADDITEMINIT,SETT0EDIT,SETREADDITEMS,SETPREDATA,
  HIDEDROP,CLICKCOUNT,ISREAD,SETOTHERHISTORY,SETMINSCREEN,MODI_LOADING,GET_INSPECT_LIST,GET_ASSIST_LIST,
  SETALLMODULES,SETSYSTEMCONFIG,SETPRE,RESET_SELECT_TAG,SET_SELECTED_AREA,SETADMIN,SET_CURRENT_MODULE,TOGGLE_PUSH_DATA,GETSTATICDATA,CHANGEHOSPITAL,HOSPITALMSG} from '../types/homePage.js';
import {showDrop,setAddItemInit,setLabelToEdit,confirmHide,clickNum,getInspectList,getAssistList,setSelectArea,resetSelectArea, changeHospital,getStaticData,setHospitalMsg} from '../actions/homePage.js';
import {getMRAnalyse} from '@store/async-actions/pushMessage';

const initState = {
  totalHide:false,
  initData:{},
  showDrop:{},
  focusTextIndex:'',
  clickData:[],
  addItems:{},
  commSymHide:false,
  loadingFlag:true,
  loadingShow:false,
  boxTop:0,
  boxLeft:0,
  allModules:[],
  assistList:[],
  inspectList:[],
  sysConfig:{},
  showPre:false,
  preData:{},
  item:{},
  admin:false,
  moduleName:'',
  showPushData: false,
  moduleObj: {
    "common": "主诉",
    "1": "主诉",
    "2": "现病史",
    "3": "其他史",
    "4": "查体"
  },
  staticData:{},
  hospitalMsg:[{
    hospitalId:-1
  }],
  curHos:{
    hosId:-1,
    hosName:'',
    connect:1
  }

};

export default function (state=initState,action) {
  let res = Object.assign({},state);
  switch (action.type){
    case HIDE:
      res.totalHide = true;
      return res;
    case RESET:
      res.totalHide = false;
      res.commSymHide = false;
      return res;
    case HOSPITALMSG:
      return setHospitalMsg(state,action);
    case CHANGEHOSPITAL:
      return changeHospital(state,action);
    case SETDROPSHOW:
      return showDrop(state,action);
    case HIDEDROP:
      return confirmHide(state,action);
    case SETINITDATA:
      res.initData = action.data;
      return res;
    case CLICKCOUNT:
      return clickNum(state,action);
    case SETADDITEMINIT:
      return setAddItemInit(state,action);
    case SETT0EDIT:
      return setLabelToEdit(state,action);
    case SETREADDITEMS:
      res.addItems = action.data||{};
      return res;
    case ISREAD:
      res.isRead = Math.random();
      return res;
    case SETOTHERHISTORY:
      res.initData.otherHis = action.data;
      res.initData.otherHisSave = action.save;
      res.initData.otherIsHis = action.otherIsHis!=undefined?action.otherIsHis:true;
      res.initData.period = action.period;
      return res;
    case SETMINSCREEN:
      res.windowWidth = action.obj.width;
      res.windowHeight = action.obj.height;
      return res;
    case MODI_LOADING:
      // res.loadingFlag = false;
      res.loadingFlag = action.flag;
      return res;
    case GET_INSPECT_LIST:
      return getInspectList(state,action);
    case GET_ASSIST_LIST:
      return getAssistList(state,action);
    case SETALLMODULES:
      res.allModules = action.data;
      return res;
    case SETSYSTEMCONFIG:
      res.sysConfig = action.data;
      return res;
    case SETPRE:
      res.showPre = action.show;
      return res;
    case SETPREDATA:
      res.preData = action.preData;
      res.item = action.item;
      return res;
    case SETADMIN:
      res.admin = action.admin;
      return res;
    case SET_SELECTED_AREA:
      return setSelectArea(state,action);
    case RESET_SELECT_TAG:
      return resetSelectArea(state,action);
    case SET_CURRENT_MODULE: 
      res.moduleName = action.moduleName
      return res;
    case TOGGLE_PUSH_DATA:
      res.showPushData = ! res.showPushData
      return res;
    case GETSTATICDATA:
      return getStaticData(state,action);
    default:
      return res;
  }
}