import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
import store from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Index',
        component: () => import('@/views/Home/HomeIndex.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: 'policyadvice',
        name: 'PolicyAdvice',
        component: () => import('@/views/PolicyAdvice/PolicyAdviceIndex.vue'),
        meta: {
          title: '政策咨询'
        }
      },
      {
        path: 'recruitmentemployment',
        name: 'RecruitmentEmploymentIndex',
        component: () =>
          import(
            '@/views/RecruitmentEmployment/RecruitmentEmploymentIndex.vue'
          ),
        meta: {
          title: '招聘就业'
        }
      },
      {
        path: 'cooperativeenterprise',
        name: 'CooperativeEnterpriseIndex',
        component: () =>
          import(
            '@/views/CooperativeEnterprise/CooperativeEnterpriseIndex.vue'
          ),
        meta: {
          title: '合作企业'
        }
      },
      {
        path: 'enterprisedetails',
        name: 'EnterpriseDetailsIndex',
        component: () =>
          import(
            '@/views/CooperativeEnterprise/EnterpriseDetails/EnterpriseDetailsIndex.vue'
          ),
        meta: {
          title: '企业详情'
        }
      },
      {
        path: 'enterprisePosition',
        name: 'EnterprisePositionIndex',
        component: () =>
          import(
            '@/views/CooperativeEnterprise/EnterprisePosition/EnterprisePositionIndex.vue'
          ),
        meta: {
          title: '职位详情'
        }
      },
      {
        path: 'cooperativecolleges',
        name: 'CooperativeCollegesIndex',
        component: () =>
          import('@/views/CooperativeColleges/CooperativeCollegesIndex.vue'),
        meta: {
          title: '合作院校'
        }
      },
      {
        path: 'collegesdetails',
        name: 'CollegesDetailsIndex',
        component: () =>
          import(
            '@/views/CooperativeColleges/CollegesDetails/CollegesDetailsIndex.vue'
          ),
        meta: {
          title: '院校详情'
        }
      },
      {
        path: 'skilltraining',
        name: 'SkillTrainingIndex',
        component: () => import('@/views/SkillTraining/SkillTrainingIndex.vue'),
        meta: {
          title: '技能培训'
        }
      },
      {
        path: 'skilltraining/skillpackage',
        name: 'SkillPackageIndex',
        component: () => import('@/views/SkillTraining/SkillPackage/SkillPackageIndex.vue'),
        meta: {
          title: '技能包'
        }
      },
      {
        path: 'skilltraining/skillpackage/selectedcourses',
        name: 'SelectedCoursesIndex',
        component: () => import('@/views/SkillTraining/SkillPackage/SelectedCourses/SelectedCoursesIndex.vue'),
        meta: {
          title: '精选课程'
        }
      },
      {
        path: 'coursevideo',
        name: 'CourseVideoIndex',
        component: () => import('@/views/SkillTraining/CourseVideo/CourseVideoIndex.vue'),
        meta: {
          title: '课程详情'
        }
      },
      {
        path: 'workguide',
        name: 'WorkGuideIndex',
        component: () => import('@/views/WorkGuide/WorkGuideIndex.vue'),
        meta: {
          title: '创业指引'
        }
      },
      {
        path: 'workguide/details',
        name: 'WorkGuideDetailsIndex',
        component: () => import('@/views/WorkGuide/WorkGuideDetails/WorkGuideDetailsIndex.vue'),
        meta: {
          title: '创业计划详情'
        }
      },
      {
        path: 'educationpromote',
        name: 'EducationPromoteIndex',
        component: () =>
          import('@/views/EducationPromote/EducationPromoteIndex.vue'),
        meta: {
          title: '学历提升'
        }
      },
      {
        path: 'educationpromote/details',
        name: 'EducationPromoteDetailsIndex',
        component: () =>
          import('@/views/EducationPromote/EducationPromoteDetails/EducationPromoteDetailsIndex.vue'),
        meta: {
          title: '学历提升详情'
        }
      },
      {
        path: 'educationpromote/recruitstudents',
        name: 'RecruitStudentsIndex',
        component: () =>
          import('@/views/EducationPromote/RecruitStudents/RecruitStudentsIndex.vue'),
        meta: {
          title: '招生简章'
        }
      },
      {
        path: 'adaptivetraining',
        name: 'AdaptiveTrainingIndex',
        component: () =>
          import('@/views/AdaptiveTraining/AdaptiveTrainingIndex.vue'),
        meta: {
          title: '适应性培训'
        }
      },
      {
        path: 'adaptivetraining/onlinecoursedetails',
        name: 'OnlineCourseDetailsIndex',
        component: () =>
          import('@/views/AdaptiveTraining/OnlineCourseDetails/OnlineCourseDetailsIndex.vue'),
        meta: {
          title: '线上课程详情'
        }
      },
      {
        path: 'adaptivetraining/offlinecoursedetails',
        name: 'OfflineCourseDetailsIndex',
        component: () =>
          import('@/views/AdaptiveTraining/OfflineCourseDetails/OfflineCourseDetailsIndex.vue'),
        meta: {
          title: '线下课程详情'
        }
      },
      {
        path: 'personalcenter',
        name: 'PersonalCenterIndex',
        component: () =>
          import('@/views/PersonalCenter/PersonalCenterIndex.vue'),
        meta: {
          title: '我的'
        }
      },
      {
        path: 'personalcenter/setting',
        name: 'SettingIndex',
        component: () =>
          import('@/views/PersonalCenter/Setting/SettingIndex.vue'),
        meta: {
          title: '设置'
        }
      },
      {
        path: 'personalcenter/resume',
        name: 'ResumeIndex',
        component: () =>
          import('@/views/PersonalCenter/Resume/ResumeIndex.vue'),
        meta: {
          title: '我的简历'
        }
      },
      {
        path: 'personalcenter/resumeEdit',
        name: 'ResumeEdit',
        component: () =>
          import('@/views/PersonalCenter/Resume/ResumeEdit.vue'),
        meta: {
          title: '编辑简历'
        }
      },
      {
        path: 'personalcenter/deliver',
        name: 'DeliverIndex',
        component: () =>
          import('@/views/PersonalCenter/Deliver/DeliverIndex.vue'),
        meta: {
          title: '我的投递'
        }
      },
      {
        path: 'personalcenter/interview',
        name: 'InterviewIndex',
        component: () =>
          import('@/views/PersonalCenter/Interview/InterviewIndex.vue'),
        meta: {
          title: '我的面试'
        }
      },
      {
        path: 'personalcenter/evaluate',
        name: 'EvaluateIndex',
        component: () =>
          import('@/views/PersonalCenter/Evaluate/EvaluateIndex.vue'),
        meta: {
          title: '我的评价'
        }
      },
      {
        path: 'personalcenter/skilltraining',
        name: 'SkillTrainingIndex',
        component: () =>
          import('@/views/PersonalCenter/SkillTraining/SkillTrainingIndex.vue'),
        meta: {
          title: '我的技能培训'
        }
      },
      {
        path: 'personalcenter/skillsTrainingdetails',
        name: 'SkillsTrainingDetailsIndex',
        component: () =>
          import('@/views/PersonalCenter/SkillTraining/SkillsTrainingDetails/SkillsTrainingDetailsIndex.vue'),
        meta: {
          title: '我的技能培训详情'
        }
      },
      {
        path: 'personalcenter/coursevideo',
        name: 'CourseVideoIndex',
        component: () =>
          import('@/views/PersonalCenter/SkillTraining/SkillsTrainingDetails/CourseVideo/CourseVideoIndex.vue'),
        meta: {
          title: '课程视频'
        }
      },
      {
        path: 'personalcenter/skillsTrainingdetails/achievementcertificate',
        name: 'AchievementCertificateIndex',
        component: () =>
          import('@/views/PersonalCenter/SkillTraining/SkillsTrainingDetails/AchievementCertificate/AchievementCertificateIndex.vue'),
        meta: {
          title: '成绩与证书'
        }
      },
      {
        path: 'personalcenter/progresspoints',
        name: 'ProgressPointsIndex',
        component: () =>
          import('@/views/PersonalCenter/ProgressPoints/ProgressPointsIndex.vue'),
        meta: {
          title: '进步积分'
        }
      },
      {
        path: 'personalcenter/progresspoints/integralrule',
        name: 'IntegralRuleIndex',
        component: () =>
          import('@/views/PersonalCenter/ProgressPoints/IntegralRule/IntegralRuleIndex.vue'),
        meta: {
          title: '积分规则'
        }
      },
      {
        path: 'applyeducationauth',
        name: 'ApplyEducationAuthIndex',
        component: () =>
          import('@/views/PersonalCenter/ApplyEducationAuth/ApplyEducationAuthIndex.vue'),
        meta: {
          title: '退役军人认证'
        }
      },
      {
        path: 'newscenter',
        name: 'NewsCenterIndex',
        component: () =>
          import('@/views/NewsCenter/NewsCenterIndex.vue'),
        meta: {
          title: '新闻中心'
        }
      },
      {
        path: 'newsdetails',
        name: 'NewsDetailsIndex',
        component: () =>
          import('@/views/NewsCenter/NewsDetails/NewsDetailsIndex.vue'),
        meta: {
          title: '新闻详情'
        }
      },
      {
        path: 'noticedetails',
        name: 'NoticeDetailsIndex',
        component: () =>
          import('@/views/NewsCenter/NoticeDetails/NoticeDetailsIndex.vue'),
        meta: {
          title: '通知详情'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login/LoginIndex.vue'),
    meta: {
      title: '登录'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  if (store.state.user.token && !store.state.user.isLogin) {
    store.dispatch('GetUserInfo')
  }
  next()
})

export default router
