import {allRoutes} from "@/router/all-routes";

// export function getUserRouter(routes,routesUse,obj,isTwo) {
//  routes.forEach(item => {
//
//   if (item.childList.length > 0) {
//    isTwo = true
//    if (+item.HIGHER === 116){
//
//    // 代表最高层
//     obj.CODE1Info = {
//      CODE:item.CODE,
//      NAME:item.NAME
//     }
//    }
//    delete obj.CODE2Info
//    if (+item.HIGHER !== 116){
//     isTwo = false
//    // 代表第二层,总共3级
//     obj.CODE2Info = {
//      CODE:item.CODE,
//      NAME:item.NAME
//     }
//    }
//    console.log(obj,'obj')
//    getUserRouter(item.childList,routesUse,obj,isTwo)
//
//   }else {
//    console.log('iiisasa',item)
//    const findI = allRoutes.find(i => i.path === ('/main' + item.O_PATH))
//    if (findI) {
//
//     routesUse.push({
//      ...findI,
//      meta:{
//       CODE:item.CODE,
//       parent:[...Object.values(obj)].concat([{
//        CODE:item.CODE,
//        NAME:item.NAME
//       }])
//      }
//     })
//
//
//    }
//
//   }
//
//  })
// }

export function getU(item,routesUse) {
 const findI = allRoutes.find(i => i.name === item.O_PATH)

 if (findI){
  routesUse.push({
   ...findI,
   meta:{
    CODE:item.CODE,
    parent:item.parent
   }
  })
 }

}
let arr = []
export function getUserRouter(routes,routesUse) {
  routes.forEach(i => {
   if (i.childList.length > 0) {
    if (+i.HIGHER === 51) {

     i.childList.forEach(item => {
      item.layer = 1
      item.parent = (item.parent||[]).concat([{
       NAME:i.NAME,
       CODE:i.CODE,
       path:i.O_PATH
      },{
       NAME:item.NAME,
       CODE:item.CODE,
       path:item.O_PATH
      }])
      if (item.childList.length > 0) {

       item.childList.forEach(child => {
        child.layer = 2
        child.parent = (child.parent||[]).concat([{
         NAME:i.NAME,
         CODE:i.CODE,
         path:i.O_PATH
        },{
         NAME:item.NAME,
         CODE:item.CODE,
         path:item.O_PATH
        },{
         NAME:child.NAME,
         CODE:child.CODE,
         path:item.O_PATH
        }])
        getU(child,routesUse)

       })
      }else {
       getU(item,routesUse)
      }
     })
    }
    }
   }
  )
}
