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

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 *
 * role ===> 用户详情中的type字段：1-总局 2-机场 3-单位 4-授权账号
 * adminType ===> 用户详情中的adminType字段：1-机场公司 2-机场公安局 只有type【 2、3、4 】才会有对应关联的adminType
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [{
      path: 'index',
      name: '账号管理',
      component: () => import('@/views/account/index'),
      meta: { title: '账号管理', adminType: [1], role: [1] }
    }]
  },

  {
    path: '/accountUnit',
    component: Layout,
    meta: { title: '账号管理', adminType: [1], role: [2] },
    children: [
      {
        path: 'index',
        name: 'accountUnit',
        component: () => import('@/views/accountUnit/index'),
        meta: { title: '单位账号管理', adminType: [1], role: [2] }
      },
      {
        path: 'audit',
        name: 'audit',
        component: () => import('@/views/accountUnit/audit'),
        meta: { title: '单位准入审核', adminType: [1], role: [2] }
      }
    ]
  },
  {
    path: '/departmentName',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'departmentName',
        component: () => import('@/views/departmentName/index'),
        meta: { title: '部门单位账号管理', adminType: [2], role: [2] }
      }
    ]
  },
  {
    path: '/unit',
    component: Layout,
    meta: { title: '单位管理', adminType: [null, 1, 2], role: [2, 3, 4] },
    children: [
      {
        path: 'organization',
        name: 'organization',
        component: () => import('@/views/unit/organization'),
        meta: { title: '组织架构', adminType: [null, 1, 2], role: [2, 3, 4] }
      },
      {
        path: 'postArea',
        name: 'postArea',
        component: () => import('@/views/unit/postArea'),
        meta: { title: '岗位区域备案列表', adminType: [null, 1], role: [2, 3, 4] }
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/unit/user'),
        meta: { title: '人员管理', adminType: [null, 1, 2], role: [2, 3, 4] }
      },
      {
        path: 'userChange',
        name: 'userChange',
        component: () => import('@/views/unit/userChange'),
        meta: { title: '人员变更列表', adminType: [null, 1], role: [2, 3, 4] }
      },
      {
        path: 'userAudit',
        name: 'userAudit',
        component: () => import('@/views/unit/userAudit'),
        meta: { title: '审核人员备案列表', adminType: [1], role: [2, 3] }
      }
    ]
  },
  {
    path: '/authAccount',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'AuthAccount',
        component: () => import('@/views/authAccount/index'),
        meta: { title: '授权账号管理', adminType: [1], role: [3] }
      }
    ]
  },
  {
    path: '/leader',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'leader',
        component: () => import('@/views/leader/index'),
        meta: { title: '引领人管理', adminType: [null, 1], role: [2, 3, 4] }
      }
    ]
  },
  {
    path: '/areaManagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'areaManagement',
        component: () => import('@/views/areaManagement/index'),
        meta: { title: '通行区域管理', adminType: [null, 1], role: [2, 3, 4] }
      }
    ]
  },
  {
    path: '/passManagement',
    component: Layout,
    meta: { title: '人员通行证管理', adminType: [null, 1], role: [2, 3, 4] },
    children: [
      {
        path: 'record',
        name: 'record',
        component: () => import('@/views/passManagement/record'),
        meta: { title: '申请记录', adminType: [null, 1], role: [2, 3, 4] }
      },
      {
        path: 'documentList',
        name: 'documentList',
        component: () => import('@/views/passManagement/documentList'),
        meta: { title: '证件列表', adminType: [null, 1], role: [2, 3, 4] }
      }
      // {
      //   path: 'blacklist',
      //   name: 'blacklist',
      //   component: () => import('@/views/passManagement/blacklist/index'),
      //   meta: { title: '黑名单', adminType:[1],role: [2,3] },
      //   children: [
      //     {
      //       path: 'blacklistuser',
      //       name: 'blacklistuser',
      //       component: () => import('@/views/passManagement/blacklist/user'),
      //       meta: { title: '人员黑名单',adminType:[1], role: [2,3] }
      //     },
      //     {
      //       path: 'unit',
      //       name: 'unit',
      //       component: () => import('@/views/passManagement/blacklist/unit'),
      //       meta: { title: '单位黑名单',adminType:[1], role: [2,3] }
      //     },
      //   ]
      // },
    ]
  },
  {
    path: '/studyExamination',
    component: Layout,
    meta: { title: '学习考试', adminType: [1], role: [2] },
    children: [
      {
        path: 'studyContent',
        name: 'studyContent',
        component: () => import('@/views/studyExamination/studyContent'),
        meta: { title: '学习内容管理', adminType: [1], role: [2] }
      },
      {
        path: 'questionBank',
        name: 'questionBank',
        component: () => import('@/views/studyExamination/questionBank'),
        meta: { title: '考试题库管理', adminType: [1], role: [2] }
      },
      {
        path: 'examinationPaper',
        name: 'examinationPaper',
        component: () => import('@/views/studyExamination/examinationPaper'),
        meta: { title: '试卷管理', adminType: [1], role: [2] }
      }
    ]
  },
  {
    path: '/studyTestBinding',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'studyTestBinding',
        component: () => import('@/views/studyTestBinding/index'),
        meta: { title: '学习考试绑定', adminType: [1], role: [2] }
      }
    ]
  },
  {
    path: '/securityIncident',
    component: Layout,
    meta: { title: '安全事件管理', adminType: [1], role: [2] },
    children: [
      {
        path: 'record',
        name: 'record',
        component: () => import('@/views/securityIncident/record'),
        meta: { title: '安全事件记录列表', adminType: [1], role: [2] }
      },
      {
        path: 'eventType',
        name: 'eventType',
        component: () => import('@/views/securityIncident/eventType'),
        meta: { title: '事件类型管理', adminType: [1], role: [2] }
      },
      {
        path: 'place',
        name: 'place',
        component: () => import('@/views/securityIncident/place'),
        meta: { title: '查获地点管理', adminType: [1], role: [2] }
      }
    ]
  },

  /*   {
    path: '/paymentManagement',
    component: Layout,
    meta: { title: '缴费管理', adminType: [1], role: [2, 3] },
    children: [
      {
        path: 'expense',
        name: 'expense',
        component: () => import('@/views/paymentManagement/expense'),
        meta: { title: '费用管理', adminType: [1], role: [2, 3] }
      },
      {
        path: 'paymentList',
        name: 'paymentList',
        component: () => import('@/views/paymentManagement/paymentList'),
        meta: { title: '缴费列表', adminType: [1], role: [2, 3] }
      }
    ]
  }, */
  {
    path: '/jurisdiction',
    component: Layout,
    meta: { title: '权限管理', adminType: [1], role: [2] },
    children: [
      {
        path: 'examination',
        name: 'examination',
        component: () => import('@/views/jurisdiction/examination'),
        meta: { title: '通行证考试管理权限', adminType: [1], role: [2] }
      },
      {
        path: 'penalize',
        name: 'penalize',
        component: () => import('@/views/jurisdiction/penalize'),
        meta: { title: '通行证处罚权限', adminType: [1], role: [2] }
      },
      {
        path: 'fill',
        name: 'fill',
        component: () => import('@/views/jurisdiction/fill'),
        meta: { title: '安保事件填报权限', adminType: [1], role: [2] }
      }
      // {
      //   path: 'securityCheck',
      //   name: 'securityCheck',
      //   component: () => import('@/views/jurisdiction/securityCheck'),
      //   meta: { title: '入场安检权限',adminType:[1], role: [2] }
      // },
    ]
  },
  {
    path: '/auditManagement',
    component: Layout,
    meta: { title: '审核管理', adminType: [1], role: [2] },
    children: [
      {
        path: 'auditUser',
        name: 'auditUser',
        component: () => import('@/views/auditManagement/auditUser'),
        meta: { title: '审核人员备案审核流管理', adminType: [1], role: [2] }
      },
      {
        path: 'auditArea',
        name: 'auditArea',
        component: () => import('@/views/auditManagement/auditArea'),
        meta: { title: '岗位区域备案审核流管理', adminType: [1], role: [2] }
      },
      {
        path: 'auditPass',
        name: 'auditPass',
        component: () => import('@/views/auditManagement/auditPass'),
        meta: { title: '人员通行证审核流管理', adminType: [1], role: [2] }
      },
      {
        path: 'securityIncident',
        name: 'securityIncident',
        component: () => import('@/views/auditManagement/securityIncident'),
        meta: { title: '安全事件审核流管理', adminType: [1], role: [2] }
      }
    ]
  },

  // {
  //   path: '/departmentAccount',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'departmentAccount',
  //       component: () => import('@/views/departmentAccount/index'),
  //       meta: { title: '部门后台账号管理',adminType:[2], role: [2] }
  //     }
  //   ]
  // },
  {
    path: '/auditFlow',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'basicSetting',
        component: () => import('@/views/securityIncident/auditFlow'),
        meta: { title: '安全事件审核流管理', adminType: [2], role: [2] }
      }
    ]
  },
  // {
  //   path: '/publicSecurityRecords',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'basicSetting',
  //       component: () => import('@/views/securityIncident/publicSecurityRecords'),
  //       meta: { title: '安全事件记录列表',adminType:[2], role: [2] }
  //     }
  //   ]
  // },

  {
    path: '/basicSetting',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'basicSetting',
        component: () => import('@/views/basicSetting/index'),
        meta: { title: '基本设置', adminType: [null, 1, 2], role: [1, 2, 3, 4] }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
