<template>
  <el-button @click="printClick">打印</el-button>
  <div style="width: 595.275pt;  height: 841.89pt;  font-size: 6.75pt;
   border: 0.75pt solid" ref="divRef">
    <h1 style="text-align: center; font-size: 22.5pt;margin-bottom: 3.75pt">长沙泰和医院</h1>
    <h4 style="text-align: center; font-size: 12.75pt; margin-top: 0">会 诊 记 录 单</h4>
    <table style="width: 100%;border-bottom: 0.75pt solid #000">
      <tr>
        <td>
          住院号：{{ huanZheXinXi.inpatientNo }}
        </td>
        <td>
          姓名：{{ huanZheXinXi.name }}
        </td>
        <td>
          性别：{{ cptSex(huanZheXinXi.sex) }}
        </td>
        <td>
          年龄：{{ huanZheXinXi.age }}
        </td>
        <td>
          科室：{{ huanZheXinXi.deptCodeName }}
        </td>
        <td>
          床号：{{ huanZheXinXi.bedNo }}
        </td>
      </tr>
    </table>
    <div style="height: 3.75pt"/>
    <div style="width: 100%; height: 15pt;">
      <div style="width: 375pt;height: 100%;float: left">
        <table>
          <tr>
            <td>
              请
            </td>
            <td style="width: 115pt;border-bottom: 0.75pt solid #000">
              {{ huanZheXinXi.reqDept1Name }}
            </td>
            <td>
              会诊
            </td>
          </tr>
        </table>
      </div>

      <div style=" width: 120pt;float: right">
        会诊类别: {{ hzLeiBie(huanZheXinXi.hzType) }}
      </div>
    </div>
    <div style="width: 100%;padding: 7.5pt 7.5pt 0 7.5pt">
      病情简介
      <textarea v-model="huanZheXinXi.reqComment"
                readonly="readonly"
                style="height: 115.5pt;
                margin: 3.75pt 0 0;width: 574.75pt;border: none;overflow: hidden;
                resize:none;"/>
      <br>
      目前主要诊断
      <textarea v-model="huanZheXinXi.hzZd"
                readonly="readonly"
                style="height: 37.5pt;
                margin: 3.75pt 0 0;width: 574.75pt;border: none;overflow: hidden;
                resize:none;"/>
      <br>
      会诊目的
      <textarea v-model="huanZheXinXi.hzMd"
                readonly="readonly"
                style="height: 37.5pt;
                margin: 3.75pt 0 0;width: 574.75pt;border: none;overflow: hidden;
                resize:none;"/>
      <div style="float: right">
        <table>
          <tr>
            <td style="width: 165pt">
              请求会诊科室：{{ huanZheXinXi.deptCodeName }}
            </td>
            <td style="width: 165pt">
              会诊申请医师：{{ huanZheXinXi.reqDoctor }}
            </td>
          </tr>
          <tr>
            <td style="width: 165pt">
              申请时间：{{ huanZheXinXi.reqDate }}
            </td>
          </tr>
        </table>
      </div>
      <div style="clear: both"></div>
      <hr>
      会诊意见
      <textarea v-model="huanZheXinXi.hzComment"
                maxlength="1100"
                :readonly="laiYuan === 2"
                onkeydown="if(event.keyCode === 13)event.returnValue = false;"
                style="height: 246.75pt;
                margin: 3.75pt 0 0;width: 574.75pt;border: none;overflow: hidden;
                resize:none;"/>
      <div style="float: right">
        <table>
          <tr>
            <td style="width: 165pt">
              会诊科室：{{ huanZheXinXi.reqDept1Name }}
            </td>
            <td style="width: 165pt">
              医师：{{ props.laiYuan === 2 ? huanZheXinXi.hzDoctor2Name : store.state.user.info.name }}
            </td>
          </tr>
          <tr>
            <td style="width: 165pt">
              会诊时间：{{ huanZheXinXi.hzDate }}
            </td>
          </tr>
        </table>
      </div>

    </div>
  </div>

</template>

<script setup name='PrintTheConsultationForm'>
import {onMounted} from "vue";
import {getLodop, initLodop} from "@/utils/c-lodop";
import {cptSex} from "@/utils/computed";
import store from '@/store'
import {getServerDateApi} from "@/api/public-api";

const props = defineProps({
  laiYuan: {
    type: Number,
    default: 1,
  },
})

const divRef = ref()
const huanZheXinXi = ref({})

async function shiJian() {
  if (props.laiYuan === 1) {
    huanZheXinXi.value.hzDate = await getServerDateApi()
  }
}

const huiZhenXinXiXiangQing = async (val) => {
  await shiJian()
  huanZheXinXi.value = val
}

const printClick = async () => {
  if (props.laiYuan === 1) {
    await shiJian()
  }
  const allTextArea = divRef.value.getElementsByTagName('textarea')
  const textInput = divRef.value.getElementsByTagName('input')
  for (let i = 0; i < textInput.length; i++) {
    textInput[i].setAttribute('value', textInput[i].value)
  }
  for (let i = 0; i < allTextArea.length; i++) {
    allTextArea[i].innerText = allTextArea[i].value
  }
  let LODOP = getLodop()
  const strFormHtml = '<body>' + divRef.value.innerHTML + '</body>'
  LODOP.PRINT_INIT('会诊记录单') // 初始化打印机 名字
  LODOP.SET_PRINT_PAGESIZE(1, '210mm', '297mm', '') // 设置纸张大小  A4
  LODOP.SET_PRINT_MODE('FULL_WIDTH_FOR_OVERFLOW', true) // 整宽不变形
  LODOP.ADD_PRINT_HTM('2mm', '5mm', '100%', '100%', strFormHtml) //要打印的内容
  LODOP.SET_PRINT_STYLE('ItemType', 3) //设置对象风格
  LODOP.ADD_PRINT_TEXT('290mm', '190mm', '20mm', '2mm', '第#页/共&页') //增加纯文本项
  LODOP.PREVIEW() // 关闭
}

onMounted(() => {
  initLodop()
})

const fanHuiXinXi = () => {
  emit('fanHuiXinXi', {huanZheXinXi})
}

defineExpose({
  huiZhenXinXiXiangQing
})


function hzLeiBie(val) {
  switch (val) {
    case '1':
      return '常规会诊'
    case '2':
      return '疑难病例会诊'
    case '3':
      return '急救会诊'
  }
}
</script>

<style scoped lang="scss">

</style>
