<template>
  <el-dialog
    v-model="dialogVisible"
    :title="dialogTitle"
    class="my-custom-close-icon"
    :fullscreen="true"
    :close-on-press-escape="false"
  >
    <el-tabs
      @tab-click="
        (tabpane) => {
          if (tabpane.props.name == 'second') loadimage()
        }
      "
      v-model="activeName"
      type="card"
    >
      <el-tab-pane v-if="tagLoaded" label="影像" name="first">
        <el-scrollbar height="80vh">
          <iframe
            v-if="dataLoaded"
            frameborder="0"
            scrolling="no"
            :src="newSrc"
            style="width: 100%; height: 87vh; margin-right: 14px"
          ></iframe>
        </el-scrollbar>
      </el-tab-pane>
      <el-tab-pane label="报告单" name="second">
        <el-scrollbar height="80vh">
          <div style="display: flex">
            <!-- 模版区域 -->
            <div style="flex: 28; min-width: 0; border: 1px solid rgb(220, 223, 230)">
              <el-select
                v-model="fordevicemValue"
                placeholder="请选择模版类别"
                clearable
                @change="handleselectchange"
                @clear="selectclear"
                style="width: 100%"
              >
                <el-option label="门诊" value="门诊模版" />
                <el-option label="住院" value="住院模版" />
                <el-option label="体检" value="体检模版" />
              </el-select>
              <el-tabs type="border-card" style="border: none">
                <el-tab-pane label="通用模版">
                  <el-scrollbar height="114vh" style="border: 2px solid rgb(220, 223, 230)">
                    <el-tree
                      style="padding-top: 15px; padding-bottom: 20px; min-width: 195px"
                      v-loading="formLoading"
                      class="treeStyle"
                      :check-on-click-node="true"
                      :highlight-current="true"
                      :default-expand-all="true"
                      :data="treeData"
                      :props="treeDefaultProps"
                      node-key="id"
                      :show-checkbox="false"
                      :check-strictly="true"
                      @check="handleTreeNodeClick"
                      ref="selectTree"
                      :expand-on-click-node="false"
                    />
                  </el-scrollbar>
                </el-tab-pane>
                <el-tab-pane label="私有模版">
                  <el-scrollbar height="114vh" style="border: 2px solid rgb(220, 223, 230)">
                    <el-tree
                      style="padding-top: 15px; padding-bottom: 20px; min-width: 195px"
                      v-loading="formLoading"
                      class="treeStyle"
                      :check-on-click-node="true"
                      :highlight-current="true"
                      :default-expand-all="false"
                      :data="privateData"
                      :props="treeDefaultProps"
                      node-key="id"
                      :show-checkbox="false"
                      :check-strictly="true"
                      @node-click="handleTreeNodeClick"
                      ref="priselectTree"
                      :expand-on-click-node="false"
                    />
                  </el-scrollbar>
                </el-tab-pane>
              </el-tabs>
            </div>
            <!-- 用户信息区域 -->
            <div
              style="
                flex: 58;
                min-width: 0;
                border: 1px solid rgb(220, 223, 230);
                padding: 10px 14px 12px 2px;
                margin-left: 6px;
                margin-right: 6px;
              "
            >
              <label style="font-size: 18px; font-weight: bold; margin-left: 50px">患者信息</label>
              <el-divider />
              <el-form
                :model="applyFormVO"
                label-width="96px"
                style="max-width: 1000px; margin-left: 28px"
                :inline="false"
              >
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="检查号" style="font-weight: bold">
                      <el-input v-model="applyFormVO.examId" style="width: 100%" :disabled="true" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="姓名" style="font-weight: bold">
                      <el-input v-model="applyFormVO.pname" style="width: 100%" :disabled="true" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="性别" style="font-weight: bold">
                      <el-input v-model="applyFormVO.gender" style="width: 100%" :disabled="true" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="检查时间" style="font-weight: bold">
                      <el-date-picker
                        v-model="applyFormVO.examDate"
                        type="datetime"
                        placeholder=""
                        size="default"
                        style="width: 100%"
                        :disabled="true"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="出生日期" style="font-weight: bold">
                      <el-date-picker
                        v-model="applyFormVO.birthday"
                        type="date"
                        placeholder=""
                        size="default"
                        style="width: 100%"
                        :disabled="true"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="年龄" style="font-weight: bold">
                      <el-input v-model="age" style="width: 100%" :disabled="true" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="送检科室" style="font-weight: bold">
                      <el-input
                        v-model="applyFormVO.billDoctorDepartment"
                        style="width: 100%"
                        :disabled="true"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="申请时间" style="font-weight: bold">
                      <el-date-picker
                        v-model="applyFormVO.applicationDate"
                        type="datetime"
                        placeholder=""
                        size="default"
                        style="width: 100%"
                        :disabled="true"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="申请单号" style="font-weight: bold">
                      <el-input v-model="applyFormVO.regId" style="width: 100%" :disabled="true" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <!-- <el-form-item label="检查项目名称" style="font-weight: bold">
                    <el-input
                      v-model="applyFormVO.examItemName"
                      style="width: 220px"
                      :disabled="true"
                    />
                  </el-form-item> -->
                  </el-col>
                </el-row>
              </el-form>
              <label style="font-size: 18px; font-weight: bold; margin-left: 50px">肉眼所见</label>
              <el-divider />
              <div class="demo-image">
                <el-button
                  type="danger"
                  circle
                  style="width: 21px; height: 21px"
                  @click="deleteimage('1')"
                  :icon="Delete"
                  v-if="isImageLoaded"
                />
                <el-card style="width: 180px; text-align: center">
                  <el-image
                    style="width: 106px; height: 106px"
                    :src="selecteimagedone"
                    :close-on-press-escape="true"
                    fit="fill"
                    alt=""
                    :preview-src-list="[selecteimagedone]"
                    @load="handleLoad('1')"
                    @error="handleError('1')"
                  >
                    <template #error>
                      <div class="image-error">
                        <!--  <span>自定义加载失败提示</span> -->
                      </div>
                    </template>
                  </el-image>
                </el-card>
                <el-button
                  type="danger"
                  circle
                  style="width: 21px; height: 21px"
                  @click="deleteimage('2')"
                  :icon="Delete"
                  v-if="isImageLoaded2"
                />
                <el-card style="width: 180px; text-align: center">
                  <el-image
                    style="width: 106px; height: 106px"
                    :src="selecteimagedtwo"
                    :close-on-press-escape="true"
                    fit="fill"
                    alt=""
                    :preview-src-list="[selecteimagedtwo]"
                    @load="handleLoad('2')"
                    @error="handleError('2')"
                  >
                    <template #error>
                      <div class="image-error">
                        <!--  <span>自定义加载失败提示</span> -->
                      </div>
                    </template>
                  </el-image>
                </el-card>
                <el-button
                  type="danger"
                  circle
                  style="width: 21px; height: 21px"
                  @click="deleteimage('3')"
                  :icon="Delete"
                  v-if="isImageLoaded3"
                />
                <el-card style="width: 180px; text-align: center">
                  <el-image
                    style="width: 106px; height: 106px"
                    :src="selecteimagedthree"
                    :close-on-press-escape="true"
                    fit="fill"
                    alt=""
                    :preview-src-list="[selecteimagedthree]"
                    @load="handleLoad('3')"
                    @error="handleError('3')"
                  >
                    <template #error>
                      <div class="image-error">
                        <!--  <span>自定义加载失败提示</span> -->
                      </div>
                    </template>
                  </el-image>
                </el-card>
              </div>
              <label style="font-size: 18px; font-weight: bold; margin-left: 50px">标本名称</label>
              <el-divider />
              <el-input
                v-model="applyFormVO.examItemName"
                style="width: 95%; font-size: 20px; margin-left: 40px; margin-bottom: 6px"
                :rows="1"
                :disabled="true"
                placeholder="标本名称"
              />
              <label style="font-size: 18px; font-weight: bold; margin-left: 50px">病理所见</label>
              <el-divider />
              <el-input
                v-model="sj"
                style="width: 95%; font-size: 20px; margin-left: 40px; margin-bottom: 3px"
                :rows="4"
                type="textarea"
                placeholder="病理所见"
              />
              <label style="font-size: 18px; font-weight: bold; margin-left: 50px">病理结论</label>
              <el-divider />
              <el-input
                v-model="zdjl"
                style="width: 95%; font-size: 20px; margin-left: 40px; margin-bottom: 3px"
                :rows="4"
                type="textarea"
                placeholder="病理结论"
              />
              <label style="font-size: 18px; font-weight: bold; margin-left: 50px">报告备注</label>
              <el-divider />
              <el-input
                v-model="notes"
                style="
                  width: 95%;
                  font-size: 19px;
                  margin-left: 40px;
                  margin-top: 6px;
                  margin-bottom: 6px;
                "
                placeholder="报告备注"
              />
              <el-divider v-if="false" />
              <el-radio-group
                v-if="false"
                v-model="radio1"
                size="small"
                class="radio-group-wrapper"
                @dblclick="cancelSelection"
              >
                <el-radio-button label="阴性" value="0" />
                <el-radio-button label="阳性" value="1" />
                <el-radio-button label="重大阳性" value="2" />
              </el-radio-group>
              <el-divider />
              <div class="form-row-yx">
                <el-form-item label="诊断医生" class="form-item">
                  <el-input
                    v-model="applyFormVO.diagDoctor"
                    style="width: 180px"
                    :disabled="true"
                  />
                </el-form-item>
                <el-form-item label="审核医生" class="form-item">
                  <el-input
                    v-model="applyFormVO.reviewDoctor"
                    style="width: 180px"
                    :disabled="true"
                  />
                </el-form-item>

                <el-form-item label="报告状态" class="form-item">
                  <el-input
                    v-model="applyFormVO.reportstatus"
                    style="width: 180px"
                    :disabled="true"
                  />
                </el-form-item>
              </div>

              <div style="text-align: right">
                <el-button
                  type="primary"
                  plain
                  v-show="examinedisabled"
                  style="
                    width: 80px;
                    margin-right: 15px;
                    background-color: rgba(56, 119, 246, 1);
                    font-size: 14;
                    color: rgb(255, 255, 255);
                  "
                  @click="examine"
                >
                  审核
                </el-button>
                <el-button
                  type="success"
                  plain
                  style="
                    width: 80px;
                    margin-right: 15px;
                    background-color: rgba(56, 119, 246, 1);
                    font-size: 14;
                    color: rgb(255, 255, 255);
                  "
                  @click="save"
                  :disabled="savedisabled"
                >
                  保存
                </el-button>
              </div>
            </div>
            <!-- 右侧按钮区域 -->
            <div
              style="
                flex: 14;
                min-width: 0;
                padding-left: 4px;
                padding-right: 4px;
                margin-right: 14px;
                border: 1px solid rgb(220, 223, 230);
              "
            >
              <div style="width: 100%">
                <el-button
                  style="
                    background-color: rgb(56, 119, 246);
                    font-size: 14;
                    color: rgb(255, 255, 255);
                    width: 100%;
                    margin-top: 4px;
                    margin-bottom: 4px;
                  "
                  @click="refreshImages"
                  :disabled="savedisabled"
                >
                  <el-icon style="margin-right: 10px"><Refresh /></el-icon>
                  图像刷新
                </el-button>
              </div>
              <div class="image-container image-wrapper">
                <el-image
                  class="image-item"
                  v-for="image in images"
                  :key="image.id"
                  :src="image.imgUrl"
                  @click="chooseImage($event, image.id)"
                  @dblclick="selectImage(image.imgUrl, image.id)"
                />
              </div>
            </div>
          </div>
        </el-scrollbar>
      </el-tab-pane>
    </el-tabs>
  </el-dialog>
  <!--  弹窗-->
  <el-dialog v-model="dialogTableVisible" title="选择结论添加方式" width="320" align-center>
    <div>
      <el-button @click="handleButtonClick('覆盖')" type="primary" style="font-size: 20px"
        >覆盖</el-button
      >
      <el-button @click="handleButtonClick('追加')" type="success" style="font-size: 20px"
        >追加</el-button
      >
      <el-button @click="dialogTableVisible = false" type="info" style="font-size: 20px"
        >关闭</el-button
      >
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { Delete } from '@element-plus/icons-vue'
import { ultrasoniccomApi, updateexamineimageVO } from '@/api/ultrasoniccom'
import { PatientexamlistApi, PatientexamlistVO } from '@/api/tblist/patientexamlist'
import { getUserProfile, ProfileVO } from '@/api/system/user/profile'

/** dicom */
defineOptions({ name: 'DicomPathologyViewForm' })

/** 图片相关 **/
const images = ref<any[]>([])
const chooseImageid = ref('')
const updateexamineimage = ref<updateexamineimageVO[]>([])
const getimages = async (type: string) => {
  let imageslist = await ultrasoniccomApi.getpathologyimglist(orgId.value, regId.value, type)
  images.value = imageslist
  //处理choose
  chooseImageid.value = ''
  let items = document.querySelectorAll('.image-item')
  if (items) {
    items.forEach((item) => {
      item.classList.remove('image-item-selected')
    })
  }
}
const chooseImage = async (event, id: number) => {
  chooseImageid.value = id.toString()
  let items = document.querySelectorAll('.image-item')
  if (items) {
    items.forEach((item) => {
      item.classList.remove('image-item-selected')
    })
  }
  event.target.parentNode.classList.add('image-item-selected')
}
const selectImage = (imageUrl: string, id: number) => {
  if (selecteimagedone.value == '1') {
    selecteimagedone.value = imageUrl
    selecteimagedoneid = id
    return
  }
  if (selecteimagedtwo.value == '2') {
    selecteimagedtwo.value = imageUrl
    selecteimagedtwoid = id
    return
  }
  if (selecteimagedthree.value == '3') {
    selecteimagedthree.value = imageUrl
    selecteimagedthreeid = id
    return
  }
}
const isImageLoaded = ref(false)
const isImageLoaded2 = ref(false)
const isImageLoaded3 = ref(false)
const selecteimagedone = ref('1')
const selecteimagedtwo = ref('2')
const selecteimagedthree = ref('3')
let selecteimagedoneid: number = 0
let selecteimagedtwoid: number = 0
let selecteimagedthreeid: number = 0
const handleLoad = (id: string) => {
  if (applyFormVO.value.reportstatus && applyFormVO.value.reportstatus == '已审核') {
    isImageLoaded.value = false
    isImageLoaded2.value = false
    isImageLoaded3.value = false
  } else {
    switch (id) {
      case '1':
        isImageLoaded.value = true
        break
      case '2':
        isImageLoaded2.value = true
        break
      case '3':
        isImageLoaded3.value = true
        break
    }
  }
}
const handleError = (id: string) => {
  switch (id) {
    case '1':
      isImageLoaded.value = false
      break
    case '2':
      isImageLoaded2.value = false
      break
    case '3':
      isImageLoaded3.value = false
      break
  }
}
const deleteimage = (flag: string) => {
  if (flag == '1') {
    selecteimagedone.value = '1'
    selecteimagedoneid = 0
    return
  } else if (flag == '2') {
    selecteimagedtwo.value = '2'
    selecteimagedtwoid = 0
    return
  } else if (flag == '3') {
    selecteimagedthree.value = '3'
    selecteimagedthreeid = 0
    return
  }
}
const upimageselect = async () => {
  try {
    updateexamineimage.value = []
    updateexamineimage.value.push({
      id: selecteimagedoneid.toString(),
      isDelete: '',
      deletePerson: '',
      selected: '1'
    })
    updateexamineimage.value.push({
      id: selecteimagedtwoid.toString(),
      isDelete: '',
      deletePerson: '',
      selected: '1'
    })
    updateexamineimage.value.push({
      id: selecteimagedthreeid.toString(),
      isDelete: '',
      deletePerson: '',
      selected: '1'
    })
    let response = await ultrasoniccomApi.updateexamineimagelist(updateexamineimage.value)
    if (response) {
      console.log('更新图片标识接口调用成功')
    }
  } finally {
    updateexamineimage.value = []
  }
}
const loadimage = async () => {
  if (applyFormVO.value.reportstatus == '已分析' || applyFormVO.value.reportstatus == '已审核') {
    let imageslist = await ultrasoniccomApi.getpathologyimglist(orgId.value, regId.value, '1')
    if (imageslist.length > 0) {
      imageslist.forEach((image, index) => {
        switch (index) {
          case 0:
            selecteimagedone.value = image.imgUrl
            selecteimagedoneid = image.id
            break
          case 1:
            selecteimagedtwo.value = image.imgUrl
            selecteimagedtwoid = image.id
            break
          case 2:
            selecteimagedthree.value = image.imgUrl
            selecteimagedthreeid = image.id
            break
        }
      })
    }
  }
}

/** 组件引用 **/
const selectTree = ref()

/** 数据结构 **/
const message = useMessage()
const { t } = useI18n()
const Profilevo = ref<ProfileVO>({} as ProfileVO)
const dialogVisible = ref(false)
const dialogTitle = ref('')
const activeName = ref('first')
//影像
const dataLoaded = ref(false) //是否加载网页
const tagLoaded = ref(true) //是否加载影像标签
const newSrc = ref('') //内嵌网页加载增加时间戳 防止缓存
//报告单
const savedisabled = ref(false) //保存按钮是否可用
const examinedisabled = ref(true) //审核按钮是否可见
const fordevicemValue = ref('') //下拉模版类别
//报告单(树相关)
const formLoading = ref(false)
const dialogTableVisible = ref(false)
const treeDefaultProps = {
  children: 'children',
  label: 'tempname'
} //树配置项
const treeData = ref([]) //通用树数据
const privateData = ref([]) //私有树数据
let strzdjl: string = '' //当前选中节点的值
let strsj: string = ''
let pid: string = '' //当前节点的父id

/** 自定义方法 **/
const resetForm = () => {
  //images
  images.value = []
  chooseImageid.value = ''
  isImageLoaded.value = false
  isImageLoaded2.value = false
  isImageLoaded3.value = false
  selecteimagedone.value = '1'
  selecteimagedtwo.value = '2'
  selecteimagedthree.value = '3'
  selecteimagedoneid = 0
  selecteimagedtwoid = 0
  selecteimagedthreeid = 0
  //其它
  applyFormVO.value = {} as PatientexamlistVO
  pid = ''
  strzdjl = ''
  strsj = ''
  activeName.value = 'first'
  updateexamineimage.value = []
  //selectTree.value = ''
  treeData.value = []
  privateData.value = []
  fordevicemData.value = []
  fordevicemValue.value = ''
  upFJApplyformVO.value = []
  formRef.value?.resetFields()
  orgId.value = ''
  regId.value = ''
}

const getlogininfo = async () => {
  Profilevo.value = await getUserProfile()
  console.log('审核是否可见' + Profilevo.value.isimageexamine)
  if (false && Profilevo.value.isimageexamine === '1') {
    examinedisabled.value = true
  }
}

const applyFormVO = ref<PatientexamlistVO>({} as PatientexamlistVO)
const radio1 = ref('') //阴性阳性
const zdjl = ref('') //诊断结论
const sj = ref('') //所见
const notes = ref() //备注
const getPatientexamlist = async (id: number) => {
  const data = await PatientexamlistApi.getPatientexamlist(id)
  applyFormVO.value = data
  //阳性阴性 赋值
  //radio1.value = applyFormVO.value.diagFlag
  radio1.value = '0'
  zdjl.value = applyFormVO.value.diagResults
  sj.value = applyFormVO.value.examDescription
  notes.value = applyFormVO.value.notes
  calculateAge(applyFormVO.value.birthday)

  if (
    applyFormVO.value.reportstatus &&
    (applyFormVO.value.reportstatus == '已分析' ||
      applyFormVO.value.reportstatus == '已分检' ||
      applyFormVO.value.reportstatus == '待分析')
  ) {
    savedisabled.value = false
  } else {
    savedisabled.value = true
  }
  loadimage()
}

const age = ref()
const calculateAge = (birthdate) => {
  if (!birthdate) {
    age.value = null
    return
  }
  const today = new Date()
  const birth = new Date(birthdate)
  let yearsDiff = today.getFullYear() - birth.getFullYear()
  // Check if the birthday hasn't occurred yet this year
  const hasBirthdayPassed =
    today.getMonth() > birth.getMonth() ||
    (today.getMonth() === birth.getMonth() && today.getDate() >= birth.getDate())
  if (!hasBirthdayPassed) {
    yearsDiff--
  }
  age.value = yearsDiff
}

const clickuptime = async (pid: string) => {
  await ultrasoniccomApi.upreporttemplatetime(pid)
}

const iframeData = async () => {
  try {
    const response = await ultrasoniccomApi.getdcmlist(examid.value, orgId.value, regId.value)
    if (response) {
      //给打开的内嵌html 传递参数
      var localData = {
        regid: '', // 这里的 'someNumber' 应该替换为实际的数值
        orgId: '', // 这里的 'someOrgId' 应该替换为实际的组织ID
        maxSize: 10,
        do: response
      }
      // 在存入新数据之前，先删除原有的'data'项
      localStorage.removeItem('data')
      // 将对象转换为JSON字符串
      var localStorageData = JSON.stringify(localData)
      localStorage.setItem('data', localStorageData)
      localStorage.removeItem('regid_pathology')
      localStorage.setItem('regid_pathology', regId.value)
      localStorage.removeItem('orgId_pathology')
      localStorage.setItem('orgId_pathology', orgId.value)
      const Src = `/static/dicom/dicomViewPc1.html?method=PathologyView&t=${new Date().getTime()}`
      newSrc.value = Src
    } else {
      // 如果status不是success，可以根据需要处理错误情况
      console.error('Request did not succeed:', response.data)
    }
    // dataLoaded.value = true // 请求完成后，无论成功与否，都设置dataLoaded为true
  } catch (error) {
    console.error('Error fetching data:', error)
    // dataLoaded.value = true // 即使发生错误，也设置dataLoaded为true，以便可以显示错误信息
  }
}

/** 组件事件 **/
let ID: number
const orgId = ref('')
const regId = ref('')
const examid = ref('')
const open = async (id: number, orgid: string, regid: string, examId: string, isLoaded: string) => {
  resetForm()

  //判断是否隐藏影像标签
  if (isLoaded == '1') {
    tagLoaded.value = false
    activeName.value = 'second'
  } else {
    tagLoaded.value = true
    activeName.value = 'first'
  }
  console.log('orgid' + orgid)
  console.log('regid' + regid)
  console.log('id' + id)
  orgId.value = orgid
  regId.value = regid
  examid.value = examId
  ID = id
  dialogVisible.value = true
  dialogTitle.value = '书写报告(病理)'
  // 提交请求
  formLoading.value = true
  try {
    //通用
    const dd = await ultrasoniccomApi.getreporttemplatelist('', String(fordevicemValue.value), '')
    treeData.value = dd
    console.log('返回值1' + dd)
    console.log('返回值2' + treeData.value)
    //私有
    const pridate = await ultrasoniccomApi.getreporttemplatelist(
      '',
      String(fordevicemValue.value),
      '1'
    )
    privateData.value = pridate
    getPatientexamlist(id)
    getlogininfo()
    iframeData()
    // 延迟1秒后加载iframe
    setTimeout(() => {
      dataLoaded.value = true // 确保iframe只在弹窗打开时加载
    }, 200)
    if (savedisabled.value == false) getimages('')
  } finally {
    formLoading.value = false
  }
}

const examineFormVO = ref<PatientexamlistVO>({} as PatientexamlistVO)
const save = async () => {
  try {
    if (selecteimagedoneid == 0 || selecteimagedtwoid == 0 || selecteimagedthreeid == 0) {
      message.warning('请选择影像图')
      return
    }
    // 二次确认
    await message.delConfirm('是否进行保存', '确认')
    let timesta = new Date()
    var localDateTime = new Date(timesta.getTime()).toISOString() // 转换为ISO格式的字符串
    localDateTime = localDateTime.slice(0, localDateTime.length - 1)
    console.log('当前时间' + localDateTime)
    examineFormVO.value.id = ID.toString()
    examineFormVO.value.examDescription = sj.value
    examineFormVO.value.diagResults = zdjl.value
    examineFormVO.value.notes = notes.value
    examineFormVO.value.diagFlag = radio1.value
    examineFormVO.value.diagDoctor = Profilevo.value.doctorname
    examineFormVO.value.diagDoctorId = Profilevo.value.doctorID
    // examineFormVO.value.reviewDoctor = Profilevo.value.username
    examineFormVO.value.reportstatus = '已分析'
    // examineFormVO.value.diagDate=localDateTime
    // examineFormVO.value.reviewDate=dateTime

    const response = await PatientexamlistApi.examineupdatelist(examineFormVO.value)
    // 根据code判断接口调用是否成功
    if (response) {
      await upimageselect()
      message.alertSuccess('保存成功')
      // 接口调用成功，可以根据需要处理返回的data数据
      console.log('接口调用成功')
      console.log('data:', response.data)
      //查询患者信息 根据ID
      getPatientexamlist(ID)
      emit('success')
    } else {
      // 接口调用失败，根据具体情况处理错误
      console.error('接口调用失败:', response.msg)
    }
  } catch (error) {
    // 处理异常情况，例如接口调用失败或其他错误
    console.error('接口调用失败:', error)
  }
}

const examine = async () => {
  if (applyFormVO.value.reportstatus === '已分析') {
    const response = await PatientexamlistApi.examine(ID.toString())
    if (response) {
      message.alertSuccess('审核成功')
      getPatientexamlist(ID)
      isImageLoaded.value = false
      isImageLoaded2.value = false
      isImageLoaded3.value = false
      images.value = []
      emit('success')
    }
  } else if (applyFormVO.value.reportstatus === '已审核') {
    message.warning('已经审核,无需再次审核')
    return
  } else {
    message.warning('请先进行保存')
    return
  }
}

const cancelSelection = () => {
  radio1.value = ''
}

const refreshImages = async () => {
  getimages('')
}

const handleselectchange = async () => {
  console.log(fordevicemValue.value)

  if (fordevicemValue.value) {
    //选择模版后 刷新接口
    //通用
    const dd = await ultrasoniccomApi.getreporttemplatelist('', String(fordevicemValue.value), '')
    treeData.value = dd

    const pridate = await ultrasoniccomApi.getreporttemplatelist(
      '',
      String(fordevicemValue.value),
      '1'
    )
    privateData.value = pridate
  }
}

const selectclear = async () => {
  //选择模版后 刷新接口
  //通用
  const dd = await ultrasoniccomApi.getreporttemplatelist('', '', '')
  treeData.value = dd

  const pridate = await ultrasoniccomApi.getreporttemplatelist('', '', '1')
  privateData.value = pridate
}

const handleTreeNodeClick = async (data) => {
  strzdjl = data.diagResults
  strsj = data.examDescription
  pid = data.pid
  console.log('父节点' + data.pid)
  //判断节点类型的不需要弹
  if (data.dataType === '0') {
    dialogTableVisible.value = true
  }
}

const handleButtonClick = (buttonName) => {
  if (buttonName == '覆盖') {
    zdjl.value = strzdjl
    sj.value = strsj
  } else if (buttonName == '追加') {
    let lszdjl: string = zdjl.value
    let lssj: string = sj.value
    zdjl.value = lszdjl + strzdjl
    sj.value = lssj + strsj
  }
  dialogTableVisible.value = false
  console.log('获取到父节点' + pid)
  clickuptime(pid)
}

/** 导入内容 **/
const emit = defineEmits(['success'])

/** 导出内容 **/
defineExpose({ open })

/** 备用内容 **/
const formRef = ref()
const formRules = reactive({})
const btncleckname = ref()
const fordevicemData = ref<any[]>([])
const upFJApplyformVO = ref<any[]>([])
const PrintForm = () => {
  //window.print()
  //发送操作成功的事件
  emit('success')
}
</script>

<style scoped>
/* 
.my-container-yx {
  height: 100vh;
  width: 100vw;
}
*/

/* 报告区域 左侧模版选择字体大小 */
.treeStyle {
  font-size: 20px;
}
/* 分割线内部的间距 */
.el-divider--horizontal {
  margin: 6px;
}
/* 阴性 阳性 */
.radio-group-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px; /* 调整上方外边距 */
  margin-right: 33px;
}

/* 诊断医生等样式 */
.form-row-yx {
  display: flex;
  justify-content: space-around; /* 将元素左右对齐 */
  margin-top: 8px;
  margin-left: 26px;
}

/* 右侧图片列表样式 */
.image-container {
  overflow-y: auto;
  /* 添加一些外边距来控制图像容器与周围元素之间的间距 */
  margin-top: 10px;
  margin-bottom: 10px;
  padding-top: 10px;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
}

.image-wrapper {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  gap: 10px; /* 设置图像之间的间距 */
  width: 100%;
  flex-direction: column;
}

.image-item {
  /* 可选：设置图像的宽度和高度 */
  width: 80%;
  height: auto;
  cursor: pointer;
  transition: transform 0.3s ease; /* 添加过渡效果 */
}

.image-item2:hover {
  transform: scale(1.1); /* 放大容器 */
}

.image-item-selected {
  outline: none;
  border-color: blue;
  box-shadow: 0 0 10px blue;
}

.image-item2:active {
  transform: scale(0.9); /* 缩小图像 */
}

.demo-image {
  margin-top: 10px;
  margin-bottom: 10px;
  display: flex;
  justify-content: center;
}

.demo-image .el-card:not(:last-child) {
  margin-right: 72px;
}
</style>
