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

Vue.use(Router)

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

/* Router Modules */

/** note: sub-menu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']    will control the page roles (you can set multiple roles)
    title: 'title'               the name show in sub-menu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if true, the page will no be cached(default is false)
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
    affix: true                  if true, the tag will affix in the tags-view
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  /* {
    path: '/login',
    component: () => import('@/views/question/kindergarten'),
    hidden: true
  },*/
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    redirect: 'dashboard',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', noCache: true, affix: true }
      }
    ]
  }
]

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

export const asyncRouterMap = [
  /* {
    path: '/permission',
    component: Layout,
    redirect: '/permission/index',
    alwaysShow: true, // will always show the root menu
    meta: {
      title: 'permission',
      icon: 'lock',
      roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: 'pagePermission',
          roles: ['admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: 'directivePermission'
          // if do not set roles, means: this page does not require permission
        }
      }
    ]
  },*/
  // role = 1 管理员
  // role = 2 定制师
  // role = 3 地区管理员
  {
    path: '/goodsinfo',
    component: Layout,
    name: 'goodsinfo',
    meta: { title: '商品信息', icon: 'international' },
    children: [
      {
        path: 'goodsmngr',
        component: () => import('@/views/goodsinfo'),
        name: 'goodsmngr',
        meta: { title: '商品管理', icon: 'international' }
      },
      {
        path: 'category',
        component: () => import('@/views/goodsinfo/category'),
        name: 'category',
        meta: { title: '商品分类', icon: 'international' }
      }

    ]
  },
  {
    path: '/customerinfo',
    component: Layout,
    name: 'customerinfo',
    meta: { title: '客户信息', icon: 'international' },
    children: [
      {
        path: 'customermngr',
        component: () => import('@/views/customerinfo'),
        name: 'customermngr',
        meta: { title: '客户管理', icon: 'international' }
      },
      {
        path: 'address',
        component: () => import('@/views/customerinfo/address'),
        name: 'address',
        meta: { title: '客户地址', icon: 'international' }
      },
      {
        path: 'cuser',
        component: () => import('@/views/customerinfo/cuser'),
        name: 'cuser',
        meta: { title: '微信用户', icon: 'international' }
      }
    ]
  },
  {
    path: '/userinfo',
    component: Layout,
    children: [{
      path: 'userinfo',
      component: () =>
        import('@/views/userinfo'),
      name: 'userinfo',
      meta: { title: '用户管理', icon: 'dashboard' }
    }]
  },
  {
    path: '/supplier',
    component: Layout,
    children: [{
      path: 'supplier',
      component: () =>
        import('@/views/supplier'),
      name: 'supplier',
      meta: { title: '供应商', icon: 'dashboard' }
    }]
  },
  {
    path: '/ordermngr',
    component: Layout,
    children: [{
      path: 'ordermngr',
      component: () =>
        import('@/views/ordermngr'),
      name: 'ordermngr',
      meta: { title: '订单管理', icon: 'dashboard' }
    }]
  },
  {
    path: '/warehouse',
    component: Layout,
    children: [{
      path: 'warehouse',
      component: () =>
        import('@/views/warehouse'),
      name: 'ordermngr',
      meta: { title: '仓库管理', icon: 'dashboard' }
    }]
  },
  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: { title: '系统管理', icon: 'international' },
    children: [
      {
        path: 'user',
        component: () => import('@/views/system/user'),
        name: 'user',
        meta: { title: '系统用户', icon: 'international' }
      },
      {
        path: 'memberpackage',
        component: () => import('@/views/memberpackage'),
        name: 'memberpackage',
        meta: { title: '会员套餐', icon: 'international' }
      },
      {
        path: 'memberorder',
        component: () => import('@/views/memberorder'),
        name: 'memberorder',
        meta: { title: '会员订单', icon: 'international' }
      },
      {
        path: 'opinion',
        component: () => import('@/views/system/opinion'),
        name: 'opinion',
        meta: { title: '意见反馈', icon: 'international' }
      },
      {
        path: 'log',
        component: () => import('@/views/system/log'),
        name: 'log',
        meta: { title: '日志管理', icon: 'international' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
