<template>
  <div :style="'overflow: scroll;font-size: 14px;width:100%;height:' + divHeight + 'px;'">
    <table width="100%">
      <tbody v-for="(item, index) of tableData" :key="index">
        <tr height="40">
          <td width="100" class="tdCellClass">体检次数：</td>
          <td width="100" class="tdCellClass">{{ item.medicalTimes }}</td>
          <td width="200" class="tdCellClass">总检医生：{{ item.summaryDoctor }}</td>
          <td class="tdCellClass">总检日期：{{ item.summaryDate }}</td>
        </tr>
        <tr height="10">
          <td colspan="4"></td>
        </tr>
        <tr height="40">
          <td width="100" class="tdCellClass" style="vertical-align: top;">检查综述：</td>
          <td colspan="3" class="tdCellClass" v-html="item.sumSummarys"></td>
        </tr>
        <tr height="20">
          <td colspan="4"></td>
        </tr>
        <tr height="40">
          <td width="100" class="tdCellClass" style="vertical-align: top;">医生建议：</td>
          <td colspan="3" class="tdCellClass" v-html="item.sumSuggestions"></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import Sortable from "sortablejs";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { arrayExistObj } from '@/utlis/proFunc';
export default {
  components: {},
  props: ["patientId","tabChoosed"],
  data() {
    return {
      tableData: [],   //显示数据
    };
  },

  created() { },

  //挂载完成
  mounted() {
    // if(this.patientId){
    //   this.SumHistory(this.patientId);
    // }
    this.SumHistory(this.patientId) 
  },

  computed: {
    ...mapState(['window', 'dict','dataTransOpts', 'doctorCheck', 'sumDoctorCheck']),
    divHeight() {
      let tempHeight = this.window.pageHeight < 600 ? 600 : this.window.pageHeight
      return tempHeight - 195
    },
  },

  methods: {
    //获取历次综述
    // {
    //   "medicalTimes": 3,
    //   "summaryDoctor": "admin",
    //   "summaryDate": "7/24/2023",
    //   "sumSummarys": "*  乙肝两对半：\n(01)无免疫\n*  身高体重：\n(01)重度脂肪肝\n*  血常规：\n(01)白细胞计数升高\n*  心电图：\n(01)右眼近视\n",
    //   "sumSuggestions": "*  乙肝两对半：\n(01)接种疫苗\n*  身高体重：\n(01)减肥、锻炼\n*  血常规：\n(01)注意休息\n*  心电图：\n(01)护眼及注意用眼卫生\n"
    // },    
    SumHistory(patientId) {
      this.tableData = []
      if (!patientId) return
      console.log(`/api/app/sumsummaryreport/gethistoricalreviewlist?PatientId=${patientId}`)
      getapi(`/api/app/sumsummaryreport/gethistoricalreviewlist?PatientId=${patientId}`)
        .then((res) => {
          console.log("获取历次综述 SumHistory", res.data);
          if (res.code != -1) {
            this.tableData = res.data;
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `操作失败，原因：${err}` });
        });
    },

    lreplaceAll(str) {
      return str.replaceAll('*', "<br/>")
    },

  },

  //监听事件
  watch: {    
    // 虚拟表 触发强制刷新 （sumDoctor.M 合并包含：综述、建议、对比、历史等，不包含总检诊断）
    "dataTransOpts.refresh.sumDoctor.M":{
      // immediate:true,
      handler(newVal, oldVal) {
        console.log(`watch 总检--历次综述建议 newVal: ${newVal}, oldVal: ${oldVal} patientId: ${this.patientId}`);        
        if(newVal != oldVal && this.tabChoosed == '6') this.SumHistory(this.patientId)
      }
    },

  },
};
</script>
<style scoped>
::v-deep .el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  padding: 0;
}
.tdCellClass {
  padding: 0 5px;
}
</style>
  