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: '/nightClinic',
    component: () => import('../views/hospital-service/appointment/night-clinic/ChooseDepartment.vue'),
    meta: { title: '夜间门诊' },
  },
  {
    path: '/selectDoctorAndDate/:deptCode/:deptName/:nightClinic',
    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: '/payClinicAppointmentOrder/:patientId/:times',
    component: () => import('../views/hospital-service/appointment/PayClinicAppointmentOrder.vue'),
    meta: { title: '挂号支付' },
  },
  {
    path: '/selectTargetPatient',
    component: () => import('../views/hospital-service/appointment/management/SelectTargetPatient.vue'),
    meta: { title: '选择就诊人' },
  },
  {
    path: '/appointmentManagement/:patientId',
    component: () => import('../views/hospital-service/appointment/management/AppointmentManagement.vue'),
    meta: { title: '挂号管理' },
  },
  {
    path: '/refundAppointment/:patientId/:times',
    component: () => import('../views/hospital-service/appointment/management/RefundAppointment.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: '/fromGuideBillQrScan/:patientId',
    component: () => import('../views/hospital-service/pay-mz-fee/FromGuideBillQrScan.vue'),
    meta: { title: '待缴费列表' },
  },
  {
    path: '/medinsSettle/:patientId/:hisOrdNum/:patientName/:deptName/:doctorCode/:doctorName/:mdtrtId/:totalAmt?/:fundPay?/:acctPay?/:selfAmt?',
    name: 'medinsSettle',
    component: () => import('../views/hospital-service/pay-mz-fee/MedInsSettle.vue'),
    meta: { title: '医保结算' },
  },
  {
    path: '/unPaidDetail/:patientId/:hisOrdNum/:patientName/:deptName/:doctorCode/:doctorName/:mdtrtId?/: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: '/selectExamBranch/:patientId',
    component: () => import('../views/hospital-service/check-exam/SelectExamBranch.vue'),
    meta: { title: '报告类别' },
  },
  {
    path: '/checkExamIndex/:patientId',
    component: () => import('../views/hospital-service/check-exam/exam/CheckExamIndex.vue'),
    meta: { title: '检验报告查询' },
  },
  {
    path: '/checkExamDetail/:patientId',
    component: () => import('../views/hospital-service/check-exam/exam/CheckExamDetail.vue'),
    meta: { title: '检验报告详情' },
  },
  {
    path: '/checkTestIndex/:patientId',
    component: () => import('../views/hospital-service/check-exam/test/CheckTestIndex.vue'),
    meta: { title: '检查报告查询' },
  },
  {
    path: '/checkTestDetail/:reportId/:patientId',
    component: () => import('../views/hospital-service/check-exam/test/CheckTestDetail.vue'),
    meta: { title: '检查报告详情' },
  },
  {
    path: '/checkPathologyIndex/:patientId',
    component: () => import('../views/hospital-service/check-exam/pathology/CheckPathologyIndex.vue'),
    meta: { title: '病理报告查询' },
  },
  {
    path: '/checkPathologyDetail/:patientId',
    component: () => import('../views/hospital-service/check-exam/pathology/CheckPathologyDetail.vue'),
    meta: { title: '病理报告详情' },
  },
  {
    path: '/checkElectroIndex/:patientId',
    component: () => import('../views/hospital-service/check-exam/electrocardiogram/CheckElectroIndex.vue'),
    meta: { title: '心电报告查询' },
  },
  {
    path: '/checkElectroDetail/:patientId',
    component: () => import('../views/hospital-service/check-exam/electrocardiogram/CheckElectroDetail.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: '/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: '/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: '/myCoupons',
    component: () => import('../views/mine/my-coupons/MyCoupons.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: '/inpatientQrEntry',
    component: () => import('../views/hospital-service/assessments/InpatientQrEntry.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/clinicSatisfied/:patientId',
    component: () => import('../views/hospital-service/assessments/ClinicSatisfiedAssessment.vue'),
    meta: {
      title: '门诊服务满意度调查',
    },
  },
  {
    path: '/clinicSatisfiedByPush/:patientId',
    component: () => import('../views/hospital-service/assessments/ClinicSatisfiedAssessment.vue'),
    meta: {
      title: '门诊服务满意度调查',
    },
  },
  {
    path: '/assessments/inpatientSatisfied/:visitId',
    component: () => import('../views/hospital-service/assessments/InpatientSatisfiedAssessment.vue'),
    meta: {
      title: '住院服务满意度调查',
    },
  },
  {
    path: '/inpatientSatisfiedByPush/:visitId',
    component: () => import('../views/hospital-service/assessments/InpatientSatisfiedAssessment.vue'),
    meta: {
      title: '住院服务满意度调查',
    },
  },
  {
    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: '/healthEducation',
    component: () => import('../views/isolations/HealthEducation.vue'),
    meta: {
      title: '健康宣教',
    },
  },
  {
    path: '/receiveCoupon/:key',
    component: () => import('../views/isolations/ReceiveCoupon.vue'),
    meta: {
      title: '领取优惠券',
    },
  },
  {
    path: '/buyCoupon/:key',
    component: () => import('../views/isolations/BuyCoupon.vue'),
    meta: {
      title: '购买优惠券',
    },
  },
  {
    path: '/selectPriceQueryBranch',
    component: () => import('../views/hospital-service/query-price/SelectPriceQueryBranch.vue'),
    meta: {
      title: '价格查询',
    },
  },
  {
    path: '/queryMedicinePrice',
    component: () => import('../views/hospital-service/query-price/QueryMedicinePrice.vue'),
    meta: {
      title: '药品价格查询',
    },
  },
  {
    path: '/queryItemPrice',
    component: () => import('../views/hospital-service/query-price/QueryItemPrice.vue'),
    meta: {
      title: '项目价格查询',
    },
  },
  {
    path: '/electronicHealthCardHome',
    component: () => import('../views/hospital-service/electronic-health-card/ElectronicHealthCardHome.vue'),
    meta: {
      title: '电子健康卡',
    },
  },
  {
    path: '/addElectronicHealthCard',
    component: () => import('../views/hospital-service/electronic-health-card/AddElectronicHealthCard.vue'),
    meta: {
      title: '添加健康卡',
    },
  },
  {
    path: '/linkHealthCardResult',
    component: () => import('../views/hospital-service/electronic-health-card/LinkHealthCardResult.vue'),
    meta: {
      title: '结果页',
    },
  },
  {
    path: '/activeHealthCard',
    component: () => import('../views/hospital-service/electronic-health-card/ActiveHealthCard.vue'),
    meta: {
      title: '激活健康卡',
    },
  },
  {
    path: '/showCardQrCode',
    name: 'showCardQrCode',
    component: () => import('../views/hospital-service/electronic-health-card/ShowCardQrCode.vue'),
    meta: {
      title: '我的健康卡',
    },
  },
  {
    path: '/newUserRegForElectronicHealthCard',
    component: () => import('../views/hospital-service/electronic-health-card/NewUserReg.vue'),
    meta: {
      title: '新用户注册',
    },
  },
  {
    path: '/shareholdersEquity',
    component: () => import('../views/hospital-service/shareholder/ShareholdersEquity.vue'),
    meta: {
      title: '股东权益',
    },
  },
  {
    path: '/chronicDisease',
    component: () => import('../views/isolations/ChronicDisease.vue'),
    meta: {
      title: '慢病患者登记表',
    },
  },
  {
    path: '/cashier',
    name: 'cashier',
    component: () => import('../views/public-pages/Cashier.vue'),
    meta: {
      title: '收银台'
    }
  },
  {
    path: '/resultSuccess/:title?/:subtitle?',
    name: 'resultSuccess',
    component: () => import('../views/public-pages/ResultSuccess.vue'),
    meta: {
      title: '',
    },
  },
  {
    path: '/paymentSuccess',
    name: 'paymentSuccess',
    component: () => import('../views/public-pages/PaymentSuccess.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
