import { createRouter, createWebHistory } from 'vue-router'

export const constantRoutes = [
  {
    path: '/',
    redirect: {
      path: '/wxService',
    },
  },
  {
    path: '/wxService/:code?/:to?',
    component: () => import('../views/Home.vue'),
    meta: { title: '医疗服务' },
    children: [
      {
        path: '/hospitalService/:code?/:to?',
        component: () => import('../views/hospital-service/HospitalServiceHome.vue'),
        meta: {
          title: '医疗服务',
        },
      },
      {
        path: '/hospitalIntroduction/:code?/:to?',
        component: () => import('../views/hospital-info/HospitalIntroduction.vue'),
        meta: {
          title: '医院信息',
        },
      },
      {
        path: '/mine/:code?/:to?',
        component: () => import('../views/mine/MineHome.vue'),
        meta: {
          title: '个人中心',
        },
      },
    ],
  },
  {
    path: '/myPatientIdCards',
    component: () => import('../views/mine/patient-id-cards/MyPatientIdCards.vue'),
    meta: { title: '我的就诊人' },
  },
  {
    path: '/bindPatientCard',
    component: () => import('../views/mine/patient-id-cards/BindPatientCard.vue'),
    meta: { title: '添加就诊人' },
  },
  {
    path: '/createPatientCard',
    component: () => import('../views/mine/patient-id-cards/CreatePatientCard.vue'),
    meta: { title: '新建就诊人' },
  },
  {
    path: '/appointment',
    component: () => import('../views/hospital-service/appointment/Appointment.vue'),
    meta: { title: '预约挂号' },
  },
  {
    path: '/selectDoctorAndDate/:deptCode/:deptName',
    component: () => import('../views/hospital-service/appointment/SelectDoctorAndDate.vue'),
    meta: { title: '' },
  },
  {
    path: '/doctorArrangement/:date/:dept/:doctor',
    component: () => import('../views/hospital-service/appointment/DoctorArrangement.vue'),
    meta: {
      title: '医生排班',
    },
  },
  {
    path: '/appointmentConfirm',
    component: () => import('../views/hospital-service/appointment/AppointmentConfirm.vue'),
    meta: { title: '挂号确认' },
  },
  {
    path: '/payAppointmentFee',
    component: () => import('../views/hospital-service/appointment/PayAppointmentFee.vue'),
    meta: { title: '收银台' },
  },
  {
    path: '/selectPayPatient',
    component: () => import('../views/hospital-service/pay-mz-fee/SelectPayPatient.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/unPaidList/:patientId',
    component: () => import('../views/hospital-service/pay-mz-fee/UnPaidList.vue'),
    meta: { title: '待缴费列表' },
  },
  {
    path: '/unPaidDetail/:patientId/:hisOrdNum/:patName/:deptName/:doctorName/:totalAmt/:selfAmt/:fundPay?/:acctPay?',
    name: 'unPaidDetail',
    component: () => import('../views/hospital-service/pay-mz-fee/UnPaidDetail.vue'),
    meta: { title: '待缴费详情' },
  },
  {
    path: '/selectExamPatient',
    component: () => import('../views/hospital-service/check-exam/SelectExamPatient.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/checkExamIndex/:patientId',
    component: () => import('../views/hospital-service/check-exam/CheckExamIndex.vue'),
    meta: { title: '报告查询' },
  },
  {
    path: '/checkExamDetail/:orderId/:patNo?/:patType?',
    component: () => import('../views/hospital-service/check-exam/CheckExamDetail.vue'),
    meta: { title: '报告详情' },
  },
  {
    path: '/selectPhysicalExamPatient',
    component: () => import('../views/hospital-service/physical-exam/PhysicalExamPatient.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/physicalExamIndex/:patientId',
    component: () => import('../views/hospital-service/physical-exam/PhysicalExamIndex.vue'),
    meta: { title: '体检报告' },
  },
  {
    path: '/physicalExamination/:tjid?',
    component: () => import('../views/hospital-service/physical-exam/PhysicalExamination.vue'),
    meta: { title: '体检报告' },
  },
  {
    path: '/selectCovidVaccinatePatient',
    component: () => import('../views/hospital-service/covid-vaccinate/SelectCovidVaccinatePatient.vue'),
    meta: { title: '选择患者' },
  },
  {
    path: '/covidVaccinate/:patientId?',
    component: () => import('../views/hospital-service/covid-vaccinate/CovidVaccinate.vue'),
    meta: { title: '选择新冠疫苗' },
  },
  {
    path: '/excuteAppointment/:patientId?/:vaccinateCode/:vaccinateName/:vaccinateFactory',
    name: 'excuteAppointment',
    component: () => import('../views/hospital-service/covid-vaccinate/ExcuteAppointment.vue'),
    meta: { title: '新冠接种预约' },
  },
  {
    path: '/selectInpatientCard',
    component: () => import('../views/hospital-service/inpatient-service/SelectInpatientCard.vue'),
    meta: { title: '住院查询' },
  },
  {
    path: '/inPatientService/:patientId',
    component: () => import('../views/hospital-service/inpatient-service/InPatientService.vue'),
    meta: { title: '住院服务' },
  },
  {
    path: '/zyFeeDetail/:inpatientNo/:admissTimes/:admissDate',
    name: 'zyFeeDetail',
    component: () => import('../views/hospital-service/inpatient-service/ZyFeeDetail.vue'),
    meta: { title: '住院费用明细' },
  },
  {
    path: '/displayPrepaid/:patientId/:name/:inpatientNo/:admissTimes/:deptName/:lastBalance',
    name: 'displayPrepaid',
    component: () => import('../views/hospital-service/inpatient-service/DisplayPrepaid.vue'),
    meta: { title: '预交金' },
  },
  {
    path: '/selectHealthCartPatient',
    component: () => import('../views/hospital-service/health-cart/SelectPatientCard.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/healthCartCategory/:patientId',
    component: () => import('../views/hospital-service/health-cart/ExaminationCategory.vue'),
    meta: { title: '类别选择' },
  },
  {
    path: '/bookableExaminations/:flag/:patientId',
    component: () => import('../views/hospital-service/health-cart/BookableExaminations.vue'),
    meta: { title: '可预约项目' },
  },
  {
    path: '/selectBookDate',
    component: () => import('../views/hospital-service/health-cart/SelectBookDate.vue'),
    meta: { title: '可预约时间' },
  },
  {
    path: '/bookExam',
    component: () => import('../views/hospital-service/health-cart/BookExam.vue'),
    meta: { title: '预约详情' },
  },
  {
    path: '/resignOrRefund/:reqNo',
    component: () => import('../views/hospital-service/health-cart/ResignOrRefund.vue'),
    meta: { title: '未成功的预约' },
  },
  {
    path: '/selectCovidBranch/:patientId',
    component: () => import('../views/hospital-service/covid-exam/SelectCovidBranch.vue'),
    meta: { title: '新冠肺炎核酸检测' },
  },
  {
    path: '/checkCovidExamResult/:patientId',
    component: () => import('../views/hospital-service/covid-exam/CheckExamResult.vue'),
    meta: { title: '查询新冠核酸检测结果' },
  },
  {
    path: '/selectOrderCovidPatient',
    component: () => import('../views/hospital-service/covid-exam/SelectPatientCard.vue'),
    meta: { title: '选择就诊卡' },
  },
  {
    path: '/selectAppointmentRecordPatient',
    component: () => import('../views/mine/appointment-record/SelectPatientCard.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/appiontmentRecords/:patientId',
    component: () => import('../views/mine/appointment-record/AppointmentRecords.vue'),
    meta: { title: '挂号记录' },
  },
  {
    path: '/selectMzFeePaymentRecordPatient',
    component: () => import('../views/mine/mz-pay-record/SelectPatientCard.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/mzFeePaymentRecords/:patientId',
    component: () => import('../views/mine/mz-pay-record/MzFeePaymentRecords.vue'),
    meta: { title: '门诊缴费记录' },
  },
  {
    path: '/mzFeePaymentDetail/:deptName/:doctorName/:datetime/:hisOrdNum/:totalAmt',
    name: 'mzFeePaymentDetail',
    component: () => import('../views/mine/mz-pay-record/MzFeePaymentDetail.vue'),
    meta: { title: '门诊缴费详细' },
  },
  {
    path: '/selectZyYjjPatient',
    component: () => import('../views/mine/zy-prepaid-record/SelectPatientCard.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/prepaidRecord/:patientId',
    component: () => import('../views/mine/zy-prepaid-record/PrepaidRecord.vue'),
    meta: { title: '住院预交金记录' },
  },
  {
    path: '/myCollection',
    component: () => import('../views/mine/my-collection/MyCollection.vue'),
    meta: { title: '我的收藏' },
  },
  {
    path: '/patientCardInfo/:patientId',
    component: () => import('../views/mine/patient-id-cards/PatientCardInfo.vue'),
    meta: { title: '就诊人信息' },
  },

  {
    path: '/selectAssessmentPatient',
    component: () => import('../views/hospital-service/assessments/SelectAssessmentPatient.vue'),
    meta: { title: '选择问卷填写人' },
  },
  {
    path: '/assessments/:patientId',
    component: () => import('../views/hospital-service/assessments/AssessmentsEntrance.vue'),
    meta: {
      title: '问卷选择',
    },
  },
  {
    path: '/assessments/depression/:patientId',
    component: () => import('../views/hospital-service/assessments/DepressionAssessment.vue'),
    meta: {
      title: 'SDS抑郁自评量',
    },
  },
  {
    path: '/assessments/covid/:patientId?/:from?',
    component: () => import('../views/hospital-service/assessments/Covid19Assessment.vue'),
    meta: {
      title: '新型冠状病毒感染流行病学史问卷',
    },
  },
  {
    path: '/onlineConsult',
    component: () => import('../views/hospital-service/online-consult/OnlineConsult.vue'),
    meta: {
      title: '在线咨询',
    },
  },
  {
    path: '/studentInspection',
    component: () => import('../views/isolations/StudentInspection.vue'),
    meta: {
      title: '学生体检',
    },
  },
  {
    path: '/500',
    component: () => import('../views/500.vue'),
    meta: {
      title: '服务器错误',
    },
  },
  {
    path: '/404',
    component: () => import('../views/404.vue'),
    meta: {
      title: '网页未找到',
    },
  },
  {
    // 找不到路由重定向到404页面
    path: '/:pathMatch(.*)',
    redirect: '/404',
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
})

router.beforeEach((to, from, next) => {
  if (to.fullPath.startsWith('/selectDoctorAndDate')) {
    to.meta.title = to.params.deptName
  }
  document.title = to.meta.title
  next()
})

export default router
