import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    meta: { title: '首页' },
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页看板', icon: 'el-icon-house', roles: 'dashboard' }
      },
      {
        path: 'audience',
        component: () => import('@/views/audienceManage/index'),
        name: 'audienceManage',
        meta: {
          title: '观众管理',
          icon: 'el-icon-user',
          roles: 'audience',
          func: [
            {
              name: '添加观众',
              roles: 'audience.add'
            },
            {
              name: '导入',
              roles: 'audience.import'
            },
            {
              name: '导出',
              roles: 'audience.export'
            }
          ]
        }
      },
      {
        path: 'preRegister',
        component: () => import('@/views/preRegManage/index'),
        name: 'preRegManage',
        meta: { title: '预登记表单', icon: 'el-icon-tickets', roles: 'preReg' },
        redirect: '/preRegister/list',
        children: [
          {
            path: 'list',
            component: () => import('@/views/preRegManage/list'),
            name: 'preRegManageList',
            meta: {
              title: '表单管理',
              icon: 'el-icon-edit',
              roles: 'preReg.list',
              collapse: false,
              func: [
                {
                  roles: 'preReg.creat',
                  name: '创建表单'
                }
              ]
            }
          },
          {
            path: 'edit/:id',
            component: () => import('@/views/preRegManage/edit.vue'),
            name: 'preRegManagEdit',
            meta: { title: '表单编辑', icon: 'el-icon-edit', hidden: true, roles: 'preReg.edit', collapse: true }
          },
          {
            path: 'add',
            component: () => import('@/views/preRegManage/edit'),
            name: 'preRegManagAdd',
            meta: { title: '表单新增', icon: 'el-icon-document-add', roles: 'preReg.edit', collapse: true }
          },
          {
            path: 'comp',
            component: () => import('@/views/preRegManage/compEdit.vue'),
            name: 'preRegManagcomp',
            meta: { title: '我的组件', icon: 'el-icon-menu', roles: 'preReg.comp' }
          }
        ]
      },
      {
        path: 'exhibitor',
        component: () => import('@/views/exhibitorManage/index'),
        name: 'ExhibitorManage',
        meta: { title: '展会管理', icon: 'el-icon-office-building', roles: 'exhibitor' },
        redirect: '/exhibitor/list',
        children: [
          {
            component: () => import('@/views/exhibitorManage/exhibitorList'),
            path: 'list',
            name: 'exhibitorManageList',
            meta: { title: '展会管理', icon: 'el-icon-edit', roles: 'exhibitor', func: [
              {
                roles: 'exhibitor.add',
                name: '添加展会'
              },
              {
                roles: 'exhibitor.import',
                name: '导入'
              },
              {
                roles: 'exhibitor.export',
                name: '导出'
              }
            ] }
          },
          {
            component: () => import('@/views/exhibitorManage/exhibitorSetting'),
            name: 'exhibitorEdit',
            path: 'edit/:id',
            meta: { title: '配置展会', icon: 'el-icon-setting', roles: 'exhibitor.setting', hidden: true }
          },
          {
            component: () => import('@/views/exhibitorManage/exhibitorSetting'),
            name: 'exhibitorAdd',
            path: 'add',
            meta: { title: '添加展会', icon: 'el-icon-document-add', roles: 'exhibitor.add' }
          }
        ]
      },
      {
        path: 'invitation',
        component: () => import('@/views/invitationManage/index'),
        name: 'invitationManage',
        meta: { title: '邀请函模板管理', icon: 'el-icon-files', roles: 'invitation' },
        redirect: '/invitation/list',
        children: [{
          path: 'list',
          component: () => import('@/views/invitationManage/list'),
          name: 'invitationManageList',
          meta: { title: '邀请函模板管理', icon: 'el-icon-edit', roles: 'invitation',collapse: false }
        },
        {
          path: 'add',
          component: () => import('@/views/invitationManage/edit'),
          name: 'invitationAdd',
          meta: { title: '邀请函模板新增', icon: 'el-icon-document-add', roles: 'invitation.add',collapse: true }
        },
        {
          path: 'edit/:id',
          component: () => import('@/views/invitationManage/edit'),
          name: 'invitationEdit',
          meta: { title: '邀请函模板编辑', icon: 'el-icon-edit', hidden: true, roles: 'invitation.edit',collapse: true }
        }
        ]
      },
      {
        path: 'setting',
        component: () => import('@/views/setting/index'),
        name: 'setting',
        meta: { title: '信息与配置', icon: 'el-icon-setting', roles: 'setting' },
        redirect: '/setting/exhibitor',
        children: [
          {
            path: 'account',
            component: () => import('@/views/setting/accountSetting'),
            name: 'accountSetting',
            meta: {
              title: '系统账号管理',
              icon: 'el-icon-user',
              roles: 'setting.account',
              func: [
                {
                  name: '添加账号',
                  roles: 'setting.account.add'
                }
              ]
            }
          },
          {
            path: 'roles',
            component: () => import('@/views/setting/rolesSetting.vue'),
            name: 'accountRoles',
            meta: {
              title: '系统角色管理',
              icon: 'el-icon-suitcase-1',
              roles: 'setting.roles',
              func: [
                {
                  name: '添加角色',
                  roles: 'setting.roles.add'
                }
              ]
            }
          },
          {
            path: 'system',
            component: () => import('@/views/setting/systemSetting'),
            name: 'systemSetting',
            meta: { title: '系统信息配置', icon: 'el-icon-setting', roles: 'setting.system' }
          }
        ]
      },
      {
        path: '404',
        component: () => import('@/views/errorPage/404'),
        name: '404',
        meta: { title: '页面不存在哦', icon: 'el-icon-delete-location', hidden: true }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/user/form/:url',
    name: 'userForm',
    component: () => import('@/views/user/form.vue'),
    hidden: true
  },
  {
    path: '/user/register',
    name: 'userRegister',
    component: () => import('@/views/user/register.vue'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
export default router
