import Vue from 'vue'
import Router from 'vue-router'
import layout from '../views/layout/layout'

const _import = require('./_import_' + process.env.NODE_ENV)

if(Router.version >= '3.1.0'){
  const originalPush = Router.prototype.push
  Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
  }
}

Vue.use(Router)

export const constantRouterMap = [
  {path: '/', redirect: '/login'},
  {path: '/login', component: _import('login/index'), name: 'login'},
  {path: '/login-by-backend', component: _import('login/login-by-backend'), name: 'login-by-backend'},
  {path: '/modify-password/:username', component: _import('login/modify-password'), name: 'modify-password'},
  // { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  // { path: '/404', component: _import('errorPage/404'), hidden: true },
  // { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '/dashboard/index',
    component: layout,
    redirect: '/dashboard/index',
    children: [{
      path: '/dashboard/index',
      component: _import('dashboard/index'),
      name: 'dashboard_index',
      meta: {
        title: '控制台',
        breadcrumb: [
          {title: '首页', path: '/dashboard/index'},
        ],
      },
    }]
  },
  {
        path: '/shop',
        component: layout,
        redirect: '/shop/dec-order-list',
        children: [
            {
                path: '/shop/dec-order-list',
                component: _import('shop/dec-order-list'),
                name: 'shop_dec-order-list',
                meta: {
                    title: '报单列表',
                    breadcrumb: [
                        {title: '首页', path: '/dashboard/index'},
                        {title: '商城管理', path: '/shop/dec-order-list'},
                    ],
                },
            },
            {
                path: '/shop/order-list',
                component: _import('shop/order-list'),
                name: 'shop_order-list',
                meta: {
                    title: '订单列表',
                    breadcrumb: [
                        {title: '首页', path: '/dashboard/index'},
                        {title: '商城管理', path: '/shop/dec-order-list'},
                    ],
                },
            },
            {
                path: '/shop/index',
                component: _import('shop/index'),
                name: 'shop_index',
                meta: {
                    title: '商品列表',
                    breadcrumb: [
                        {title: '首页', path: '/dashboard/index'},
                        {title: '商城管理', path: '/shop/dec-order-list'},
                    ],
                },
            },
            {
                path: '/shop/order',
                component: _import('shop/order'),
                name: 'shop_order',
                meta: {
                    title: '商品结算',
                    breadcrumb: [
                        {title: '首页', path: '/dashboard/index'},
                        {title: '商城管理', path: '/shop/dec-order-list'}
                    ],
                },
            },
            {
                path: '/shop/goods-detail/:id',
                component: _import('shop/goods-detail'),
                name: 'shop_goods-detail',
                meta: {
                    title: '商品详情',
                    breadcrumb: [
                        {title: '首页', path: '/dashboard/index'},
                        {title: '商城管理', path: '/shop/dec-order-list'},
                    ],
                },
            },

        ],
    },
  {
    path: '/user',
    component: layout,
    redirect: '/user/index',
    children: [
      {
        path: '/user/index',
        component: _import('user/index'),
        name: 'user_index',
        meta: {
          title: '个人资料',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '会员管理', path: '/user/index'},
          ],
        },
      },
      {
          path: '/user/password',
          component: _import('user/password'),
          name: 'user_password',
          meta: {
              title: '重置密码',
              breadcrumb: [
                  {title: '首页', path: '/dashboard/index'},
                  {title: '会员管理', path: '/user/index'},
              ],
          },
      },
      {
        path: '/user/id-card',
        component: _import('user/id-card'),
        name: 'user_id-card',
        meta: {
          title: '上传身份证',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '会员管理', path: '/user/index'},
          ],
        },
      },
      {
        path: '/user/rec-user',
        component: _import('user/rec-user'),
        name: 'user_rec-user',
        meta: {
          title: '开拓会员列表',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '会员管理', path: '/user/index'},
          ],
        },
      },
      {
        path: '/user/bind',
        component: _import('user/bind'),
        name: 'user_bind',
        meta: {
          title: '点位绑定列表',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '会员管理', path: '/user/index'},
          ],
        },
      },
      {
        path: '/user/bind-edit/:id',
        component: _import('user/bind-edit'),
        name: 'user_bind-edit',
        meta: {
          title: '点位绑定编辑',
          highLight: '/user/bind',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '会员管理', path: '/user/index'},
            {title: '点位绑定列表', path: '/user/bind'},
          ],
        },
      },
      {
        path: '/user/dec',
        component: _import('user/dec'),
        name: 'user_dec',
        meta: {
          title: '报单管理',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '会员管理', path: '/user/index'},
          ],
        },
      },
    ]
  },
    {
        path: '/atlas',
        component: layout,
        redirect: '/atlas/network',
        children: [
            {
                path: '/atlas/network',
                component: _import('atlas/network'),
                name: 'atlas_network',
                meta: {
                    title: '安置网络',
                    breadcrumb: [
                        {title: '首页', path: '/dashboard/index'},
                        {title: '网络图谱', path: '/atlas/network'},
                    ],
                },
            },
        ]
    },
  {
    path: '/bonus',
    component: layout,
    redirect: '/bonus/index',
    children: [
      {
        path: '/bonus/index',
        component: _import('bonus/index'),
        name: 'bonus_index',
        meta: {
          title: '我的账户',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '奖金管理', path: '/bonus/index'},
          ],
        },
      },
      {
        path: '/bonus/new',
        component: _import('bonus/new'),
        name: 'bonus_new',
        meta: {
          title: '最新奖金',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '奖金管理', path: '/bonus/index'},
          ],
        },
      },
      {
        path: '/bonus/other',
        component: _import('bonus/other'),
        name: 'bonus_other',
        meta: {
          title: '往期奖金',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '奖金管理', path: '/bonus/index'},
          ],
        },
      },
      {
        path: '/bonus/real-time-perf',
        component: _import('bonus/real-time-perf'),
        name: 'bonus_real-time-perf',
        meta: {
          title: '实时业绩',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '奖金管理', path: '/bonus/index'},
          ],
        },
      },
      {
        path: '/bonus/fc-point',
        component: _import('bonus/fc-point'),
        name: 'bonus_fc-point',
        meta: {
          title: '房产积分',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '奖金管理', path: '/bonus/index'},
          ],
        },
      },

    ]
  },
  {
    path: '/article',
    component: layout,
    redirect: '/article/list',
    children: [
      {
        path: '/article/list/:cid',
        component: _import('article/list'),
        name: 'article_list',
        meta: {
          title: '文章列表',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '文章管理', path: '/article/list'},
          ],
        },
      },
      {
        path: '/article/detail/:id',
        component: _import('article/detail'),
        name: 'article_detail',
        meta: {
          title: '文章详情',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '文章管理', path: '/article/list'},
          ],
        },
      },
    ]
  },
  {
    path: '/message',
    component: layout,
    redirect: '/message/list',
    children: [
      {
        path: '/message/list',
        component: _import('message/list'),
        name: 'message_list',
        meta: {
          title: '站内信列表',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '站内信', path: '/message/list'},
          ],
        },
      },
      {
        path: '/message/detail/:id',
        component: _import('message/detail'),
        name: 'message_detail',
        meta: {
          title: '站内信详情',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '站内信', path: '/message/list'},
          ],
        },
      },
    ]
  },
  {
    path: '/finance',
    component: layout,
    redirect: '/finance/withdraw',
    children: [
      {
        path: '/finance/reconsume-pool-flow',
        component: _import('finance/reconsume-pool-flow'),
        name: 'finance_reconsume-pool-flow',
        meta: {
          title: '会员复销池余额流水',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '财务管理', path: '/finance/withdraw'},
          ],
        },
      },
      {
        path: '/finance/withdraw',
        component: _import('finance/withdraw'),
        name: 'finance_withdraw',
        meta: {
          title: '提现明细',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '财务管理', path: '/finance/index'},
          ],
        },
      },
      {
        path: '/finance/withdraw-add',
        component: _import('finance/withdraw-add'),
        name: 'finance_withdraw-add',
        meta: {
          title: '我要提现',
          highLight: '/finance/withdraw',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '财务管理', path: '/finance/index'},
            {title: '提现明细', path: '/finance/withdraw'},
          ],
        },
      },
      {
        path: '/finance/dec-list',
        component: _import('finance/dec-list'),
        name: 'finance_dec-list',
        meta: {
          title: '报单订货单列表',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '财务管理', path: '/finance/index'},
          ],
        },
      },
      {
        path: '/finance/transfer-list',
        component: _import('finance/transfer-list'),
        name: 'finance_transfer-list',
        meta: {
          title: '转账记录',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '财务管理', path: '/finance/index'},
          ],
        },
      },
      {
        path: '/finance/transfer-add',
        component: _import('finance/transfer-add'),
        name: 'finance_transfer-add',
        meta: {
          title: '我要转账',
          highLight: '/finance/transfer-list',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '财务管理', path: '/finance/index'},
            {title: '转账记录', path: '/finance/transfer-list'},
          ],
        },
      },
        {
            path: '/finance/recharge',
            component: _import('finance/recharge'),
            name: 'finance_recharge',
            meta: {
                title: '充值明细',
                breadcrumb: [
                    {title: '首页', path: '/dashboard/index'},
                    {title: '财务管理', path: '/finance/index'},
                ],
            },
        },
        {
            path: '/finance/recharge-add',
            component: _import('finance/recharge-add'),
            name: 'finance_recharge-add',
            meta: {
                title: '我要充值',
                highLight: '/finance/recharge',
                breadcrumb: [
                    {title: '首页', path: '/dashboard/index'},
                    {title: '财务管理', path: '/finance/index'},
                    {title: '提现明细', path: '/finance/withdraw'},
                ],
            },
        },
    ]
  },
  {
    path: '/config',
    component: layout,
    redirect: '/config/base',
    children: [
      {
        path: '/config/receive-address-list',
        component: _import('config/receive-address-list'),
        name: 'config_receive-address-list',
        meta: {
          title: '收货地址管理',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '设置', path: '/config/base'},
          ],
        },
      },
      {
        path: '/config/receive-address-add',
        component: _import('config/receive-address-edit'),
        name: 'config_receive-address-add',
        meta: {
          title: '添加收货地址',
          highLight: '/config/receive-address-list',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '设置', path: '/config/base'},
            {title: '收货地址管理', path: '/config/receive-address-list'},
          ],
        },
      },
      {
        path: '/config/receive-address-edit/:id',
        component: _import('config/receive-address-edit'),
        name: 'config_receive-address-edit',
        meta: {
          title: '编辑收货地址',
          highLight: '/config/receive-address-list',
          breadcrumb: [
            {title: '首页', path: '/dashboard/index'},
            {title: '设置', path: '/config/base'},
            {title: '收货地址管理', path: '/config/receive-address-list'},
          ],
        },
      },

    ]
  },
]

export default new Router({
  routes: constantRouterMap
})
