<template>
  <div id="MyDiv" style="margin: 16px;" :class="{ nocopy: $route.query.status }">
    <!-- <div class="header">
      <el-button @click="getback">返回</el-button>
    </div> -->
    <div class="cont_container">
      <!-- 左侧点击列表部分 -->
      <div class="cont-left-tiem">
        <ul class="el-menu-vertical-demo el-menu">
          <li class="li-left-item" :class="is_active == 0 ? 'is-active' : ''" @click="clickTree(0, '住院病案')">
            <span>住院病案</span>
          </li>
          <li
            :class="[is_active == item.bllb && item.bllb != 49 ? 'is-active' : '', item.bllb == 49 || [2000002, 294, 303].includes(item.bllb) ? 'li-left-itemyz' : 'li-left-item']"
            v-for="(item, index) in treeList"
            :key="index"
            @click="clickTree(item.bllb, item.name, item)"
          >
            <span>{{ item.name }}</span>
            <div v-if="item.bllb == 49">
              <div :class="['li-left-item-li', is_active == '长期医嘱' ? 'is-active' : '']" data-li="49-1">长期医嘱</div>
              <div :class="['li-left-item-li', is_active == '临时医嘱' ? 'is-active' : '']" data-li="49-2">临时医嘱</div>
            </div>
            <div v-if="item.bllb == 2000002">
              <div :class="['li-left-item-li', is_active == jitem.ExamType ? 'is-active' : '']" v-for="(jitem, jindex) in item.list" :key="jindex" :id="jitem.type">
                {{ jitem.name }}
              </div>
            </div>
            <!-- 病程记录、手术记录 -->
            <div v-if="[294, 303].includes(item.bllb)">
              <div
                :class="['li-left-item-li', is_active == jitem.blbh ? 'is-active' : '']"
                v-for="(jitem, jindex) in item.list"
                :key="jindex"
                :id="`${jitem.blbh}`"
                :title="jitem.name.trim()"
              >
                {{ jitem.name.trim() }}
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="cont-left-file">
        <div v-if="is_active == 0">
          <mainHomePage :data="mainHomeData" ref="main" :ifFile="ifFile"></mainHomePage>
        </div>
        <div v-else-if="is_active == 292">
          <!-- 入院记录 -->
          <admissionRecord :data="admissionRecord" :ifFile="ifFile"></admissionRecord>
        </div>
        <div v-else-if="parentType == '1' && is_active == 1">
          <!-- 出院记录 -->
          <OutHospitalRecord :data="outHospitalRecordData" />
        </div>
        <div v-else-if="bcjlLiIds.includes(Number(is_active))">
          <!-- 病程记录 -->
          <CaseRecord :data="caseRecodeInfo" v-if="caseRecodeInfo.is_format === 1" />
          <NoFormatText :text="caseRecodeInfo.content" :data="caseRecodeInfo" name="" v-else />
        </div>
        <div v-else-if="shoushuLiIds.includes(Number(is_active))">
          <!-- 手术记录 -->
          <template v-if="surgeryData.is_format">
            <ShouShuRecord1 v-if="surgeryData.type === 1" :data="surgeryData" />
            <ShouShuRecord2 v-if="surgeryData.type === 2" :data="surgeryData" />
            <ShouShuRecord4 v-if="surgeryData.type === 4" :data="surgeryData" />
          </template>
          <NoFormatText v-else :text="surgeryData.content" :data="surgeryData" :name="blname_title" />
        </div>
        <div v-else-if="is_active == '长期医嘱'">
          <!-- 长期医嘱 -->
          <medicalAdvice :dataObj="longAdvice"></medicalAdvice>
        </div>
        <div v-else-if="is_active == '临时医嘱'">
          <!-- 临时医嘱 -->
          <medicalTemporary :dataObj="happensAdvice"></medicalTemporary>
        </div>
        <div v-else-if="parentType == '2000002' && is_active == '1'">
          <!-- 病历图文报告 -->
          <caseImageText :dataObjArr="pacsDetail"></caseImageText>
        </div>
        <div v-else-if="parentType == '2000002' && is_active == '2'">
          <!-- 超声诊断 -->
          <ultrasound :dataObjArr="pacsDetail"></ultrasound>
        </div>
        <div v-else-if="parentType == '2000002' && is_active == '3'">
          <!-- 影像诊断 -->
          <imaging :dataObjArr="pacsDetail"></imaging>
        </div>
        <div v-else-if="parentType == '2000002' && is_active == '4'">
          <!-- 为心电 -->
          <electrocar :dataObjArr="pacsDetail"></electrocar>
        </div>
        <div v-else-if="parentType == '2000002' && is_active == '5'">
          <!-- 检验报告单 病理 -->
          <checkout :dataObjArr="pacsDetail"></checkout>
        </div>
        <div v-else-if="parentType == '2000002' && is_active == '6'">
          <!-- 內窥镜检查报告 病理 -->
          <sightGlass :dataObjArr="pacsDetail"></sightGlass>
        </div>
        <div v-else-if="is_active == 288 || is_active == 18">
          <!-- 死亡记录 或者 24小时内入院记录 -->
          <DeathText :dataObjArr="dataObj"></DeathText>
        </div>
        <div v-else>
          <newContFile v-for="(item, index) of text" :key="index" :text="item.HJNR" :name="name_title"></newContFile>
        </div>
      </div>
      <!-- status 不存在 意味着不脱敏、医院自助查询 -->
      <template v-if="!$route.query.status">
        <!-- 住院病案质控 -->
        <CaseQualityBox :data="results" :type="type_v" :width="380" :height="820" />
      </template>
    </div>
  </div>
</template>
<script>
import Mmenu from '@/components/m-menu';
import mainHomePage from '@/views/allcase/contFile/mainHomePage';
import newContFile from '@/views/allcase/contFile/newContFile';
import admissionRecord from '@/views/allcase/contFile/admissionRecord';
import medicalAdvice from '@/views/allcase/contFile/medicalAdvice';
import medicalTemporary from '@/views/allcase/contFile/medicalTemporary';
import caseImageText from '@/views/allcase/report/caseImageText';
import ultrasound from '@/views/allcase/report/ultrasound';
import imaging from '@/views/allcase/report/imaging';
import electrocar from '@/views/allcase/report/electrocar';
import checkout from '@/views/allcase/report/checkout';
import sightGlass from '@/views/allcase/report/sightGlass';
import CaseRecord from './components/CaseRecord2.vue';
import ShouShuRecord1 from './components/ShouShuRecord1.vue';
import ShouShuRecord2 from './components/ShouShuRecord2.vue';
import ShouShuRecord4 from './components/ShouShuRecord4.vue';
import NoFormatText from './components/NoFormatText.vue';
import OutHospitalRecord from './components/OutHospitalRecord.vue';
import CaseQualityBox from './components/CaseQualityBox2.vue';
import DeathText from './components/DeathText.vue';

export default {
  components: {
    Mmenu,
    mainHomePage,
    newContFile,
    admissionRecord,
    medicalAdvice,
    medicalTemporary,
    caseImageText,
    ultrasound,
    imaging,
    electrocar,
    sightGlass,
    checkout,
    CaseRecord,
    ShouShuRecord1,
    ShouShuRecord2,
    ShouShuRecord4,
    NoFormatText,
    OutHospitalRecord,
    CaseQualityBox,
    DeathText,
  },
  directives: {},
  filters: {},
  extends: {},
  mixins: {},
  props: {},
  data() {
    return {
      type_v:'', // v2 表示从（事中）进入
      mainHomeData: {},
      admissionRecord: {},
      longAdvice: {},
      happensAdvice: {},
      valData: '',
      ifFile: false,
      treeList: [],
      is_active: 0,
      parentType: 0,
      name_title: '',
      text: [],
      update: true,
      titleName: '住院病案',
      pacsDetail: {},
      // 病程记录详情
      caseRecodeInfo: {
        is_format: 1,
      },
      surgeryData: {
        mzfj: [],
        ssqk: [],
        sscxsj: [],
        sslb: [],
        is_format: 0,
      },
      outHospitalRecordData: {
        name: {},
        ry_time: {},
        sex: {},
        age: {},
        cy_time: {},
        zyts: {},
        ryqk: {},
        cbzd: {},
        zljg: {},
        cyqk: {},
        cyzd: {},
        cyyz: {},
      },
      dataObj: [],
      results: {
        data: {}
      },
    };
  },
  computed: {
    bcjlLiIds() {
      // 病程记录子项数据
      const arr = Object.values(this.treeList).filter(item => item.bllb === 294);
      const liIds = [];
      if (arr.length) {
        if (arr[0].list) {
          for (let i = 0; i < arr[0].list.length; i++) {
            liIds.push(arr[0].list[i].blbh);
          }
        }
      }
      return liIds;
    },
    shoushuLiIds() {
      // 病程记录子项数据
      const arr = Object.values(this.treeList).filter(item => item.bllb === 303);
      const liIds = [];
      if (arr.length) {
        if (arr[0].list) {
          for (let i = 0; i < arr[0].list.length; i++) {
            liIds.push(arr[0].list[i].blbh);
          }
        }
      }
      return liIds;
    },
    blname_title() {
      let title;
      const type = this.surgeryData.type;
      if (type === 1) {
        title = '手术风险评估表';
      } else if (type === 2) {
        title = '手术安全核查表';
      } else if (type === 3) {
        title = '手术同意书';
      } else if (type === 4) {
        title = '手术记录';
      }
      return title;
    },
  },
  watch: {},
  created(){
    this.type_v = this.$route.query.type_v;
  },
  mounted() {
    let v = 
    this.valData = this.storageGet('getData');
    if (this.valData) {
      this.funQuery();
      this.getCaseQualityResults();
    }
    this.getTree();
  },

  methods: {
    // 获取新病案指控结果
    getCaseQualityResults() {
      const params = {
        id: Number(this.valData),
      };
      if(this.type_v == 'v2'){
        // (事中)
        this.$axios2.post('/get_case_quality_v2', params).then(res => {
          this.results = res.data;
        });
      }else{
        this.$axios2.post('/get_case_quality', params).then(res => {
          this.results = res.data;
        });
      }

    },
    reload() {
      // 移除组件
      this.update = false;
      // 在组件移除后，重新渲染组件
      // this.$nextTick可实现在DOM 状态更新后，执行传入的方法。
      this.$nextTick(() => {
        this.update = true;
      });
    },
    funEdit() {
      this.ifFile = true;
      this.$message('errer:功能待开发');
    },
    getback() {
      this.$router.go(-1);
    },
    /**
     * 跳转对应病历首页
     */
    getBlankIndexss(item) {
      this.$refs.main.getBlankIndex(item);
    },
    funQuery() {
      const params = {
        id: this.valData,
      };
      if (this.$route.query.status) {
        params.is_tm = 1;
      }
      this.$axios.post('/medical_record', params).then(res => {
        this.mainHomeData = res.data;
      });
    },

    getTree() {
      let that = this;
      let pramse = {
        id: this.valData,
      };
      this.$axios.post('/getTree', pramse).then(res => {
        that.treeList = res.data;
      });
    },
    clickTree(b, n, item) {
      this.titleName = n;
      this.parentType = b;
      let that = this;
      // 判断点击的
      if (event.target.outerText == '长期医嘱' || event.target.outerText == '临时医嘱') {
        that.is_active = event.target.outerText;
      } else if (b == 2000002) {
        that.is_active = event.target.id;
      } else if (b == 294) {
        that.is_active = event.target.id;
      } else if (b == 303) {
        that.is_active = event.target.id;
      } else {
        that.is_active = b;
      }
      that.name_title = n;
      if (b != 0 && b != 292 && b != 1) {
        const params = {
          MED_REC_ID: that.valData,
          bllb: b,
        };
        if (this.$route.query.status) {
          params.is_tm = 1;
        }
        that.$axios.post('/getAllCase', params).then(res => {
          that.text = res.data;
          that.dataObj = res.data;
          that.reload();
        });
      } else if (b == 292) {
        // 获取详情
        const params = {
          id: this.valData,
          bllb: b,
        };
        if (this.$route.query.status) {
          params.is_tm = '1';
        }
        that.$axios2.post('/get_case_platform', params).then(res => {
          this.admissionRecord = res.data;
        });
      } else if (b == 1) {
        // 获取详情
        const params = {
          id: this.valData,
          bllb: b,
        };
        if (this.$route.query.status) {
          params.is_tm = 1;
        }
        that.$axios2.post('/get_case_platform', params).then(res => {
          this.outHospitalRecordData = res.data;
        });
      }
      if (that.is_active == '长期医嘱') {
        // 长期医嘱
        const params = {
          AAA28: that.valData,
        };
        if (this.$route.query.status) {
          params.is_tm = 1;
        }
        that.$axios.post('/long', params).then(res => {
          this.longAdvice = res.data;
        });
      }
      if (that.is_active == '临时医嘱') {
        // 临时医嘱
        const params = {
          AAA28: that.valData,
        };
        if (this.$route.query.status) {
          params.is_tm = 1;
        }
        that.$axios.post('/temporary', params).then(res => {
          this.happensAdvice = res.data;
        });
      }
      if (that.parentType == '2000002' && that.is_active != '') {
        // 报告单 相关
        let parm = {
          type: Number(that.is_active),
        };
        if (this.$route.query.status) {
          parm.is_tm = 1;
        }
        let treeListArr = Object.values(that.treeList);
        treeListArr.forEach((item, index) => {
          if (item.bllb == 2000002) {
            parm.zyh = Number(item.list[0].ZYH);
          }
        });

        that.$axios.post('/get_pacs_data', parm).then(res => {
          this.pacsDetail = res.data;
        });
      }

      // if (that.is_active === '12') {
      //   // 报告单 相关
      //   let parm = { id: this.valData };
      //   that.$axios.post('/get_jmgs_detail', parm).then(res => {
      //     this.pacsDetail = res.data;
      //   });
      // }
      // 病程记录
      if (item.bllb === 294) {
        if (that.is_active) {
          // 请求前先重置之前的数据
          that.caseRecodeInfo = {};
          let parm = { blbh: that.is_active };
          if (this.$route.query.status) {
            parm.is_tm = 1;
          }
          that.$axios.post('/get_bc_data', parm).then(res => {
            that.caseRecodeInfo = res.data[0].bc_data;
            that.caseRecodeInfo.is_format = res.data[0].is_format;
          });
        }
      }
      // 手术记录
      if (item.bllb === 303) {
        if (that.is_active) {
          // 请求前先重置之前的数据
          that.surgeryData = {};
          let parm = { blbh: that.is_active };
          if (this.$route.query.status) {
            parm.is_tm = 1;
          }
          that.$axios.post('/get_surgery_data', parm).then(res => {
            that.surgeryData = res.data[0].surgery_data;
            that.surgeryData.is_format = res.data[0].is_format;
          });
        }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
#MyDiv {
  margin: 0;
  padding: 0 !important;
}
.nocopy {
  user-select: none;
}
.header {
  margin: 10px 20px;
  text-align: right;
  display: flex;
  justify-content: flex-end;
}
.cont_container {
  display: flex;
  justify-content: center;
}
.cont-left-tiem {
  width: 250px;
  min-height: 650px;
  height: calc(100vh - 130px);
  overflow-y: scroll;
  background: #ffffff;
}
.cont-left-file {
  flex: 1;
  min-height: 650px;
  margin: 0 5px;
  height: calc(100vh - 130px);
  overflow-y: scroll;
  background: #ffffff;
  border: 1px solid #e2e2e2;
  padding: 10px;
}
.li-router {
  display: inline-block;
  width: 100%;
  height: 100%;
}
.li-left-item {
  line-height: 56px;
  font-size: 14px;
  color: #303133;
  padding: 0 20px;
  cursor: pointer;
  -webkit-transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
.li-left-itemyz {
  line-height: 56px;
  font-size: 14px;
  color: #303133;
  padding-left: 20px;

  -webkit-transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  .li-left-item-li {
    width: 100%;
    line-height: 36px;
    padding: 0 20px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .li-left-item-li:hover {
    outline: 0;
    background-color: #ecf5ff;
  }
}
.li-left-item:focus,
.li-left-item:hover {
  outline: 0;
  background-color: #ecf5ff;
}

.is-active {
  color: #409eff;
}
</style>
<style>
/*  ================================== 文本形式样式 ↓ ======================== */
.refachInput span {
  height: auto;
  line-height: 1;
  padding: 10px 0;
}
.refachInput span.refachInput-text {
  padding-left: 12px;
}
.el-row--flex.is-justify-space-around {
  justify-content: flex-start;
}
.member-infobox {
  width: 100%;
}
.member-infobox .info-box-1 {
  /* display: flex;
    flex-wrap: wrap; */
  margin-top: 20px;
}
.infoBox-items {
  width: auto;
  display: flex;
  align-items: center;
  padding: 8px 0;
}
.padding-left20 {
  padding-left: 20px;
}
.padding-right20 {
  padding-right: 20px;
}
.infoBox-title {
  color: #333;
  font-size: 12px;
  font-weight: bold;
}
.infoBox-items-text {
  color: #666;
  font-size: 12px;
  padding-left: 5px;
  padding-right: 20px;
}
.title-ff0000 {
  color: #ff0000;
}
/* 高亮 */
.choose-twinkle {
  font-size: 20px;
  color: red;
  font-weight: 600;
  background: yellow;
}
.table-value-look {
  padding-left: 12px;
  color: #ff0000;
  cursor: pointer;
}
</style>
