<template>
  <div class="component-box-wrapper__half-transparent">
    <div class="component-content-box__dialog-like">
      <div class="component-header-box">
        <div class="component-header__title">患者在院信息</div>
        <div class="component-header__close-button">
          <el-button plain icon="Close" circle title="关闭" @click="close"></el-button>
        </div>
      </div>
      <div v-if="injuryMode">
        <el-descriptions :column="3" size="small" border>
          <el-descriptions-item>
            <template #label> 姓名 </template>
            {{ registerInfo.name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 住院号 </template>
            {{ registerInfo.patient_id }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 个人电脑号 </template>
            {{ registerInfo.indi_id }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 性别 </template>
            {{ cptSex(registerInfo.sex) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 身份证 </template>
            {{ registerInfo.idcard }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 出生日期 </template>
            {{ registerInfo.birthday }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 医疗类别 </template>
            {{ registerInfo.treatment_name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 入院科室 </template>
            {{ registerInfo.out_dept_name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 入院病房 </template>
            {{ registerInfo.area_name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 诊断编码 </template>
            {{ registerInfo.in_diagnose }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 诊断名称 </template>
            {{ registerInfo.in_disease_name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 就诊登记号 </template>
            {{ registerInfo.serial_no }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 工伤业务序号 </template>
            {{ registerInfo.serial_bo_no }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 入院登记时间 </template>
            {{ registerInfo.reg_date }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 单位名称 </template>
            {{ registerInfo.corp_name }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div v-else>
        <el-descriptions :column="3" size="small" border>
          <el-descriptions-item>
            <template #label> 姓名 </template>
            {{ registerInfo.psnName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 住院号 </template>
            {{ registerInfo.iptOtpNo }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 性别 </template>
            {{ cptSex(registerInfo.gend) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 证件类型 </template>
            {{ cptPsnCertType(registerInfo.psnCertType) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 证件号码 </template>
            {{ registerInfo.certno }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 出生日期 </template>
            {{ registerInfo.brdy }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 险种类型 </template>
            {{ cptInsutype(registerInfo.insutype) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 医疗类别 </template>
            {{ cptMedType(registerInfo.medType) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 异地标志 </template>
            {{ cptYesOrNo(registerInfo.outFlag) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 开始日期 </template>
            {{ registerInfo.begndate }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 就诊ID </template>
            {{ registerInfo.mdtrtId }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template #label> 人员编号 </template>
            {{ registerInfo.psnNo }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </div>
  </div>
</template>

<script>
import { computed, onMounted, ref } from 'vue'
import { useStore } from 'vuex'
import { getInjuryRegisterInfo } from '@/api/medical-insurance/si-injury'
import { queryInHospitalPatientsInfo } from '@/api/medical-insurance/si-query'
import { cptSex, cptPsnCertType, cptInsutype, cptMedType, cptYesOrNo } from '@/utils/computed'
export default {
  props: {
    params: {
      type: Object,
      required: true,
    },
  },
  emits: ['close'],
  setup(props, ctx) {
    const store = useStore()
    const registerInfo = ref({})

    const injuryMode = computed(() => {
      return store.state.ptnt.injuryMode
    })

    const getRegistinfo = () => {
      if (injuryMode.value) {
        getInjuryRegisterInfo(props.params)
          .then((res) => {
            registerInfo.value = res
          })
          .catch(() => {
            registerInfo.value = {}
            ctx.emit('close')
          })
      } else {
        const param = {
          patNo: props.params.inpatientNo,
          times: props.params.admissTimes,
          ledgerSn: props.params.ledgerSn,
          begntime: props.params.admissDate,
        }
        queryInHospitalPatientsInfo(param)
          .then((res) => {
            registerInfo.value = res[0]
          })
          .catch(() => {
            registerInfo.value = {}
            ctx.emit('close')
          })
      }
    }

    const close = () => {
      ctx.emit('close')
    }

    onMounted(() => {
      getRegistinfo()
    })

    return {
      injuryMode,
      registerInfo,
      cptSex,
      cptPsnCertType,
      cptInsutype,
      cptMedType,
      cptYesOrNo,
      close,
    }
  },
}
</script>
