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 : {
    perms: ['admin','editor']    control the page perms (you can set multiple perms)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             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 perms can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/myinfo',
    component: Layout,
    redirect: '/myinfo',
    hidden: true,
    children: [
      {
        path: '',
        name: 'ChangePassword',
        component: () => import('@/views/system/changepassword'),
        meta: { title: '修改密码', noCache: true, icon: '', perms: [] },
      },
    ]
  },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user perms
 */
export const asyncRoutes = [
  {
    path: '/share',
    component: Layout,
    redirect: '/share/qualification',
    name: 'Share',
    alwaysShow: true,
    meta: { title: '能力共享', icon: 'share' },
    children: [
      {
        path: 'qualification',
        name: 'Qualification',
        component: () => import('@/views/ability/qualification'),
        meta: { title: '资质情况', perms: ['qualification_view'] }
      },
      {
        path: 'abilityQuality',
        name: 'abilityQuality',
        component: () => import('@/views/ability/abilityQuality'),
        meta: { title: '资质情况（新）', perms: ['qualification_view'] }
      },
      {
        path: 'cma',
        name: 'CMA',
        component: () => import('@/views/ability/cma'),
        meta: { title: '检测能力(总部CMA+CNAS)', perms: ['cma_view'] }
      },

      {
        path: 'cma2',
        name: 'CMA2',
        component: () => import('@/views/ability/cma2'),
        meta: { title: '检测能力(分子公司CMA)', perms: ['cma2_view'] }
      }
      ,
      {
        path: 'inspection',
        name: 'Inspection',
        component: () => import('@/views/ability/inspection'),
        meta: { title: '检验能力', perms: ['inspection_view'] }
      }
      ,
      {
        path: 'correct',
        name: 'correct',
        component: () => import('@/views/ability/correct'),
        meta: { title: '校准/检定能力', perms: ['correct_view'] }
      } ,
      {
        path: 'qualityTask',
        name: 'QualityTask',
        component: () => import('@/views/ability/qualityTask.vue'),
        meta: { title: '资质报送任务' ,perms:['quli_task']}
      },
      {
        path: 'qualityTaskDo',
        name: 'qualityTaskDo',
        component: () => import('@/views/ability/qualityTaskDo.vue'),
        meta: { title: '任务详情'},
        hidden: true
      },
      {
        path: 'mQualityTask',
        name: 'mQualityTask',
        component: () => import('@/views/ability/mQualityTask.vue'),
        meta: { title: '我的资质报送任务', perms: ['qtask_my'] }
      },
      /*{
        path: 'qactionMy',
        name: 'qactionMy',
        component: () => import('@/views/ability/qactionMy.vue'),
        meta: { title: '资质报送操作', perms: ['qtask_my'] }
      },*/
      {
        path: 'recordselect',
        name: 'Recordselect',
        component: () => import('@/views/ability/recordselect.vue'),
        meta: { title: '资质能力报送查询', perms: ['record_view'] }
      },
    ]

  }
  ,
  {
    path: '/consulting',
    component: Layout,
    redirect: '/consulting/',
    name: 'consulting',
    meta: { title: '资讯资料分享', icon: 'guide', perms: ['consulting_views'] },
    alwaysShow: true,
    children: [
      {
        path: 'policy',
        name: 'policy',
        component: () => import('@/views/consulting/policy.vue'),
        meta: { title: '政策资讯', perms: ['policy_view'] }
      },
      {
        path: 'regulatory',
        name: 'regulatory',
        component: () => import('@/views/consulting/regulatory.vue'),
        meta: { title: '监管信息', perms: ['regulatory_view'] }
      }, {
        path: 'professional',
        name: 'professional',
        component: () => import('@/views/consulting/professional.vue'),
        meta: { title: '专业领域要求', perms: ['professional_view'] }
      }, {
        path: 'validation',
        name: 'validation',
        component: () => import('@/views/consulting/validation.vue'),
        meta: { title: '能力验证', perms: ['validation_view'] }
      },
    ]
  },
  {
    path: '/supervision',
    component: Layout,
    redirect: '/supervision/task',
    name: 'Supervision',
    meta: { title: '日常监督', icon: 'guide', perms: ['supervision'] },
    alwaysShow: true,
    children: [
      {
        path: 'content',
        name: 'Content',
        component: () => import('@/views/supervision/content.vue'),
        meta: { title: '材料清单', perms: ['content'] }
      },
      {
        path: 'task',
        name: 'Task',
        component: () => import('@/views/supervision/task.vue'),
        meta: { title: '报送任务', perms: ['task_view'] }
      },
      {
        path: 'mytask',
        name: 'myTask',
        component: () => import('@/views/supervision/mytask.vue'),
        meta: { title: '我的报送任务', perms: ['record_view'] }
      },
      {
        path: 'record',
        name: 'Record',
        component: () => import('@/views/supervision/record.vue'),
        meta: { title: '报送材料查询', perms: ['record_view'] }
      },
      {
        path: 'taskdo/:id',
        name: 'Taskdo',
        component: () => import('@/views/supervision/taskdo.vue'),
        meta: { title: '报送任务执行', perms: ['task_view'] },
        hidden: true
      },
    ]
  },
  {
    path: '/qualityinspect',
    component: Layout,
    redirect: '/qualityinspect/task',
    name: 'Qualityinspect',
    meta: { title: '质量巡查', icon: 'inspect', perms: ['qualityinspect'] },
    alwaysShow: true,
    children: [
      
     
      {
        path: 'table',
        name: 'InspectTable',
        component: () => import('@/views/qualityinspect/inspectTable.vue'),
        meta: { title: '检查表', perms: ['inspecttask_create'] }
      },
      {
        path: 'task',
        name: 'inspeatTask',
        component: () => import('@/views/qualityinspect/inspeatTask.vue'),
        meta: { title: '巡查任务', perms: ['qualityinspect_view'] }
      },
      {
        path: 'inpecttaskdo/:id',
        name: 'InpectTaskdo',
        component: () => import('@/views/qualityinspect/inspecttaskdo.vue'),
        meta: { title: '报送任务执行', perms: ['qualityinspect_view'] },
        hidden: true
      },
      
      {
        path: 'myinspecttask',
        name: 'myinspectTask',
        component: () => import('@/views/qualityinspect/mytask.vue'),
        meta: { title: '我的任务', perms: ['my_inspecttask'] }
      },
      {
        path:'mytaskdos/:id',
        name: 'myTaskdos',
        component: () => import('@/views/qualityinspect/mytaskdo.vue'),
        meta: { title: '任务执行', perms: ['my_inspecttask'] },
        hidden: true
      },
      {
        path: 'InspectDoc',
        name: 'InspectDoc',
        component: () => import('@/views/qualityinspect/inspectdoc.vue'),
        meta: { title: '质量文档', perms: ['inspectdoc'] }
      },
    ]
  },
  {
    path: '/test',
    component: Layout,
    redirect: '/test/',
    name: 'TestVideo',
    meta: { title: '视频培训', icon: 'guide', perms: ['video_views'] },
    alwaysShow: true,
    children: [
      {
        path: 'videolist',
        name: 'videolist',
        component: () => import('@/views/testvideo/videolist.vue'),
        meta: { title: '视频列表', perms: ['video_view'] }
      },
      {
        path: 'upload',
        name: 'upload',
        component: () => import('@/views/testvideo/upload.vue'),
        meta: { title: '上传视频', perms: ['video_create'] }
      },
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/testvideo/index.vue'),
        meta: { title: '视频播放', perms: ['video_view'] },
        hidden: true
      },
      {
        path: 'videoStatistics',
        name: 'videoStatistics',
        component: () => import('@/views/testvideo/videoStatistics.vue'),
        meta: { title: '视频播放统计', perms: ['video_view'] },
        // hidden: true
      },
    ]
  },
  {
    path: '/pt',
    component: Layout,
    redirect: '/pt/',
    name: 'ProficiencyTest',
    meta: { title: '能力验证', icon: 'PT', perms: ['pt_view'] },
    alwaysShow: true,
    children: [
      {
        path: '',
        name: 'PT1',
        component: () => import('@/views/PT/index.vue'),
        meta: { title: '菜单一', perms: ['pt_view'] }
      },
      {
        path: 'msg',
        name: 'PT2',
        component: () => import('@/views/PT/index.vue'),
        meta: { title: '菜单二', perms: ['pt_view'] }
      },
    ]
  },
  {
    path: '/exam',
    component: Layout,
    redirect: '/exam/questions',
    name: 'exam',
    meta: { title: '考试', icon: 'PT', perms: ['pt_view'] },
    alwaysShow: true,
    children: [
      {
        path: 'classify',
        name: '题目分类',
        component: () => import('@/views/exam/classify.vue'),
        meta: { title: '题目分类', perms: ['pt_view'] }
      },
      {
        path: 'questions',
        name: '题目列表',
        component: () => import('@/views/exam/questions.vue'),
        meta: { title: '题目列表', perms: ['pt_view'] }
      },
      {
        path: 'questionCreate',
        name: '新增题目',
        component: () => import('@/views/exam/questioncreate.vue'),
        meta: { title: '新增题目'},
        hidden: true
      },
      {
        path: 'questionUpdate',
        name: '编辑题目',
        component: () => import('@/views/exam/questionupdate.vue'),
        meta: { title: '编辑题目'},
        hidden: true
      },
      {
        path: 'testPaper',
        name: '考试试卷',
        component: () => import('@/views/exam/testPaper.vue'),
        meta: { title: '考试试卷', perms: ['pt_view'] }
      },
      {
        path: 'paperCreate',
        name: '新建试卷',
        component: () => import('@/views/exam/testPaperCreate.vue'),
        meta: { title: '新建试卷'},
        hidden: true
      },
      {
        path: 'paperUpdate',
        name: '编辑试卷',
        component: () => import('@/views/exam/testPaperUpdate.vue'),
        meta: { title: '编辑试卷'},
        hidden: true
      },
      {
        path: 'index',
        name: '考试',
        component: () => import('@/views/exam/index.vue'),
        meta: { title: '考试', perms: ['pt_view'] }
      },
      {
        path: 'record',
        name: '考试记录',
        component: () => import('@/views/exam/examRecord.vue'),
        meta: { title: '考试记录', perms: ['pt_view'] }
      },
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/user',
    name: 'System',
    meta: { title: '系统管理', icon: 'example', perms: ['system_manage'] },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user.vue'),
        meta: { title: '用户管理', icon: 'user', perms: ['user_manage'] }
      },
      {
        path: 'organization',
        name: 'Organization',
        component: () => import('@/views/system/organization'),
        meta: { title: '部门管理', icon: 'tree', perms: ['org_manage'] }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role'),
        meta: { title: '角色管理', icon: 'lock', perms: ['role_manage'] }
      },
      {
        path: 'queryrecord',
        name: 'queryrecord',
        component: () => import('@/views/ability/queryrecord'),
        meta: { title: '查询日志', icon: 'table', perms: ['queryrecord_view'] }
      },
      {
        path: 'position',
        name: 'Postion',
        component: () => import('@/views/system/position'),
        meta: { title: '岗位管理', icon: 'position', perms: ['position_manage'] }
      },
      {
        path: 'dict',
        name: 'Dict',
        component: () => import('@/views/system/dict'),
        meta: { title: '数据字典', icon: 'example', perms: ['dict_manage'] }
      },
      {
        path: 'file',
        name: 'File',
        component: () => import('@/views/system/file'),
        meta: { title: '文件库', icon: 'documentation', perms: ['file_room'] }
      }
    ]
  },
  {
    path: '/develop',
    component: Layout,
    redirect: '/develop/perm',
    name: 'Develop',
    meta: { title: '开发配置', icon: 'example', perms: ['dev_set'] },
    children: [
      {
        path: 'perm',
        name: 'Perm',
        component: () => import('@/views/system/perm'),
        meta: { title: '权限菜单', icon: 'example', perms: ['perm_manage'] }
      },
      {
        path: 'form-gen-link',
        component: Layout,
        children: [
          {
            path: 'https://jakhuang.github.io/form-generator/',
            meta: { title: '表单设计器', icon: 'link', perms: ['dev_form_gen'] }
          }
        ]
      },
      {
        path: 'docs-link',
        component: Layout,
        children: [
          {
            path: process.env.VUE_APP_BASE_API + '/docs/',
            meta: { title: '接口文档', icon: 'link', perms: ['dev_docs'] }
          }
        ]
      },
      {
        path: 'admin-link',
        component: Layout,
        children: [
          {
            path: process.env.VUE_APP_BASE_API + '/admin/',
            meta: { title: 'Django后台', icon: 'link', perms: ['dev_admin'] }
          }
        ]
      }
    ]
  },
  // 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
