
export const showMixCheckBox = (state,action)=>{//点击症状显示下拉
  const res=Object.assign({},state);
  let show = action.showCheckBox;
  res.showCheckBox = !res.showCheckBox; 

  res.showDrop = !res.showDrop;
  let inlineDatas = res.zayin;
  let id = action.id;
  for(let i=0; i<inlineDatas.length; i++){
    if(inlineDatas[i].id == id){
      inlineDatas[i].showDrop = !inlineDatas[i].showDrop;
    }
  }
  return res;
};

export const confirnMix=(state,action)=>{//确定
    const res=Object.assign({},state);
    res.showCheckBox = false;
    res.showDrop = false;
    let checkBoxId = action.checkBoxId;
    let datas = res.zayin;
    for(let i=0; i<datas.length; i++){
      if(datas[i].id == checkBoxId){
        datas[i].showDrop = false;
      }
    }
    let allDatas = res.zayin[0].questionMapping;
    let seleDatas = "";
    for(let k=0; k<allDatas.length; k++){
      let detailList = allDatas[k].questionDetailList;
      for(let j=0; j<detailList.length; j++){
        if(detailList[j].isSelect){
          seleDatas+=detailList[j].name;
        }
      }
    }
    res.totalSele = seleDatas || res.normalData;
    return res;
};

export const clearMix = (state,action)=>{//清空选项
  const res=Object.assign({},state);
  res.noSpecialFlag = 0;//无殊标识恢复默认
  let allDatas = res.zayin[0].questionMapping;
    for(let k=0; k<allDatas.length; k++){
      let detailList = allDatas[k].questionDetailList;
      for(let j=0; j<detailList.length; j++){
        detailList[j].isSelect = false;
      }
    }
    // 如果要恢复标签，则让 res.totalSele = ""
  return res;
};


export const radio = (state,action)=>{//点击单选

  const res=Object.assign({},state);
  res.noSpecialFlag = 1;//互斥
  res.radioFlag = !res.radioFlag;
  const datas = res.zayin[0].questionMapping;
  const id = action.id;
  const parentId = action.parentId;
  let radioVals = res.radioVals;
  let radioCheckVal = '';
  for(let i=0; i<datas.length; i++){
    if(datas[i].id == parentId){
      let radioList = datas[i].questionDetailList;
      for(let k=0; k<radioList.length; k++){
        radioList[k].isSelect = false;
        if(radioList[k].id==id){
          radioList[k].isSelect = true;
          radioCheckVal = radioList[k].name;
        }
      }
    }
  }
  radioVals[parentId] = radioCheckVal;
  res.radioVals = radioVals;
  return res;
};


export const mixChecked = (state,action)=>{//点击下拉选项
  const res=Object.assign({},state);console.log("现病史",res);
  res.noSpecialFlag = 1;//互斥
  let item = action.value.name;
  let parentId = action.value.parentId;
  let change = res.change;
  let firstC = res.firstC;
  let thenC = res.thenC;
  let values = res.zayin[0].questionMapping;
  let firstArr = [];
  let thenArr = [];

  // 初为后为数据还待矫正！！！
  if(firstC && change){//初为
    for(let i=0; i<values.length; i++){
      if(values[i].name == item){
        values[i].isSelect = !values[i].isSelect;
        values[i].first = true;
        values[i].then = false;
      }
    }
    firstArr.push(item);
    // firstArr += item+'，';
    res.firstArr = firstArr;
    const theIndex = res.thenArr.indexOf(item);
    if(theIndex !== -1){
      res.thenArr.splice(theIndex,1)
    }
  }

  else if(thenC){//后为
    for(let k=0; k<values.length; k++){
      if(values[k].name == item){
        values[k].isSelect = !values[k].isSelect;
        values[k].then = true;
        values[k].first = false;
      }
    }
    // thenArr += item+'，';
    thenArr.push(item);
    res.thenArr = thenArr;
    const firIndex = res.firstArr.indexOf(item);
    if(firIndex !== -1){
      res.firstArr.splice(firIndex,1)
    }
  }

else{//无鼠标点击顺序
  let checkVals = [];
  for(let i=0; i<values.length; i++){
    if(values[i].id == parentId){
      let dataList = values[i].questionDetailList;
      for(let j=0; j<dataList.length; j++){
        if(dataList[j].name == item){
          dataList[j].isSelect = !dataList[j].isSelect;
        }
      }
      // values[i].isSelect = !values[i].isSelect;
      let selected = dataList.filter(function(item){
        return item.isSelect;
      });
      for(let k=0; k<selected.length; k++){
        checkVals.push(selected[k].name+ "，");
      }
    }
  }
   
  res.selectVal = checkVals;
}
  return res;
};


export const mixNoSpecial = (state,action)=>{//点击无殊
  const res=Object.assign({},state);
  res.noSpecial = !res.noSpecial;//无殊选中标识
  res.noSpecialFlag = res.noSpecial? 2 : 0;//互斥
  // res.noSpecialFlag = 2;
  res.normalData = action.name;
  return res;
};