<template>
    <el-tabs v-model="asideTabs">
        <el-tab-pane :name="0" label="检查记录">
            <el-container>
                <el-aside width="450px">
                    <check-application-history :data="jianChaShuJu"
                                               :returnData="dianJiaJianChaXiangQing"
                                               :current-change="handleCurrentChange"/>
                </el-aside>
                <el-main>
                    <jian-cha-jie-guo ref="jianChaJieGuoRef" :pat-info="props.huanZheXinXi"/>
                </el-main>
            </el-container>
        </el-tab-pane>
        <el-tab-pane :name="1" label="检验记录">

        </el-tab-pane>
    </el-tabs>

</template>

<script setup name="jianYanJianCha">

import {computed, ref, watch} from 'vue'
import {
    baoCunJianYanJianCha,
    diagnosisInOurHospital, getJcItem,
    huoQuJianChaShenQing,
    huoQuJianYanJianChaMing,
    huoQuShengQingXiangQing,
    queryCheckTextResults,
} from '@/api/zhu-yuan-yi-sheng/jian-yan-jian-cha-shen-qing'
import store from '@/store'
import {getDateRangeFormatDate} from '@/utils/date'
import {shortcuts} from '@/data/shortcuts'
import {ElMessageBox} from 'element-plus'
import CheckApplicationHistory from "@/components/zhu-yuan-yi-sheng/jian-cha-shen-qing/aside/CheckApplicationHistory";
import InspectionRequisition
    from "@/views/hospitalization/zhu-yuan-yi-sheng/jian-cha-jian-yan-shen-qing/InspectionRequisition";
import SaveTemplateInspection
    from "@/views/hospitalization/zhu-yuan-yi-sheng/jian-cha-jian-yan-shen-qing/SaveTemplateInspection";
import {BizException, ExceptionEnum} from "@/utils/BizException";
import {getServerDateApi, yaoPinXiangMuPiPeiYiBao} from "@/api/public-api";
import {stringNotBlank} from "@/utils/blank-utils";
import JianChaJieGuo from "@/components/zhu-yuan-yi-sheng/jian-cha-shen-qing/da-ying/JianChaJieGuo.vue";
import XcTable from "@/components/xiao-chan/xc-table/XcTable.vue";
import XcDialogV2 from "@/components/xiao-chan/dialog/XcDialogV2.vue";
import XcComboGrid from "@/components/xiao-chan/combo-grid/XcComboGrid.vue";

const props = defineProps({
    huanZheXinXi: {
        type: Object,
        default: {}
    },
    height: {
        type: Number,
        default: 600
    }
})
const asideTabs = ref(0)

const jianChaShuJu = ref({
    delFlag:1,
    currentPage: 1,
    total: 0,
    pageSize: 20,
    data: [],
})

const daYingJianChaRef = ref()
// 检查结果
const jianChaJieGuoRef = ref()

onMounted(() => {
    handleCurrentChange()
})

/**
 * 点击查看检查申请单详情
 * @param row 行数据
 */
const dianJiaJianChaXiangQing = (row) => {
    queryCheckTextResults(row.inpatientNo, row.admissTimes, row.reqNo).then((res) => {
        res.row = row
        jianChaJieGuoRef.value.fillData(res).then(() => {
        })
    }).catch((e) => {
        jianChaJieGuoRef.value.fillData({
            record: {}, recordReport: {}, row: {}
        })
    })

    huoQuShengQingXiangQing(row.reqNo).then((res) => {
        // daYingJianChaRef.value.jieShouShuJu(res)
    })
}

/**
 * 检查申请单分页
 * @param val
 */
const handleCurrentChange = (val) => {
    jianChaShuJu.value.currentPage = val
    dianJiChaXunHuanZheJianCha(jianChaShuJu.value.total)
}

/**
 * 点击查询患者检查
 * @param total
 */
const dianJiChaXunHuanZheJianCha = (total) => {
    let param = {
        patNo: props.huanZheXinXi.inpatientNo,
        times: props.huanZheXinXi.admissTimes,
        orderName: '',
        total: 0,
        currentPage: jianChaShuJu.value.currentPage,
        pageSize: jianChaShuJu.value.pageSize,
        startTime:'',
        endTime: '',
    }
    huoQuJianChaShenQing(param).then((res) => {
        if (total === 0) {
            jianChaShuJu.value.total = res.total
        }
        jianChaShuJu.value.data = res.records
    })
}
</script>