function arrayToTree(
  array,
  id = 'id',
  parentId = 'pid',
  children = 'children'
) {
  const result = []
  const hash = {}
  const data = cloneDeep(array)

  data.forEach((item, index) => {
    hash[data[index][id]] = data[index]
  })

  data.forEach(item => {
    const hashParent = hash[item[parentId]]
    if (hashParent) {
      !hashParent[children] && (hashParent[children] = [])
      hashParent[children].push(item)
    } else {
      result.push(item)
    }
  })
  return result
}
Convert an array to a tree-structured array.
@param   {array}     array     The Array need to Converted.
@param   {string}    id        The alias of the unique ID of the object in the array.
@param   {string}    parentId       The alias of the parent ID of the object in the array.
@param   {string}    children  The alias of children of the object in the array.
@return  {array}    Return a tree-structured array.