<template>
    <div style="height: 5%"/>
    <div style="height: 95%">
        <el-auto-resizer>
            <template #default="{ height, width }">
                <div style="display: flex">
                    <div style="width: 50%">
                        <vxe-table :data="rightData"
                                   :row-config="{isHover : true, isCurrent: true,height: 24}"
                                   :height="height"
                                   :tooltip-config="{showAll: true}"
                                   show-overflow
                                   @cell-click="rowClick">
                            <vxe-column title="申请时间"
                                        field="inputDate"
                                        width="120"
                                        :formatter="formatTime"/>
                            <vxe-column title="科室" field="deptName"/>
                            <vxe-column title="接受日期" field="hzDate"
                                        width="120"
                                        :formatter="formatTime"/>
                            <vxe-column title="接受医生" field="hzDoctor2Name"/>
                            <vxe-column title="申请人" field="inputName"/>
                            <vxe-column title="申请科室" field="reqDeptName"/>
                            <vxe-column title="类别" field="hzLevelName"/>
                            <vxe-column title="医生" field="hzDoctor1Name"/>
                        </vxe-table>
                    </div>
                    <div class="right_main">
                        <el-button @click="copyClick">复制</el-button>
                        <el-form>
                            <el-form-item label="病情简介:">
                                <el-input v-model="hzData.reqComment" :rows="3" type="textarea"/>
                            </el-form-item>
                            <el-form-item label="目前主要诊断:">
                                <el-input v-model="hzData.hzZd" :rows="3" type="textarea"/>
                            </el-form-item>
                            <el-form-item label="会诊目的:">
                                <el-input v-model="hzData.hzMd" :rows="3" type="textarea"/>
                            </el-form-item>
                            <el-form-item label="会诊意见:">
                                <el-input v-model="hzData.hzComment" :rows="3" type="textarea"/>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </template>
        </el-auto-resizer>
    </div>
</template>

<script setup name='EmrGroupConsultation'>
// 电子病历 查询会诊
import {chaKanHuiZhenShenQing} from "@/api/case-front-sheet";
import {patInfo} from './emr-tools-store'
import {getHuanZheXinXi} from "@/api/case-front-sheet/jie-shou-hui-zhen";
import store from "@/store";
import {
    copyEnum,
    setEmrCopy
} from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/emr-init";
import {xcMessage} from "@/utils/xiaochan-element-plus";
import {BizException, ExceptionEnum} from "@/utils/BizException";
import XEUtils from 'xe-utils'

const rightData = ref([])

const hzData = ref({})
const query = () => {
    chaKanHuiZhenShenQing(patInfo.value.inpatientNo, patInfo.value.admissTimes).then((res) => {
        rightData.value = res
    })
}

const rowClick = ({row}) => {
    getHuanZheXinXi(row.admissTimes, row.reqTimes, row.inpatientNo).then((res) => {
        hzData.value = res
    })
}

const copyClick = () => {
    let temp = hzData.value
    if (!temp.inpatientNo) {
        BizException(ExceptionEnum.MESSAGE_ERROR, "请先获取患者信息。")
    }
    let data = {
        '会诊科室': [
            {code: temp.reqDept1, name: temp.reqDept1Name}
        ],
        '会诊医生': [
            {code: temp.hzDoctor2, name: temp.hzDoctor2Name}
        ],
        '会诊意见': temp.hzComment,
        '编辑者': [
            {code: store.state.user.info.code, name: store.state.user.info.name}
        ]
    }
    setEmrCopy(copyEnum.会诊, data)
    xcMessage.success('复制成功。')
}

const formatTime = ({cellValue}) => {
    return XEUtils.toDateString(cellValue, 'yy-MM-dd HH:ss')
}

onMounted(() => {
    query()
})


</script>

<style scoped lang="scss">
.right_main {
  flex: 1;
}
</style>
