<template>
    <el-dialog v-model="dialog"
               title="患者详情"
               class="dialog-temp"
               fullscreen
               @closed="emits('closed')"
               destroy-on-close>
        <huan-zhe-xin-xi :huan-zhe-xin-xi="patInfo"/>
        <el-tabs>

            <el-tab-pane label="首页">
                <first-page-of-medical-record :dics="props.dics"
                                              :sheet-data="sheetData"/>
            </el-tab-pane>
            <el-tab-pane label="医嘱">
                <emr-order-list :pat-no="props.patNo"
                                :times="props.times"
                                :in-the-hospital="props.leaveHospital === 1"/>
            </el-tab-pane>
            <el-tab-pane label="清单">
                <charge-list :pat-no="props.patNo"
                             :show-button="false"
                             :times="props.times"/>
            </el-tab-pane>
            <el-tab-pane label="检验">
                <inspection-report-index
                        style="font-size: 12px;height: 100%"
                        :pat-no="props.patNo"
                        :start="startDate"
                        :end="endDate"/>
            </el-tab-pane>
            <el-tab-pane label="检查">
                <emr-inspect :pat-no="props.patNo"
                             :times="props.times"/>
            </el-tab-pane>
            <el-tab-pane label="会诊">
                <group-consultation :pat-no="props.patNo"
                                    :times="props.times"/>
            </el-tab-pane>
            <el-tab-pane label="病历">
                <electronic-medical-record :pat-no="props.patNo"
                                           :times="props.times"/>
            </el-tab-pane>
        </el-tabs>
    </el-dialog>
</template>

<script setup name='PatInfomationDialog'>

import FirstPageOfMedicalRecord from "@/components/pat-info-list/FirstPageOfMedicalRecord.vue";
import EmrOrderList from "@/components/zhu-yuan-yi-sheng/emr/auxiliary-tools/EmrOrderList.vue";
import InspectionReportIndex from "@/views/examination/InspectionReportIndex.vue";
import EmrInspect from "@/components/zhu-yuan-yi-sheng/emr/auxiliary-tools/EmrInspect.vue";
import GroupConsultation from "@/components/pat-info-list/GroupConsultation.vue";
import ElectronicMedicalRecord from "@/components/pat-info-list/ElectronicMedicalRecord.vue";
import {getSheetInfo} from "@/api/case-front-sheet";
import {formatDate} from "@/utils/date";
import {getServerDateApi} from "@/api/public-api";
import ChargeList from '@/components/medical-insurance/charge-list/Index.vue'
import {getDisPatient, getPatientInfo} from "@/api/inpatient/patient";
import HuanZheXinXi from "@/components/zhu-yuan-yi-sheng/HuanZheXinXi.vue";


const props = defineProps({
    patNo: String,
    times: Number,
    /*
    * 出院 2
    * 在院 1
    * */
    leaveHospital: {
        type: Number,
        default: 1
    },
    admissDate: {
        type: String
    },
    dics: {
        type: Object
    }
})

const emits = defineEmits(['closed'])

const dialog = ref(false)
const sheetData = ref({})
const startDate = ref('')
const endDate = ref('')

const patInfo = ref({})


const details = async () => {
    sheetData.value = await getSheetInfo({
        bah: props.patNo,
        times: props.times,
        inOutFlag: props.leaveHospital ? 2 : 1
    })
    startDate.value = formatDate(props.admissDate)
    dialog.value = true
}

onMounted(async () => {
    endDate.value = formatDate(await getServerDateApi())
    await details()
    if (props.leaveHospital === 1) {
        patInfo.value = await getPatientInfo(props.patNo)
    } else {
        patInfo.value = await getDisPatient(props.patNo, props.times)
    }
    console.log(patInfo.value)

})

</script>

<style lang="scss">
.dialog-temp {
  .el-dialog__body {
    padding: 0 16px;
    height: calc(100% - 55px);
  }

  .el-tabs {
    height: calc(100% - 50px);

    .el-tabs__content {
      height: calc(100% - 50px);
    }

    .el-tab-pane {
      height: calc(100% - 50px);
      overflow: auto;
    }
  }
}


</style>
