import type { Route } from '@/global'

const Layout = () => import('@/layouts/index.vue')

const routes: Route.recordRaw[] = [
  {
    path: '/measure',
    component: Layout,
    redirect: '/measure/bench',
    name: 'MeasureBench',
    meta: {
      title: '工作台',
      icon: 'ep:key',
      auth: '/measure/bench',
    },
    children: [
      {
        path: 'bench',
        name: 'MeasureBenchPage',
        component: () => import('@/views/measure/bench/bench.vue'),
        meta: {
          title: '工作台',
          auth: '/measure/bench',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/measure',
        },
      },
    ],
  },
  {
    path: '/file',
    component: Layout,
    redirect: '/file/quality',
    name: 'File',
    meta: {
      title: '计量文件',
      icon: 'ep:key',
      auth: '/file',
    },
    children: [
      {
        path: 'quality',
        name: 'QualityFile',
        component: () => import('@/views/measure/file/quality.vue'),
        meta: {
          title: '质量文件',
          icon: 'ep:key',
          auth: '/file/quality',
        },
      },
      {
        path: 'rules',
        name: 'Rules',
        component: () => import('@/views/measure/file/rules.vue'),
        meta: {
          title: '规章制度',
          icon: 'ep:key',
          auth: '/file/rules',
        },
      },
      {
        path: 'manageMethod',
        name: '',
        component: () => import('@/views/measure/file/manageMethod.vue'),
        meta: {
          title: '管理办法',
          icon: 'ep:key',
          auth: '/file/ManageMethod',
        },
      },
      {
        path: 'testingMethod',
        name: '',
        component: () => import('@/views/measure/file/testingMethod.vue'),
        meta: {
          title: '校准检测办法',
          icon: 'ep:key',
          auth: '/file/testingMethod',
        },
      },
      {
        path: 'measureRule',
        name: '',
        component: () => import('@/views/measure/file/measureRule.vue'),
        meta: {
          title: '计量规程',
          icon: 'ep:key',
          auth: '/file/measureRule',
        },
      },
      {
        path: ':type/:id?',
        name: 'measureFileDetail',
        component: () => import('@/views/measure/file/components/addDialog.vue'),
        meta: {
          title: '计量文件',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/file/quality',
        },
        // 独享守卫，根据form的路由动态修改meta中的activeMenu
        beforeEnter: (to, from, next) => {
          const type = from.path.split('/')[from.path.split('/').length - 1]
          console.log(type)
          switch (type) {
            case 'quality':
              to.meta.activeMenu = '/file/quality'
              to.meta.title = '质量文件'
              break
            case 'rules':
              to.meta.activeMenu = '/file/rules'
              to.meta.title = '规章制度'
              break
            case 'remind':
              to.meta.activeMenu = '/file/quality'
              to.meta.title = '管理办法'
              break
            case 'manageMethod':
              to.meta.activeMenu = '/file/manageMethod'
              to.meta.title = '管理办法'
              break
            case 'testingMethod':
              to.meta.activeMenu = '/file/testingMethod'
              to.meta.title = '校准检测办法'
              break
            case 'measureRule':
              to.meta.activeMenu = '/file/measureRule'
              to.meta.title = '计量规程'
              break
          }
          next()
        },
      },
      {
        path: 'approve',
        name: '',
        component: () => import('@/views/measure/file/approve.vue'),
        meta: {
          title: '文件审批',
          icon: 'ep:key',
          auth: '/file/approve',
        },
      },
    ],
  },
  {
    path: '/person',
    component: Layout,
    redirect: '/measure/person/list',
    name: 'Person',
    meta: {
      title: '计量人员',
      icon: 'ep:key',
      auth: '/measure/person',
    },
    children: [
      {
        path: 'list',
        name: 'PersonList',
        component: () => import('@/views/measure/person/list.vue'),
        meta: {
          title: '计量人员列表',
          icon: 'ep:key',
          auth: '/measure/person/list',
        },
      },
      {
        path: ':type/:id?',
        name: 'PersonListDetail',
        component: () => import('@/views/measure/person/components/addPerson.vue'),
        meta: {
          title: '计量人员',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/person/list',
        },
      },
      {
        path: 'certificateLog',
        name: 'CertificateLog',
        component: () => import('@/views/measure/person/certificateLog.vue'),
        meta: {
          title: '证书记录',
          icon: 'ep:key',
          auth: '/measure/person/certificateLog',
        },
      },
      {
        path: ':type/:id?',
        name: 'CertificateLogDetail',
        component: () => import('@/views/measure/person/components/addRecord.vue'),
        meta: {
          title: '证书记录',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/measure/person/certificateLog',
        },
        // 独享守卫，根据form的路由动态修改meta中的activeMenu
        beforeEnter: (to, from, next) => {
          const type = from.path.split('/')[from.path.split('/').length - 1]
          console.log(type)
          switch (type) {
            case 'certificateLog':
              to.meta.activeMenu = '/person/certificateLog'
              break
            case 'remind':
              to.meta.activeMenu = '/person/remind'
              break
          }
          next()
        },
      },
      {
        path: 'remind',
        name: 'Remind',
        component: () => import('@/views/measure/person/remind.vue'),
        meta: {
          title: '证书到期提醒',
          icon: 'ep:key',
          auth: '/measure/person/remind',
        },
      },
    ],
  },
  {
    path: '/train',
    component: Layout,
    redirect: '/measure/train/plan',
    name: 'Train',
    meta: {
      title: '培训管理',
      icon: 'ep:key',
      auth: '/measure/train',
    },
    children: [
      {
        path: 'plan',
        name: 'TrainPlan',
        component: () => import('@/views/measure/train/plan.vue'),
        meta: {
          title: '培训计划',
          icon: 'ep:key',
          auth: '/measure/train/plan',
        },
      },
      {
        path: ':type/:id?',
        name: 'PlanAdd',
        component: () => import('@/views/measure/train/planAdd.vue'),
        meta: {
          title: '培训计划',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/train/plan',
        },
      },
      {
        path: 'trainPlanApprove',
        name: 'TrainPlanApprove',
        component: () => import('@/views/measure/train/trainPlanApprove.vue'),
        meta: {
          title: '培训计划审批',
          icon: 'ep:key',
          auth: '/measure/train/trainPlanApprove',
        },
      },
      {
        path: 'trainPlanApprove/:type/:id?',
        name: 'listPageAdd',
        component: () => import('@/views/measure/train/components/listPageAdd.vue'),
        meta: {
          title: '培训计划审批',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/train/trainPlanApprove',
        },
      },
      {
        path: 'trainLog',
        name: 'TrainLog',
        component: () => import('@/views/measure/train/trainLog.vue'),
        meta: {
          title: '培训记录',
          icon: 'ep:key',
          auth: '/measure/train/trainLog',
        },
      },
      {
        path: 'trainLog/:type/:id?',
        name: 'planlogAdd',
        component: () => import('@/views/measure/train/trainLogAdd.vue'),
        meta: {
          title: '培训记录',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/train/trainLog',
        },
      },
    ],
  },
  {
    path: '/measureDept',
    component: Layout,
    redirect: '/measure/measureDept/bm',
    name: 'MeasureDept',
    meta: {
      title: '计量组织',
      icon: 'ep:key',
      auth: '/measure/measureDept',
    },
    children: [
      {
        path: 'bm',
        name: 'Bm',
        component: () => import('@/views/measure/measureDept/bm.vue'),
        meta: {
          title: '部门管理',
          icon: 'ep:key',
          auth: '/measure/measureDept/bm',
        },
      },
      {
        path: 'ks',
        name: 'Ks',
        component: () => import('@/views/measure/measureDept/ks.vue'),
        meta: {
          title: '科室管理',
          icon: 'ep:key',
          auth: '/measure/measureDept/ks',
        },
      },
      {
        path: 'gcz',
        name: 'Gcz',
        component: () => import('@/views/measure/measureDept/gcz.vue'),
        meta: {
          title: '工程组管理',
          icon: 'ep:key',
          auth: '/measure/measureDept/gcz',
        },
      },
      {
        path: ':type/:id?',
        name: 'MeasureDeptDetail',
        component: () => import('@/views/measure/measureDept/components/addDialog.vue'),
        meta: {
          title: '计量组织',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/measureDept/bm',
        },
        // 独享守卫，根据form的路由动态修改meta中的activeMenu
        // 当不同页面中 使用了相同的 编辑/详情路由
        beforeEnter: (to, from, next) => {
          const type = from.path.split('/')[from.path.split('/').length - 1]
          switch (type) {
            case 'bm':
              to.meta.activeMenu = '/measureDept/bm'
              break
            case 'ks':
              to.meta.activeMenu = '/measureDept/ks'
              break
            case 'gcz':
              to.meta.activeMenu = '/measureDept/gcz'
              break
          }
          next()
        },
      },
    ],
  },
  {
    path: '/source',
    component: Layout,
    redirect: '/measure/measureSource/list',
    name: 'MeasureSource',
    meta: {
      title: '溯源供方',
      icon: 'ep:key',
      auth: '/measure/measureSource',
    },
    children: [
      {
        path: 'list',
        name: 'MeasureSourceList',
        component: () => import('@/views/measure/source/list.vue'),
        meta: {
          title: '溯源供方列表',
          icon: 'ep:key',
          auth: '/measure/measureSource/list',
        },
      },
      {
        path: ':type/:id?',
        name: 'ListSourceAdd',
        component: () => import('@/views/measure/source/listAdd.vue'),
        meta: {
          title: '溯源供方列表',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/source/list',
        },
      },
      {
        path: 'approve',
        name: 'SourceApprove',
        component: () => import('@/views/measure/source/approve.vue'),
        meta: {
          title: '溯源供方审批',
          icon: 'ep:key',
          auth: '/measure/measureSource/approve',
          cache: true,
        },
      },
      {
        path: 'approve/:type/:id?',
        name: 'ListpageSourceAdd',
        component: () => import('@/views/measure/source/components/sourceApprovalDetail.vue'),
        meta: {
          title: '溯源供方审批',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/source/approve',
        },
      },
    ],
  },
  {
    path: '/price',
    component: Layout,
    redirect: '/price/list',
    name: 'MeasurePrice',
    meta: {
      title: '价格库',
      icon: 'ep:key',
      auth: '/measure/measurePrice',
    },
    children: [
      {
        path: 'list',
        name: 'measurePriceList',
        component: () => import('@/views/measure/price/list.vue'),
        meta: {
          title: '价格列表',
          icon: 'ep:key',
          auth: '/measure/measurePrice/list',
        },
      },
      {
        path: ':type/:id?',
        name: 'measurePriceDetail',
        component: () => import('@/views/measure/price/priceAdd.vue'),
        meta: {
          title: '价格列表',
          icon: 'ep:key',
          sidebar: false,
          breadcrumb: true,
          activeMenu: '/price/list',
        },
      },
    ],
  },
]

export default routes
