function sonsTree(obj, arr) {
  var children = new Array();
  for (var i = 0; i < arr.length; i++) {
    if (arr[i].pId === obj.id) {
      //pid等于加入数组
      sonsTree(arr[i], arr); //递归出子元素
      arr[i].text  = arr[i].typeName;
      arr[i].value  = arr[i].id;
      //arr[i].expanded = false;
      children.push(arr[i]);
    }
  }
  if (children.length > 0) {
    obj.children = children;
  }
  return obj;
}

function treeUtils(data) {
  let ptree = [];
  // 
  // return;
  for (var i = 0; i < data.length; i++) {
    if (data[i].pId === null || data[i].pId === 0) {
      //获取父元素
      let o = sonsTree(data[i], data);
      o.text = o.typeName;
      o.value = o.id;
      ptree.push(o);
    }
  }
  //
  return ptree;
}

export default treeUtils;