import Vue from 'vue'
import Router from 'vue-router'
import _import from './_import.js'
Vue.use(Router);

// const error403 = (r) => {
//   import('views/errorPage/403.vue').then((module) => {
//     r(module)
//   })
// };
// const error404 = (r) => {
//   import('views/errorPage/404.vue').then((module) => {
//     r(module)
//   })
// };
// const error500 = (r) => {
//   import('views/errorPage/500.vue').then((module) => {
//     r(module)
//   })
// };
const errorPage = (r) => {
  import('views/errorPage/index.vue').then((module) => {
    r(module)
  })
};
// 页面刷新时，重新赋值token
if (window.sessionStorage.getItem('token')) {
  store.commit(types.LOGIN, window.sessionStorage.getItem('token'))
}
export const constantRouterMap = [
  {
    path: '/',
    name: '/',
    redirect: 'login',
  },
  {
    path: '/login',
    name: '登录',
    component: _import('login','index')
  },
  {
    path: '/index',
    name: 'index',
    component: _import('index','index'),
  },
  {
    path: '/contacts',
    name: '通讯录',
    redirect: 'administrativeFrame',
    component: _import('contacts','index'),
    children: [
      // 通讯录
      {
        path: '/administrativeFrame',
        name: '行政架构',
        component: _import('contacts','administrativeFrame')
      },
      {
        path: "/employeeIo",
        name: "批量导入/导出",
        component: _import('contacts','employeeIo')
      },
      {
        path: '/addDepartment',
        name: '添加部门',
        component: _import('contacts','addDepartment')
      },
      {
        path: '/addClerk',
        name: '添加店员',
        component: _import('contacts','addClerk')
      },
      {
        path: '/storeFrame',
        name: '门店架构',
        component: _import('contacts','storeFrame')
      },
      {
        path: '/addGroup',
        name: '添加子分组',
        component: _import('contacts','addGroup')
      },
      {
        path: '/storeIo',
        name: '门店导入/导出',
        component: _import('contacts','storeIo')
      },
      {
        path: '/storeInfo',
        name: '编辑门店',
        component: _import('contacts','storeInfo')
      },
      {
        path: "/recycle",
        name: "门店回收站",
        component: _import('contacts','recycle')
      },
      {
        path: '/employee',
        name: '在职员工',
        component: _import('contacts','employee')
      },
      {
        path: '/unemployee',
        name: '离职员工',
        component: _import('contacts','unemployee')
      },
      {
        path: '/fileSet',
        name: '档案设置',
        component: _import('contacts','fileSet')
      },
      {
        path: '/recordInfo',
        name: '编辑员工信息',
        component: _import('contacts','recordInfo')
      },
      {
        path: '/recordIo',
        name: '导入导出员工档案',
        component: _import('contacts','recordIo')
      },
      {
        path: '/shareContact',
        name: '共享通讯录',
        component: _import('contacts','shareContact')
      },
      {
        path: "/shareCode",
        name: '共享通讯录二维码',
        component: _import('contacts','shareCode')
      },
      {
        path: "/employeeRecord",
        name: '在职员工',
        component: _import('contacts','employeeRecord')
      }
    ]
  },
  {
    // 企业应用
    path: '/enterpriseApp',
    name: '企业应用',
    component: _import('enterpriseApp','index'),
  },
  {
    // 审核中心
    path: '/reviewCenter',
    name: '审核中心',
    redirect: 'unreview',
    component: _import('reviewCenter','index'),
    children: [
      {
        path: '/reviewed',
        name: '已审核',
        component: _import('reviewCenter','reviewed')
      },
      {
        path: '/unreview',
        name: '未审核',
        component: _import('reviewCenter','unreview')
      },
    ]
  },
  {
    // 设置模块
    path: '/setCenter',
    name: '设置',
    redirect: 'companyAddress',
    component: _import('setting','index'),
    children: [
      {
        path: '/companyAddress',
        name: '企业地址',
        component: _import('setting','companyAddress')
      },
      {
        path: '/companyCertify',
        name: '企业认证',
        component: _import('setting','companyCertify')
      },
      {
        path: '/staffDetails',
        name: '员工详情字段',
        component: _import('setting','staffDetails')
      },
      {
        path: '/storePermission',
        name: '门店权限设置',
        component: _import('setting','storePermission')
      },
      {
        path: '/replaceAdmin',
        name: '更换超级管理员',
        component: _import('setting','replaceAdmin')
      },
      {
        path: '/setChildAdmin',
        name: '设置子管理员',
        component: _import('setting','setChildAdmin')
      },
      {
        path: '/addAdmin',
        name: '添加管理员',
        component: _import('setting','addAdmin')
      },
      {
        path: '/addAdminRole',
        name: '添加管理员角色',
        component: _import('setting','addAdminRole')
      }
    ]
  },
  {
    path: '/staffRecordsTemplate',
    name: '员工档案设置',
    component: _import('contacts','staffRecordsTemplate')
  },
  {
    path: '/403',
    name: '无权访问',
    component: errorPage
  },
  {
    path: '/404',
    name: 'error404',
    component: errorPage
  },
  {
    path: '/500',
    name: 'error500',
    component: errorPage
  },
  { path: '*', redirect: '/404', hidden: true },
];
export default new Router({
  // mode:'history',
  routes: constantRouterMap,
  scrollBehavior: () => ({ y: 0 }),
})
