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

Vue.use(Router)

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

export const routes = [
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/workbench'
  },
  {
    path: '/workbench',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/Workbench/index'),
      meta: { title: '首页', icon: 'el-icon-house' }
    }]
  },
  {
    path: '/statistics',
    component: Layout,
    permission: 'statistics',
    meta: { title: '统计查询', icon: 'el-icon-pie-chart' },
    children: [
      {
        path: 'note',
        permission: 'statistics:note',
        meta: { title: '短信账单' },
        component: () => import('@/views/Statistics/NoteBill/index')
      },
      {
        path: 'unit',
        permission: 'statistics:unit',
        meta: { title: '单位账单' },
        component: () => import('@/views/Statistics/UnitBill/index')
      },
      {
        path: 'statistics',
        permission: 'statistics:statistics',
        meta: { title: '统计报表' },
        component: () => import('@/views/Statistics/StatisticalForm/index.vue')
      },
      {
        path: 'down',
        permission: 'statistics:down',
        meta: { title: '下行记录查询' },
        component: () => import('@/views/Statistics/DownlinkRecordQuery/index.vue')
      },
      {
        path: 'upgoing',
        permission: 'statistics:upgoing',
        meta: { title: '上行记录查询' },
        component: () => import('@/views/Statistics/UplinkRecordQuery/index.vue')
      }
    ]
  },

  {
    path: '/account',
    component: Layout,
    permission: 'account',
    meta: { title: '账户管理', icon: 'el-icon-guide' },
    children: [{
      path: 'info',
      permission: 'account:info',
      component: () => import('@/views/Account/AccountInformation/index'),
      meta: { title: '账户信息' }
    }, {
      path: 'recharge',
      permission: 'account:recharge',
      component: () => import('@/views/Account/UnitRecharge/index'),
      meta: { title: '单位充值' }
    }, {
      path: 'noteaccount',
      permission: 'account:noteaccount',
      component: () => import('@/views/Account/NoteAccount/index'),
      meta: { title: '短信账号' }
    },
    {
      path: 'signature',
      permission: 'account:signature',
      component: () => import('@/views/Account/SignatureManagement/index'),
      meta: { title: '签名管理' }
    },
    {
      path: 'billing',
      permission: 'account:billing',
      component: () => import('@/views/Account/Billing/index.vue'),
      meta: { title: '计费管理' }
    },
    {
      path: 'flowrate',
      permission: 'account:flowrate',
      component: () => import('@/views/Account/FlowRate/index.vue'),
      meta: { title: '流量管理' }
    },
    {
      path: 'security',
      permission: 'account:security',
      component: () => import('@/views/Account/Security/index.vue'),
      meta: { title: '安全管控' }
    },
    {
      path: 'topup',
      permission: 'account:security',
      component: () => import('@/views/Account/TopUp/index.vue'),
      meta: { title: '账户充值' }
    },
    {
      path: 'subaccount/:id?',
      component: () => import('@/views/Account/AccountInformation/components/subAccount'),
      hidden: true
    }
    ]
  },
  {
    path: '/pole',
    component: Layout,
    permission: 'pole',
    meta: { title: '一体杆管理', icon: 'el-icon-refrigerator' },
    children: [{
      path: 'info',
      permission: 'pole:info',
      component: () => import('@/views/Rod/RodManage'),
      meta: { title: '一体杆管理' }
    }, {
      path: 'waring',
      permission: 'pole:warning',
      component: () => import('@/views/Rod/RodWarn'),
      meta: { title: '告警记录' }
    }]
  },
  {
    path: '/sys',
    component: Layout,
    permission: 'sys',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [{
      path: 'organ',
      permission: 'sys:organ',
      component: () => import('@/views/System/Organ/index'),
      meta: { title: '机构管理' }
    }, {
      path: 'journal',
      permission: 'sys:journal',
      component: () => import('@/views/System/Journal/index'),
      meta: { title: '操作日志' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

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

const router = createRouter()

// 重置路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher
}

export default router
