import {COMM_SYMPTOMS,CLEAR_COMSYMPTOMS,SHOW_TAIL,INSERT_MAIN,
  SET_SEARCH,CLEAR_SEARCH,GET_BIGDATAPUSH,SET_MAINSUIT,MIX_CONFIRM,NUMBER_SELECT,
  RADIO_SELECT,COMM_CONFIRM,CHANGE_LABELVAL,SAVE_FREE,CLEAR_MAIN_SUIT,SET_DATA,
  INSERT_SEARCH,MAIN_FOCUS_INDEX,SETTEXTMODEVALUE,SETMAINTEXT,MAINADDLABELITEM,SETMAININPUT,DEL_MAIN,CHANGE_LABELVAL_NUMBER,
  REMOVE_MAIN_ID,MAINSUIT_MUL,DEL_MAIN_LABLE,SET_FEATURE,SET_MS_RADIO_INPUT_VAL,SAVE_CHRONIC,SHOW_HISTORY_BOX,HIDE_HISTORY_BOX} from '../types/mainSuit'
import {getCommSymptoms,handleTailClick,insertMain,setSearch,getBigSymptom,setMainMoudle,confirm,
  setNumberValue,setRadioValue,commConfirm,changeLabelVal,saveFreeVal,clearMainSuit,insertSearch,setTextModeValue,setCheckText,
  addLabelItem,setInputLabel,backspaceText,changeNumLabelVal,removeId,multipleComfirn,delSingleLable,
  getSymptomFeature,setRadioInputValue} from '../actions/mainSuit'


const initState = {
  showDrop:false,
  CommonSymptoms:[],//常见症状
  searchDatas:[],//搜索结果
  bigDataSymptom:[],//大数据推送症状
  moduleData:[],//主诉模板
  addSmoduleData:[],//添加病情变化模板
  data:[],//主诉使用的模板数据
  saveText:[],//主诉框内的值
  selecteds:[],
  moduleNum:{num:0},//点了几次添加病情变化
  focusIndex:'',
  mainIds:[], //选中的主症状和伴随的id(搜索去重)
  editClear:true,
  symptomFeature:{//分词
    featureData:[],
    refresh:false //用于数据更新
  },
  chronicDesease:{} //慢病
}

export default function(state=initState,action){
  const res = Object.assign({},state);
  switch (action.type){
    case SET_MAINSUIT://主诉模板
      return setMainMoudle(state,action);
    case SET_DATA://主诉使用模板
      // res.data = res.moduleData.concat();
      res.data = JSON.parse(JSON.stringify(res.moduleData));
      res.update=Math.random();
      return res;
      // return setMainData(state,action);
    case COMM_SYMPTOMS:
      return getCommSymptoms(state,action);
    case CLEAR_COMSYMPTOMS://清空常见症状
      // return clearCommSymptoms(state,action);
      res.CommonSymptoms = [];
      return res;
    case GET_BIGDATAPUSH://大数据推送症状
      return getBigSymptom(state,action);
    case SHOW_TAIL://显示标签尾巴
      return handleTailClick(state,action);
    case INSERT_MAIN://插入选中的常见症状
      return insertMain(state,action);
    case COMM_CONFIRM://普通多选框确定事件
      return commConfirm(state,action);
    case MIX_CONFIRM://有伴 多选框确定事件
      return confirm(state,action);
    case SET_SEARCH:
      return setSearch(state,action);
    case INSERT_SEARCH:
      return insertSearch(state,action);
    case CLEAR_SEARCH://清空搜索结果
      res.searchDatas = [];
      return res;
    case NUMBER_SELECT://数字键盘选中的值处理
      return setNumberValue(state,action);
    case RADIO_SELECT://单选选中的值处理
      return setRadioValue(state,action);
    case CHANGE_LABELVAL://改变标签值
      return changeLabelVal(state,action);
    case CHANGE_LABELVAL_NUMBER://数字标签输入值
      return changeNumLabelVal(state,action);
    case SAVE_FREE://自由输入
      return saveFreeVal(state,action);
    case MAIN_FOCUS_INDEX:
      res.focusIndex = action.index;
      res.span = action.$span;
      return res;
    case CLEAR_MAIN_SUIT://清除数据
      return clearMainSuit(state,action);
    case SETTEXTMODEVALUE:
      return setTextModeValue(state,action);
    case SETMAINTEXT:
      return setCheckText(state,action);
    case MAINADDLABELITEM:
      return addLabelItem(state,action);
    case SETMAININPUT:
      return setInputLabel(state,action);
    case DEL_MAIN:
      return backspaceText(state,action);
    case REMOVE_MAIN_ID:
      return removeId(state,action);
    case MAINSUIT_MUL://单列多选
      return multipleComfirn(state,action);
    case DEL_MAIN_LABLE://单独删除标签
      return delSingleLable(state,action);
    case SET_FEATURE://主诉分词
      return getSymptomFeature(state,action);
    case SET_MS_RADIO_INPUT_VAL:
      return setRadioInputValue(state,action);
    case SAVE_CHRONIC:
      res.chronicDesease = action.data;
      return res;
    case SHOW_HISTORY_BOX://显示是否引用历史病例弹窗
      res.showHisBox = true;
      return res;
    case HIDE_HISTORY_BOX://关闭
      res.showHisBox = false;
      return res;
    default:
      return state;
  }
}