// 前端未找到页面路由（固定不用改）
const notFoundRouter = {
  name: 'FourOhFour',
  path: '*',
  redirect: '/FourOhFour',
  hidden: true
}
const companyRouter = {
  name: 'index',
  path: '/',
  component: () => import('@/views/common/Base'),
  redirect: '/home',
  children: [{
    path: '/home',
    name: 'home',
    meta: {
      icon: 'icon-shouye',
      title: '首页'
    },
    component: () => import('@/views/page/Home'),
  }, {
    path: '/UserManagement',
    name: 'UserManagement',
    meta: {
      icon: 'icon-yonghuguanli',
      title: '用户管理'
    },
    component: () => import('@/views/system/UserManagement'),
  }, {
    path: '/CompanyManagement',
    name: 'CompanyManagement',
    meta: {
      icon: 'icon-gongsi',
      title: '公司管理'
    },
    component: () => import('@/views/system/CompanyManagement'),
  }]
}
const clientRouter = {
  name: 'index',
  path: '/',
  component: () => import('@/views/common/Base'),
  redirect: '/MyWaybill',
  children: [{
    path: '/MyWaybill',
    name: 'MyWaybill',
    meta: {
      icon: 'icon-yundan',
      title: '我的运单'
    },
    component: () => import('@/views/system/MyWaybill'),
  }]
}
// 根级菜单
const rootRouter = {
  name: 'index',
  path: '/',
  component: () => import('@/views/common/Base'),
  redirect: '/home',
  children: [{
    path: '/home',
    name: 'home',
    meta: {
      icon: 'icon-shouye',
      title: '首页'
    },
    component: () => import('@/views/page/Home'),
  }, {
    path: '/UserManagement',
    name: 'UserManagement',
    meta: {
      icon: 'icon-yonghuguanli',
      title: '用户管理'
    },
    component: () => import('@/views/system/UserManagement'),
  }, {
    path: '/ClientManagement',
    name: 'ClientManagement',
    meta: {
      icon: 'icon-yonghuguanli',
      title: '客户管理'
    },
    component: () => import('@/views/system/ClientManagement'),
  }, {
    path: '/StoreManagement',
    name: 'StoreManagement',
    meta: {
      icon: 'icon-cangku',
      title: '仓库管理'
    },
    component: () => import('@/views/system/StoreManagement'),
  }, {
    path: '/VehicleManagement',
    name: 'VehicleManagement',
    meta: {
      icon: 'icon-chakan',
      title: '车辆管理'
    },
    component: () => import('@/views/system/VehicleManagement'),
  }, {
    path: '/WaybillManagement',
    name: 'WaybillManagement',
    meta: {
      icon: 'icon-yundanguanli',
      title: '运单管理'
    },
    component: () => import('@/views/system/WaybillManagement'),
  }, ]
}

/**
 * 动态生成菜单
 * @param arrType
 * @returns {Promise<Router>}
 */
export const generatorDynamicRouter = arrType => {
  return new Promise((resolve, reject) => {
    const routers = []
    if (arrType.userType == "sys") {
      if (arrType.deptId === 0) {
        routers.push(notFoundRouter)
        routers.push(companyRouter)
      } else {
        function deleteObjectById(arr, name) {
          return arr.filter(obj => obj.name !== name);
        }
        rootRouter.children = deleteObjectById(rootRouter.children, 'CompanyManagement')
        routers.push(notFoundRouter)
        routers.push(rootRouter)
      }
    } else {
      routers.push(notFoundRouter)
      routers.push(clientRouter)
    }
    resolve(routers)
  })
}
