/**
 * @Author: NanKeYang
 * @Description: 构建树
 * @Data: 2019/10/8 10:58
 */
export function toTree(data,target,original) {
  data.forEach(function(item) {
    delete item.children
    item[target.value] = item[original.value]
    item[target.name] = item[original.name]
    item[target.pValue] = item[original.pValue]
  })

  var map = {}
  data.forEach(function(item) {
    map[item[target.value]] = item
  })
  var val = []
  data.forEach(function(item) {
    var parent = map[item[target.pValue]]
    if (parent) {
      (parent.children || (parent.children = [])).push(item)
    } else {
      val.push(item)
    }
  })
  return val
}
