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

Vue.use(Router)

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

/** note: Submenu 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 : {
    perms: ['GET /aaa','POST /bbb']     will control the page perms (you can set multiple perms)
    title: 'title'               the name show in submenu 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)
  }
**/
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: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    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: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }
]

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

export const asyncRouterMap = [
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'userManage',
    meta: {
      title: '会员中心',
      icon: 'people'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/user'),
        name: 'user',
        meta: {
          perms: ['GET /admin/user/list'],
          title: '会员管理',
          noCache: true,
          icon: 'user'
        }
      },
      {
        path: 'address',
        component: () => import('@/views/user/address'),
        name: 'address',
        meta: {
          perms: ['GET /admin/address/list'],
          title: '收货地址',
          noCache: true,
          icon: 'tree'
        }
      },
      {
        path: 'collect',
        component: () => import('@/views/user/collect'),
        name: 'collect',
        meta: {
          perms: ['GET /admin/collect/list'],
          title: '会员收藏',
          noCache: true,
          icon: 'clipboard'
        }
      },
      {
        path: 'footprint',
        component: () => import('@/views/user/footprint'),
        name: 'footprint',
        meta: {
          perms: ['GET /admin/footprint/list'],
          title: '会员足迹',
          noCache: true,
          icon: 'eye'
        }
      },
      {
        path: 'history',
        component: () => import('@/views/user/history'),
        name: 'history',
        meta: {
          perms: ['GET /admin/history/list'],
          title: '搜索历史',
          noCache: true,
          icon: 'marker'
        }
      },
      {
        path: 'feedback',
        component: () => import('@/views/user/feedback'),
        name: 'feedback',
        meta: {
          perms: ['GET /admin/feedback/list'],
          title: '意见反馈',
          noCache: true,
          icon: 'email'
        }
      }
    ]
  },

  {
    path: '/faq',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'faqManage',
    meta: {
      title: '智库管理',
      icon: 'eye'
    },
    children: [
      {
        path: 'category',
        component: () => import('@/views/faq/category'),
        name: 'category',
        meta: {
          perms: ['GET /admin/category/list', 'POST /admin/category/create', 'GET /admin/category/read', 'POST /admin/category/update', 'POST /admin/category/delete'],
          title: 'FAQ类目',
          noCache: true,
          icon: 'product-attr'
        }
      },
      {
        path: 'list',
        component: () => import('@/views/faq/list'),
        name: 'faqList',
        meta: {
          perms: ['GET /admin/faq/list', 'POST /admin/faq/delete'],
          title: 'FAQ列表',
          noCache: true,
          icon: 'product-list'
        }
      },
      {
        path: 'create',
        component: () => import('@/views/faq/create'),
        name: 'faqCreate',
        meta: {
          perms: ['POST /admin/faq/create', 'POST /admin/faq/update'],
          title: 'FAQ添加',
          noCache: true,
          icon: 'product-add'
        }
      },
      {
        path: 'comment',
        component: () => import('@/views/faq/comment'),
        name: 'faqComment',
        meta: {
          perms: ['GET /admin/comment/list', 'POST /admin/comment/delete'],
          title: 'FAQ评论',
          noCache: true,
          icon: 'product-comment'
        }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'mallManage',
    meta: {
      title: '订单中心',
      icon: 'shopping'
    },
    children: [
      {
        path: 'order',
        component: () => import('@/views/order/order'),
        name: 'order',
        meta: {
          perms: ['GET /admin/order/list', 'GET /admin/order/export', 'GET /admin/order/detail', 'POST /admin/order/import', 'POST /admin/order/refund', 'POST /admin/order/delete', 'POST /admin/order/reply'],
          title: '订单管理',
          noCache: true,
          icon: 'order'
        }
      },
      {
        path: 'aftersale',
        component: () => import('@/views/order/aftersale'),
        name: 'aftersale',
        meta: {
          perms: ['GET /admin/aftersale/list', 'GET /admin/aftersale/detail', 'POST /admin/order/receive', 'POST /admin/aftersale/complete', 'POST /admin/aftersale/reject'],
          title: '售后管理',
          noCache: true,
          icon: 'order-return'
        }
      },
      {
        path: 'pet',
        component: () => import('@/views/order/pet'),
        name: 'pet',
        meta: {
          perms: ['GET /admin/pet/list', 'GET /admin/pet/detail', 'POST /admin/pet/pose', 'POST /admin/pet/reject'],
          title: '宠物保险',
          noCache: true,
          icon: 'ums'
        }
      }
    ]
  },
  {
    path: '/parter',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'disManage',
    meta: {
      title: '合伙人',
      icon: 'star'
    },
    children: [
      {
        path: 'commission',
        component: () => import('@/views/parter/commission'),
        name: 'commission',
        meta: {
          perms: ['GET /admin/commission/list', 'GET /admin/commission/detail', 'GET /admin/commission/relation'],
          title: '分佣明细',
          noCache: true,
          icon: 'list'

        }
      },
      {
        path: 'cashout',
        component: () => import('@/views/parter/cashout'),
        name: 'cashout',
        meta: {
          perms: ['GET /admin/cashout/list', 'POST /admin/cashout/pass', 'GET /admin/cashout/reject'],
          title: '提现审核',
          noCache: true,
          icon: 'money'
        }
      },
      {
        path: 'join',
        component: () => import('@/views/parter/joinapply'),
        name: 'join',
        meta: {
          perms: ['GET /admin/join/list', 'POST /admin/join/pase', 'GET /admin/join/reject'],
          title: '合伙人申请',
          noCache: true,
          icon: 'guide 2'
        }
      }
    ]
  },
  {
    path: '/goods',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'goodsManage',
    meta: {
      title: '商品管理',
      icon: 'product'
    },
    children: [
      {
        path: 'category',
        component: () => import('@/views/goods/category'),
        name: 'category',
        meta: {
          perms: ['GET /admin/category/list', 'POST /admin/category/create', 'GET /admin/category/read', 'POST /admin/category/update', 'POST /admin/category/delete'],
          title: '商品类目',
          noCache: true,
          icon: 'product-attr'
        }
      },
      {
        path: 'list',
        component: () => import('@/views/goods/list'),
        name: 'goodsList',
        meta: {
          perms: ['GET /admin/goods/list', 'POST /admin/goods/delete'],
          title: '商品列表',
          noCache: true,
          icon: 'product-list'
        }
      },
      {
        path: 'create',
        component: () => import('@/views/goods/create'),
        name: 'goodsCreate',
        meta: {
          perms: ['POST /admin/goods/create'],
          title: '商品添加',
          noCache: true,
          icon: 'product-add'
        }
      },
      {
        path: 'edit',
        component: () => import('@/views/goods/edit'),
        name: 'goodsEdit',
        meta: {
          perms: ['GET /admin/goods/detail', 'POST /admin/goods/update', 'POST /admin/goods/catAndBrand'],
          title: '商品编辑',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'comment',
        component: () => import('@/views/goods/comment'),
        name: 'goodsComment',
        meta: {
          perms: ['GET /admin/comment/list', 'POST /admin/comment/delete'],
          title: '商品评论',
          noCache: true,
          icon: 'product-comment'
        }
      }
    ]
  },
  {
    path: '/promotion',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'promotionManage',
    meta: {
      title: '商城营销',
      icon: 'sms'
    },
    children: [
      {
        path: 'ad',
        component: () => import('@/views/promotion/ad'),
        name: 'ad',
        meta: {
          perms: ['GET /admin/ad/list', 'POST /admin/ad/create', 'GET /admin/ad/read', 'POST /admin/ad/update', 'POST /admin/ad/delete'],
          title: '广告管理',
          noCache: true,
          icon: 'sms-ad'

        }
      },
      {
        path: 'coupon',
        component: () => import('@/views/promotion/coupon'),
        name: 'coupon',
        meta: {
          perms: ['GET /admin/coupon/list', 'POST /admin/coupon/create', 'POST /admin/coupon/update', 'POST /admin/coupon/delete'],
          title: '优惠券管理',
          noCache: true,
          icon: 'sms-coupon'
        }
      },
      {
        path: 'couponDetail',
        component: () => import('@/views/promotion/couponDetail'),
        name: 'couponDetail',
        meta: {
          perms: ['GET /admin/coupon/list', 'GET /admin/coupon/listuser'],
          title: '优惠券详情',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'topic',
        component: () => import('@/views/promotion/topic'),
        name: 'topic',
        meta: {
          perms: ['GET /admin/topic/list', 'POST /admin/topic/create', 'GET /admin/topic/read', 'POST /admin/topic/update', 'POST /admin/topic/delete'],
          title: '专题管理',
          noCache: true,
          icon: 'sms-hot'
        }
      },
      {
        path: 'topic-create',
        component: () => import('@/views/promotion/topicCreate'),
        name: 'topicCreate',
        meta: {
          perms: ['POST /admin/topic/create'],
          title: '专题创建',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'topic-edit',
        component: () => import('@/views/promotion/topicEdit'),
        name: 'topicEdit',
        meta: {
          perms: ['GET /admin/topic/read', 'POST /admin/topic/update'],
          title: '专题编辑',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'groupon-rule',
        component: () => import('@/views/promotion/grouponRule'),
        name: 'grouponRule',
        meta: {
          perms: ['GET /admin/groupon/list', 'POST /admin/groupon/create', 'POST /admin/groupon/update', 'POST /admin/groupon/delete'],
          title: '团购活动',
          noCache: true,
          icon: 'peoples'
        }
      }
    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'member',
    meta: {
      title: '会员营销',
      icon: 'tab'
    },
    children: [
      {
        path: 'campaign',
        component: () => import('@/views/member/campaign'),
        name: 'campaign',
        meta: {
          perms: ['GET /admin/campaign/list', 'POST /admin/campaign/create', 'GET /admin/campaign/read', 'POST /admin/campaign/update', 'POST /admin/campaign/delete'],
          title: '任务管理',
          noCache: true,
          icon: 'sms-ad'

        }
      },
      {
        path: 'label',
        component: () => import('@/views/member/label'),
        name: 'label',
        meta: {
          perms: ['GET /admin/dmLabel/list', 'POST /admin/dmLabel/create', 'POST /admin/dmLabel/update', 'POST /admin/dmLabel/delete'],
          title: '标签管理',
          noCache: true,
          icon: 'sms-coupon'
        }
      },
      {
        path: 'profile',
        component: () => import('@/views/member/profile'),
        name: 'profile',
        meta: {
          perms: ['GET /admin/dmLabelProfile/list', 'POST /admin/dmLabelProfile/create', 'POST /admin/dmLabelProfile/update', 'POST /admin/dmLabelProfile/delete', 'GET /admin/dmLabelProfile/all'],
          title: '标签画像',
          noCache: true,
          icon: 'peoples'
        }
      }
    ]
  },
  {
    path: '/wo',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'woManage',
    meta: {
      title: '工单管理',
      icon: 'component'
    },
    children: [
      {
        path: 'ticketEntry',
        component: () => import('@/views/ticket/ticketEntry'),
        name: 'ticketEntry',
        meta: {
          perms: ['GET /admin/ticketEntry/create', 'POST /admin/ticketEntry/update'],
          title: '工单录入',
          noCache: true,
          icon: 'form'
        }
      },
      {
        path: 'ticketHandle',
        component: () => import('@/views/ticket/ticketHandle'),
        name: 'ticketHandle',
        meta: {
          perms: ['GET /admin/ticketHandle/list', 'POST /admin/ticketHandle/create', 'GET /admin/ticketHandle/read', 'POST /admin/ticketHandle/update', 'POST /admin/ticketHandle/delete'],
          title: '工单处理',
          noCache: true,
          icon: 'example'
        }
      },
      /* {
      path: 'ticketType',
      component: () => import('@/views/ticket/ticketType'),
      name: 'ticketType',
      meta: {
        perms: ['GET /admin/ticketType/list', 'POST /admin/ticketType/create', 'GET /admin/ticketType/read', 'POST /admin/ticketType/update', 'POST /admin/ticketType/delete'],
        title: '工单类型',
        noCache: true,
        icon:'product-cate'
      }
    } ,*/
      {
        path: 'ticketConsult',
        component: () => import('@/views/ticket/ticketConsult'),
        name: 'ticketConsult',
        meta: {
          perms: ['GET /admin/ticketConsult/list', 'POST /admin/ticketConsult/create', 'GET /admin/ticketConsult/read', 'POST /admin/ticketConsult/update', 'POST /admin/ticketConsult/delete'],
          title: '咨询类型',
          noCache: true,
          icon: 'product-cate'
        }
      }
    ]
  },
  {
    path: '/config',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'configManage',
    meta: {
      title: '配置管理',
      icon: 'edit'
    },
    children: [
      {
        path: 'shop',
        component: () => import('@/views/config/shop'),
        name: 'shop',
        meta: {
          perms: ['GET /admin/shop/list', 'POST /admin/shop/create', 'GET /admin/shop/read', 'POST /admin/shop/update', 'POST /admin/shop/delete'],
          title: '门店配置',
          noCache: true,
          icon: 'password'
        }
      },
      {
        path: 'city',
        component: () => import('@/views/config/city'),
        name: 'city',
        meta: {
          perms: ['GET /admin/shop/list', 'POST /admin/city/create', 'GET /admin/city/read', 'POST /admin/city/update', 'POST /admin/city/delete'],
          title: '业务城市',
          noCache: true,
          icon: 'international'
        }
      },
      {
        path: 'channel',
        component: () => import('@/views/config/channel'),
        name: 'configChannel',
        meta: {
          perms: ['GET /admin/channel/list', 'POST /admin/channel/create'],
          title: '渠道配置',
          noCache: true,
          icon: 'guide'
        }
      },
      {
        path: 'config',
        component: () => import('@/views/config/order'),
        name: 'configOrder',
        meta: {
          perms: ['GET /admin/config/order', 'POST /admin/config/order'],
          title: '订单配置',
          noCache: true,
          icon: 'order-setting'
        }
      },
      {
        path: 'mall',
        component: () => import('@/views/config/mall'),
        name: 'configMall',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '商场配置',
          noCache: true,
          icon: 'home'
        }
      },
      {
        path: 'express',
        component: () => import('@/views/config/express'),
        name: 'configExpress',
        meta: {
          perms: ['GET /admin/config/express', 'POST /admin/config/express'],
          title: '运费配置',
          noCache: true,
          icon: 'guide'
        }
      },
      {
        path: 'wx',
        component: () => import('@/views/config/wx'),
        name: 'configWx',
        meta: {
          perms: ['GET /admin/config/wx', 'POST /admin/config/wx'],
          title: '小程序配置',
          noCache: true,
          icon: 'form'
        }
      },
      {
        path: 'keyword',
        component: () => import('@/views/config/keyword'),
        name: 'keyword',
        meta: {
          perms: ['GET /admin/keyword/list', 'POST /admin/keyword/create', 'GET /admin/keyword/read', 'POST /admin/keyword/update', 'POST /admin/keyword/delete'],
          title: '搜索关键词',
          noCache: true,
          icon: 'logo'
        }
      }
    ]
  },

  {
    path: '/stat',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'statManage',
    meta: {
      title: '统计报表',
      icon: 'dashboard'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/stat/user'),
        name: 'statUser',
        meta: {
          perms: ['GET /admin/stat/user'],
          title: '用户统计',
          noCache: true
        }
      },
      {
        path: 'order',
        component: () => import('@/views/stat/order'),
        name: 'statOrder',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '订单统计',
          noCache: true
        }
      },
      {
        path: 'goods',
        component: () => import('@/views/stat/goods'),
        name: 'statGoods',
        meta: {
          perms: ['GET /admin/stat/goods'],
          title: '商品统计',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/sys',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'sysManage',
    meta: {
      title: '系统管理',
      icon: 'ums'
    },
    children: [
      {
        path: 'admin',
        component: () => import('@/views/sys/admin'),
        name: 'admin',
        meta: {
          perms: ['GET /admin/admin/list', 'POST /admin/admin/create', 'POST /admin/admin/update', 'POST /admin/admin/delete'],
          title: '管理员',
          noCache: true,
          icon: 'ums-admin'
        }
      },
      {
        path: 'notice',
        component: () => import('@/views/sys/notice'),
        name: 'sysNotice',
        meta: {
          perms: ['GET /admin/notice/list', 'POST /admin/notice/create', 'POST /admin/notice/update', 'POST /admin/notice/delete'],
          title: '通知管理',
          noCache: true,
          icon: 'message'
        }
      },
      {
        path: 'log',
        component: () => import('@/views/sys/log'),
        name: 'log',
        meta: {
          perms: ['GET /admin/log/list'],
          title: '操作日志',
          noCache: true,
          icon: 'icon'
        }
      },
      {
        path: 'role',
        component: () => import('@/views/sys/role'),
        name: 'role',
        meta: {
          perms: ['GET /admin/role/list', 'POST /admin/role/create', 'POST /admin/role/update', 'POST /admin/role/delete', 'GET /admin/role/permissions', 'POST /admin/role/permissions'],
          title: '角色管理',
          noCache: true,
          icon: 'ums-menu'
        }
      },
      {
        path: 'os',
        component: () => import('@/views/sys/os'),
        name: 'os',
        meta: {
          perms: ['GET /admin/storage/list', 'POST /admin/storage/create', 'POST /admin/storage/update', 'POST /admin/storage/delete'],
          title: '对象存储',
          noCache: true,
          icon: 'documentation'
        }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    children: [
      {
        path: 'password',
        component: () => import('@/views/profile/password'),
        name: 'password',
        meta: { title: '修改密码', noCache: true }
      },
      {
        path: 'notice',
        component: () => import('@/views/profile/notice'),
        name: 'notice',
        meta: { title: '通知中心', noCache: true }
      }
    ],
    hidden: true
  },

  { path: '*', redirect: '/404', hidden: true }
]
