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 }
      }
    ]
  }
]

/*
  const routerPush = Router.prototype.push;
  Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
} */

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: 'customer',
        component: () => import('@/views/member/customer'),
        name: 'customer',
        meta: {
          perms: ['GET /admin/customer/list', 'POST /admin/customer/detail'],
          title: '客户管理',
          noCache: true,
          icon: 'user'
        }
      },
      {
        path: 'customerDetail',
        component: () => import('@/views/member/customerDetail'),
        name: 'ticketDetail',
        meta: {
          // perms: ['GET /admin/ticketResult/list', 'POST /admin/ticketResult/create', 'GET /admin/ticketResult/read', 'POST /admin/ticketResult/update', 'POST /admin/ticketConsult/delete'],
          title: '客户详情',
          noCache: true,
          icon: 'ticket-result'
        },
        hidden: true
      },
    ]
  },
  {
    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',],
          title: '订单管理',
          noCache: true,
          icon: 'order'
        }
      }
    ]
  },
  {
    path: '/callcenter',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'callcenter',
    meta: {
      title: '电访中心',
      icon: 'cc'
    },
    children: [
      {
        path: 'callcenter',
        component: () => import('@/views/callcenter/builtList'),
        name: 'builtList',
        meta: {
          perms: ['GET /admin/built/list'],
          title: '电访任务',
          noCache: false,
          icon: 'call'
        }
      },
      {
        path: 'calllog',
        component: () => import('@/views/callcenter/calllog'),
        name: 'calllog',
        meta: {
          perms: ['GET /admin/calllog/list', 'POST /admin/calllog/create', 'POST /admin/calllog/update'],
          title: '电访记录',
          noCache: true,
          icon: 'calllog'
        }
      },
      {
        path: 'callrecord',
        component: () => import('@/views/callcenter/calllogRecord'),
        name: 'callrecord',
        meta: {
          perms: ['GET /admin/calllogRecord/list', 'POST /admin/calllogRecord/create', 'POST /admin/calllogRecord/update'],
          title: '话务记录',
          noCache: true,
          icon: 'call-record'
        }
      },
      
      // {
      //   path: 'calllogIB',
      //   component: () => import('@/views/components/addCalllogIB'),
      //   name: 'calllogIB',
      //   meta: {
      //     perms: ['GET /admin/calllog/list', 'POST /admin/calllog/create', 'POST /admin/calllog/update'],
      //     title: '进电',
      //     noCache: true,
      //     icon: 'call-record'
      //   }
      // },
      // {
      //   path: 'calllogOB',
      //   component: () => import('@/views/components/addCalllogOB'),
      //   name: 'calllogOB',
      //   meta: {
      //     perms: ['GET /admin/calllog/list', 'POST /admin/calllog/create', 'POST /admin/calllog/update'],
      //     title: '外拨',
      //     noCache: true,
      //     icon: 'call-record'
      //   }
      // },
      // {
      //   path: 'addTicket',
      //   component: () => import('@/views/components/addTicket'),
      //   name: 'addTicket',
      //   meta: {
      //     perms: ['GET /admin/calllog/list', 'POST /admin/calllog/create', 'POST /admin/calllog/update'],
      //     title: '工单新增',
      //     noCache: true,
      //     icon: 'call-record'
      //   }
      // },
      {
        path: 'config',
        component: () => import('@/views/callcenter/call'),
        name: 'callconfig',
        meta: {
          perms: ['GET /admin/config/call', 'POST /admin/config/call'],
          title: '外拨配置',
          noCache: true,
          icon: 'order-setting'
        }
      },
      {
        path: 'taskRecycle',
        component: () => import('@/views/callcenter/taskRecycle'),
        name: 'taskRecycle',
        meta: {
          perms: ['GET /admin/builtRecovery/list','POST /admin/builtRecovery/assignTask'],
          title: '任务回收分配',
          noCache: true,
          icon: 'ums-menu'
        }
      },
    ]
  },
  {
    path: '/ticket',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'woManage',
    meta: {
      title: '工单管理',
      icon: 'ticket'
    },
    children: [
      {
        path: 'ticketEntry',
        component: () => import('@/views/ticket/ticketEntry'),
        name: 'ticketEntry',
        meta: {
          perms: ['GET /admin/ticket/listAll'],
          title: '全部工单',
          noCache: true,
          icon: 'all2'
        }
      },
      {
        path: 'ticketHandle',
        component: () => import('@/views/ticket/ticketHandle'),
        name: 'ticketHandle',
        meta: {
          perms: ['GET /admin/ticket/list'],
          title: '我的工单',
          noCache: true,
          icon: 'ticket_handle'
        }
      },
      {
        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: 'ticket_consult'
        }
      },
      {
        path: 'ticketResult',
        component: () => import('@/views/ticket/ticketResult'),
        name: 'ticketResult',
        meta: {
          perms: ['GET /admin/ticketResult/list', 'POST /admin/ticketResult/create', 'GET /admin/ticketResult/read', 'POST /admin/ticketResult/update', 'POST /admin/ticketConsult/delete'],
          title: '处理结果',
          noCache: true,
          icon: 'ticket-result'
        }
      },
      {
        path: 'ticketDetail',
        component: () => import('@/views/ticket/ticketDetail'),
        name: 'ticketDetail',
        meta: {
          // perms: ['GET /admin/ticketResult/list', 'POST /admin/ticketResult/create', 'GET /admin/ticketResult/read', 'POST /admin/ticketResult/update', 'POST /admin/ticketConsult/delete'],
          title: '工单详情',
          noCache: true,
          icon: 'ticket-result'
        },
        hidden: true
      },

    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'member',
    meta: {
      title: '会员营销',
      icon: 'market'
    },
    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: 'market-campaign'

        }
      },
      {
        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: 'market-label'
        }
      },
      {
        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: 'market-view'
        }
      },
      {
        path: 'skill',
        component: () => import('@/views/member/skill'),
        name: 'skill',
        meta: {
          perms: ['GET /admin/skill/list', 'POST /admin/skill/create', 'POST /admin/skill/update', 'POST /admin/skill/delete', 'GET /admin/skill/all'],
          title: '技能组',
          noCache: true,
          icon: 'market-skill'
        }
      }
    ]
  },
  {
    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: '/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: '/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: '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: 'department',
        component: () => import('@/views/sys/department'),
        name: 'department',
        meta: {
          perms: ['GET /admin/department/list', 'POST /admin/department/create', 'POST /admin/department/update', 'POST /department/role/delete', 'GET /admin/department/all'],
          title: '部门管理',
          noCache: true,
          icon: 'department'
        }
      },
      {
        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: '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 }
]
