//带加号初始数据保存
export const setAddItemInit = (state,action)=>{
  let res = Object.assign({},state);
  if(res.addItems[action.id]){
    return res;
  }
  res.addItems[action.id] = action.data;
  return res;
};

//下拉显示
export const showDrop=(state,action)=>{
  let res = Object.assign({},state);
  const {ikey} = action.data;
  let obj = res.showDrop||{};
  let temp = Object.assign({},obj);
  let keyArr = Object.keys(obj); 
  for(let i=0; i<keyArr.length; i++){
    temp[JSON.parse(keyArr[i])] = false;
  }
  /*for(let i in obj){
    temp[i] = false;
  };*/
  res.showDrop = Object.assign(temp,{[ikey]:action.show!==undefined?action.show:true});
  res.update=Math.random();

  return res;
};

// 点击确定隐藏下拉
export const confirmHide=(state,action)=>{
  let res = Object.assign({},state);
  let obj = res.showDrop||{};
  let temp = Object.assign({},obj);
  let keyArr = Object.keys(obj);
  for(let i=0; i<keyArr.length; i++){
    temp[JSON.parse(keyArr[i])] = false;
  }
  /*for(let i in obj){
    temp[i] = false;
  };*/
  res.showDrop = temp;
  res.commSymHide = true;
  res.update=Math.random();
  return res;
}

// 埋点统计
export const clickNum=(state,action)=>{
  let res = Object.assign({},state);
  let clickData = res.clickData;//储存的点击事件
  const data = action.data;
  let obj = {
    "labelId": data.id,
    "status":data.isAddIcon?1:0,      //是否为有id的标签，0为是，1为否（如血压后的加号）
    "operationNum": action.num,
    "operationType": action.clickType
  }
  if(clickData.length==0){
    clickData.push(obj);
  }else{
    let exits = clickData.filter((it)=>{
      return it.labelId==obj.labelId && it.operationType==obj.operationType && it.status==obj.status;
    })
    if(exits.length>0){
      exits.map((item)=>{
        return item.operationNum += 1;
      })
    }else{
      clickData.push(obj);
    }
  }
  // res.clickData = clickData;
  res.update=Math.random();
  return res;
};

//编辑状态
export const setLabelToEdit = (state,action)=>{
  let res = Object.assign({},state);
  const {ikey} = action.data;
  let obj = res.editState||{};
  let temp = Object.assign({},obj);
  let keyArr = Object.keys(obj); 
  for(let i=0; i<keyArr.length; i++){
    temp[JSON.parse(keyArr[i])] = false;
  }
  /*for(let i in obj){
    temp[i] = false;
  };*/
  res.editState = Object.assign(temp,{[ikey]:action.edit!==undefined?action.edit:true});
  res.update=Math.random();
  return res;
};
//编辑状态
export const searchDropLocation = (state,action)=>{
  let res = Object.assign({},state);
  // console.log(action,'dir')
  res.boxTop = action.top?action.top:res.boxTop;
  res.boxLeft = action.left?action.left+action.dis:res.left;
  return res;
};
export const getInspectList = (state,action)=>{
  let res = Object.assign({},state);
  res.inspectList = action.data
  return res;
};
export const getAssistList = (state,action)=>{
  let res = Object.assign({},state);
  res.assistList = action.data
  return res;
};
