import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/

// 所有权限通用路由表
// 如首页和登录页和一些不用权限的公用页面

export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/findPwd', component: () => import('@/views/findPwd/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard'),
      name: 'dashboard',
      meta: { title: '主页' }
    }]
  }
]

export const asynsingle = [
  {
    path: '',
    component: Layout,
    redirect: 'noredirect',
    meta: { title: '账户设置' },
    children: [
      {
        path: 'modifyInformation',
        component: () => import('@/views/accountSettings/modifyAccountInformation'),
        meta: { title: '修改账户资料' }
      },
      {
        path: 'modifyPassword',
        component: () => import('@/views/accountSettings/modifyPassword'),
        meta: { title: '修改密码' }
      }
    ]
  }
]
// 实例化vue的时候只挂载constantRouter

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRouterMap, ...asynsingle]
})

// 异步挂载的路由
// 动态需要根据权限加载的路由表
//  { path: '*', redirect: '/404', hidden: true }
export const asyncRouterMap = [
  {
    '0': {
      path: '',
      component: Layout,
      name: 'sysSetting',
      redirect: 'noredirect',
      alwaysShow: true,
      meta: { title: '系统设置' },
      children: [
        {
          path: 'adminUser',
          component: () => import('@/views/sysSetting/adminUser'),
          name: 'adminUser',
          meta: { title: '平台后台用户管理列表' }
        }
      ]
    },
    '1': {
      path: '',
      component: Layout,
      name: 'contentModule',
      redirect: 'noredirect',
      meta: { title: '内容发布' },
      children: [
        {
          path: 'content',
          component: () => import('@/views/contentPub/index'),
          name: 'content',
          redirect: '/content/pubList',
          meta: { title: '内容发布列表' },
          children: [
            {
              path: 'pubList',
              component: () => import('@/views/contentPub/pubList'),
              name: 'pubList',
              meta: { title: '内容发布列表' }
            },
            {
              path: 'publish',
              hidden: true,
              component: () => import('@/views/contentPub/publish'),
              name: 'publish',
              meta: { title: ' 新内容发布' }
            }
          ]
        },
        {
          path: 'recycle',
          component: () => import('@/views/contentPub/index'),
          name: 'recycle',
          redirect: '/recycle/recycleBinList',
          meta: { title: '内容回收站列表' },
          children: [
            {
              path: 'recycleBinList',
              component: () => import('@/views/contentPub/recycleBin'),
              name: 'recycleBinList',
              meta: { title: '内容回收站列表' }
            },
            {
              path: 'viewRecycling',
              hidden: true,
              component: () => import('@/views/contentPub/viewRecyclingBins'),
              name: 'viewRecycling',
              meta: { title: ' 查看回收内容' }
            }
          ]
        },
        {
          path: 'draftList',
          component: () => import('@/views/contentPub/draftList'),
          name: 'draftList',
          meta: { title: '内容草稿箱列表' }
        }
      ]
    },
    '2': {
      path: '',
      component: Layout,
      name: 'specialExperts',
      redirect: 'noredirect',
      alwaysShow: true,
      meta: { title: '特约专家' },
      children: [
        {
          path: 'expertslist',
          component: () => import('@/views/specialExperts/index'),
          name: 'publishedList',
          meta: { title: '特约专家列表' }
        }
      ]
    },
    '3': {
      path: '',
      component: Layout,
      name: 'cooperationAgency',
      redirect: 'noredirect',
      alwaysShow: true,
      meta: { title: '合作机构' },
      children: [
        {
          path: 'agencylist',
          component: () => import('@/views/cooperationAgency/index'),
          name: 'publishedList',
          meta: { title: '合作机构管理列表' }
        }
      ]
    },
    '4': {
      path: '',
      component: Layout,
      name: 'company',
      redirect: 'noredirect',
      meta: { title: '企业中心' },
      children: [
        {
          path: 'noactive',
          component: () => import('@/views/companyCen/noactive/index'),
          name: 'noactive',
          parentPath: true,
          redirect: { name: 'noactiveList' },
          meta: { title: '未激活企业' },
          children: [
            {
              path: 'noactiveList',
              name: 'noactiveList',
              hidden: true,
              component: () => import('@/views/companyCen/noactive/noactiveList')
            },
            {
              path: 'compHome',
              component: () => import('@/views/companyCen/noactive/compHome'),
              name: 'compHome',
              parentPath: true,
              redirect: { name: 'compInfo' },
              meta: { title: '企业信息' },
              children: [
                {
                  path: 'compInfo',
                  name: 'compInfo',
                  hidden: true,
                  component: () => import('@/views/companyCen/noactive/compInfo')
                },
                {
                  path: 'productHome',
                  component: () => import('@/views/companyCen/noactive/productHome'),
                  name: 'productHome',
                  parentPath: true,
                  redirect: { name: 'compProduct' },
                  children: [
                    {
                      path: 'compProduct',
                      component: () => import('@/views/companyCen/noactive/compProduct'),
                      name: 'compProduct',
                      meta: { title: '企业产品' }
                    },
                    {
                      path: 'productInfo',
                      component: () => import('@/views/companyCen/noactive/productInfo'),
                      name: 'productInfo',
                      hidden: true,
                      meta: { title: '产品详情' }
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          path: 'activeList',
          component: () => import('@/views/companyCen/activeList'),
          name: 'activeList',
          meta: { title: '已激活企业' }
        }
      ]
    },
    '5': {
      path: '',
      component: Layout,
      name: 'platinfo',
      redirect: 'noredirect',
      alwaysShow: true,
      meta: { title: '平台信息' },
      children: [
        {
          path: 'platUpdate',
          component: () => import('@/views/platInfo/platUpdate'),
          name: 'platUpdate',
          meta: { title: '修改平台信息' }
        }
      ]
    },
    '6': {
      path: '',
      component: Layout,
      name: 'userinfo',
      redirect: 'noredirect',
      alwaysShow: true,
      meta: { title: '用户信息' },
      children: [
        {
          path: 'usingList',
          component: () => import('@/views/userInfo/usingList'),
          name: 'usingList',
          meta: { title: '正常用户' }
        },
        {
          path: 'blackList',
          component: () => import('@/views/userInfo/blackList'),
          name: 'blackList',
          meta: { title: '黑名单用户' }
        }
      ]
    },
    '7': {
      path: '',
      component: Layout,
      name: 'demand',
      redirect: 'noredirect',
      meta: { title: '需求中心' },
      children: [
        {
          path: 'publishedList',
          component: () => import('@/views/demandCen/publishedList'),
          name: 'publishedList',
          meta: { title: '发布中需求' }
        },
        {
          path: 'expiredList',
          component: () => import('@/views/demandCen/expiredList'),
          name: 'expiredList',
          meta: { title: '已过期需求' }
        },
        {
          path: 'completedList',
          component: () => import('@/views/demandCen/completedList'),
          name: 'completedList',
          meta: { title: '已完成需求' }
        },
        {
          path: 'closedList',
          component: () => import('@/views/demandCen/closedList'),
          name: 'closedList',
          meta: { title: '已关闭需求' }
        }
      ]
    }
  }
]
