import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { path: '*', redirect: '/' },
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/login/Login.vue')
  },
  // 首页
  {
    path: '/',
    name: 'home',
    component: () => import('@/views/home/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 搜索
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 创建
  {
    path: '/create',
    name: 'create',
    component: () => import('@/views/create/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 创建组织
  {
    path: '/create/group',
    name: 'createGroup',
    component: () => import('@/views/create/Group.vue'),
    meta: { requiredLogin: true }
  },
  // 创建活动
  {
    path: '/create/activity',
    name: 'createActivity',
    component: () => import('@/views/create/Activity.vue'),
    meta: { requiredLogin: true }
  },
  // 我的
  {
    path: '/my',
    name: 'my',
    component: () => import('@/views/my/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 我的个人资料
  {
    path: '/my/info',
    name: 'myInfo',
    component: () => import('@/views/my/info.vue'),
    meta: { requiredLogin: true }
  },
  // 我的消息
  {
    path: '/message',
    name: 'message',
    component: () => import('@/views/message/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 消息列表
  {
    path: '/message/:type',
    name: 'messageList',
    component: () => import('@/views/message/List.vue'),
    meta: { requiredLogin: true }
  },
  // 消息详情
  {
    path: '/message/:type/:id',
    name: 'messageItem',
    component: () => import('@/views/message/Item.vue'),
    meta: { requiredLogin: true }
  },
  // 设置
  {
    path: '/settings',
    name: 'settings',
    component: () => import('@/views/settings/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 我的组织
  {
    path: '/my/group',
    name: 'myGroup',
    component: () => import('@/views/my/MyGroup.vue'),
    meta: { requiredLogin: true }
  },
  // 我的活动
  {
    path: '/my/activity',
    name: 'myActivity',
    component: () => import('@/views/my/MyActivity.vue'),
    meta: { requiredLogin: true }
  },
  // 我的审批
  {
    path: '/my/approve',
    name: 'myApprove',
    component: () => import('@/views/my/MyApprove.vue'),
    meta: { requiredLogin: true }
  },
  // 活动列表
  {
    path: '/activity',
    name: 'activity',
    component: () => import('@/views/activity/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 活动详情
  {
    path: '/activity/:id',
    name: 'activityItem',
    component: () => import('@/views/activity/Item.vue'),
    meta: { requiredLogin: true }
  },
  // 活动评论
  {
    path: '/activity/:id/comment/:commentId',
    name: 'activityComment',
    component: () => import('@/views/activity/Comment.vue'),
    meta: { requiredLogin: true }
  },
  // 编辑活动
  {
    path: '/activity/:id/update',
    name: 'activityUpdate',
    component: () => import('@/views/activity/Update.vue'),
    meta: { requiredLogin: true }
  },
  // 活动成员列表
  {
    path: '/activity/:id/member',
    name: 'activityMember',
    component: () => import('@/views/activity/Member.vue'),
    meta: { requiredLogin: true }
  },
  // 紫荆币活动
  {
    path: '/coins',
    name: 'coins',
    component: () => import('@/views/activity/Coins.vue'),
    meta: { requiredLogin: true }
  },
  // 组织列表
  {
    path: '/group',
    name: 'group',
    component: () => import('@/views/group/Index.vue'),
    meta: { requiredLogin: true }
  },
  // 组织详情
  {
    path: '/group/:id',
    name: 'groupItem',
    component: () => import('@/views/group/Item.vue'),
    meta: { requiredLogin: true }
  },
  // 编辑组织
  {
    path: '/group/:id/update',
    name: 'groupUpdate',
    component: () => import('@/views/group/Update.vue'),
    meta: { requiredLogin: true }
  },
  // 组织成员列表
  {
    path: '/group/:id/member',
    name: 'groupMember',
    component: () => import('@/views/group/Member.vue'),
    meta: { requiredLogin: true }
  },
  // 组织活动列表
  {
    path: '/group/:id/activity',
    name: 'groupActivity',
    component: () => import('@/views/group/Activity.vue'),
    meta: { requiredLogin: true }
  },
  //学员提交
  {
    path: '/submit',
    name: 'submitStudent',
    component: () => import('@/views/submitStudent/submitStudent.vue'),
    meta: { requiredLogin: true }
  },
  //三级认证
  {
    path: '/attestation/form',
    name: 'attestationForm',
    component: () => import('@/views/attestation/form.vue'),
    meta: { requiredLogin: true }
  },
  // 打印
  {
    path: '/attestation/printing',
    name: 'printing',
    component: () => import('@/views/attestation/printing.vue'),
    meta: { requiredLogin: true }
  },
  // 三级认证首页
  {
    path: '/attestation',
    name: 'attestation',
    component: () => import('@/views/attestation/index.vue'),
    meta: { requiredLogin: true }
  },
  // 三级认证上传
  {
    path: '/attestation/upload',
    name: 'attteUpload',
    component: () => import('@/views/attestation/upload.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/vote/index',
    name: 'voteIndex',
    component: () => import('@/views/vote/Index.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/vote/city',
    name: 'voteCity',
    component: () => import('@/views/vote/City.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/vote/choose',
    name: 'voteChoose',
    component: () => import('@/views/vote/Choose.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/vote/item/:id',
    name: 'voteItem',
    component: () => import('@/views/vote/Item.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/vote/primary',
    name: 'votePrimary',
    component: () => import('@/views/vote/Primary.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/vote/apply',
    name: 'voteApply',
    component: () => import('@/views/vote/Apply.vue')
  },
  // 推荐学生
  {
    path: '/recommend',
    component: () => import('@/views/recommend/Recommend.vue'),
    meta: { requiredLogin: true }
  },
  // 我的推荐
  {
    path: '/my/recommend',
    component: () => import('@/views/recommend/MyRecommend.vue'),
    meta: { requiredLogin: true }
  },
  {
    path: '/my/recommend/:id',
    component: () => import('@/views/recommend/MyRecommendDetail.vue'),
    meta: { requiredLogin: true }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

export default router
