<template>
  <div class="specialBox">
    <div class="examineBox">
      <i class="el-icon-refresh refresh" @click="getSpecialItem" />
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;margin-top: 16px"
        @row-click="handleData"
      >
        <el-table-column
          prop="examTime"
          label="时间"
          align="center"
          width="165"
        />
        <el-table-column
          prop="examineItem"
          label="检查项目"
          align="center"
          width="195"
        />
        <el-table-column
          label="检查结果"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.native.stop="handleRecord()">
              浏览
            </el-button>
            <!--            <el-button type="text" size="small" @click.native.stop="handleRecord(scope.row)">-->
            <!--              所有报告-->
            <!--            </el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="examineData">
      <i class="el-icon-refresh refresh-r" @click="getItemData" />
      <div style="display: flex;justify-content: space-between">
        <span style="font-size: 16px;font-weight: 500;color: rgba(0, 0, 0, 0.88);margin-top: 4px">提取数据</span>
        <div v-if="!onlyRead" size="small" style="display:inline-block;margin-left:10px;width: 32px;height: 32px;line-height:32px;text-align:center;background-color: #1e79ff;border-radius: 4px;vertical-align: middle" @click="addDataList">
          <img :src="require('@/assets/img/data.png')" alt="" style="width: 17px;height: 16px;margin-bottom: 4px">
        </div>
      </div>
      <el-table
        v-loading="loadingFlag"
        class="tableBox"
        :data="extractData"
        style="width: 100%;margin-top: 16px"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          prop="name"
          label="名称"
          width="90"
        />
        <el-table-column
          prop="od"
          label="OD"
        />
        <el-table-column
          prop="os"
          label="OS"
        />
        <el-table-column
          prop="ou"
          label="OU"
          width="80"
        />
      </el-table>
    </div>
    <!-- 图像与报告 -->
    <keep-alive>
      <el-dialog title="" class="detail-view" :fullscreen="true" :visible.sync="isActive" append-to-body @close="closePacs">
        <imgRecord :patient-info="patientBaseData" />
      </el-dialog>
    </keep-alive>
  </div>
</template>
<script>
import imgRecord from '@/components/360View/img-reccrd'
import eventBus from '@/page-subspecialty/utils/eventBus'
const Base64 = require('js-base64').Base64
export default {
  components: {
    imgRecord
  },
  mixins: [],
  props: {
    patientIdNumber: {
      type: String,
      default: ''
    },
    patientId: {
      type: String,
      default: ''
    },
    onlyRead: {
      type: Boolean,
      default: false
    }
  },
  inject: ['refresh'],
  data() {
    return {
      date: '',
      examNo: '',
      examineItem: '',
      employeeId: '',
      multipleSelection: [],
      tableData: [],
      extractData: [],
      patientBaseData: {},
      loading: false,
      loadingFlag: false,
      isActive: false
    }
  },
  mounted() {
    const user = JSON.parse(window.localStorage.getItem('qg-userData'))
    this.employeeId = user.employeeId
    this.getPatientData()
    this.getSpecialItem()
  },
  methods: {
    // 获取特殊检查项
    async getSpecialItem() {
      this.loading = true
      const { data: res } = await this.$http.get('/patient/view/getExamineItem', {
        params: {
          patientId: this.patientId
        }
      })
      if (res.code === 0) {
        this.loading = false
        this.tableData = res.data || []
        if (res.data.length) {
          this.examNo = res.data[0].examNo
          this.examineItem = res.data[0].examineItem
          await this.getItemData()
        }
      } else {
        this.tableData = []
        this.$message.error(res.msg)
      }
    },
    async getItemData() {
      this.loadingFlag = true
      const { data: res } = await this.$http.get('/patient/view/getExtractData', {
        params: {
          patientId: this.patientId,
          examNo: this.examNo,
          examineItem: this.examineItem
        }
      })
      if (res.code === 0) {
        this.loadingFlag = false
        this.extractData = res.data || []
      } else {
        this.extractData = []
        this.loadingFlag = false
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 根据id获取患者信息--中间上侧患者信息
    async getPatientData() {
      const { data: res } = await this.$http.get(
        '/patient/view/getPatientData',
        {
          params: {
            patientId: this.patientId
          }
        }
      )
      if (res.code === 0) {
        this.patientBaseData = res.data ? res.data : {}
      } else {
        this.$message.error(res.msg)
      }
    },
    // 点击行展示提取数据
    handleData(item) {
      this.examNo = item.examNo
      this.examineItem = item.examineItem
      this.getItemData()
    },
    handleRecord() {
      // const patientInfo = {
      //   examDate: item.examTime ? item.examTime.substring(0, 11) : '',
      //   itemCode: item.examineItem,
      //   examNo: item.examNo,
      //   patientId: this.patientId
      // }
      // const { href } = this.$router.resolve({
      //   name: 'pacs',
      //   query: {
      //     info: this.$Base64.encode(JSON.stringify(patientInfo))
      //   }
      // })
      // const baseUrl = 'http://z1.huimucloud.com:8085'
      // const baseUrl = 'http://10.80.5.32:8026'
      const baseUrl = 'http://192.168.0.85:8001'
      const href = `${baseUrl}/EXAMINE_Report/InterFace?PatID=${this.patientId}&DoctorID=${this.employeeId}&PatIdKey=&ExamNo=`
      window.open(href, '_blank')
    },
    // 关闭360弹框
    closePacs() {
      this.isActive = false
    },
    // 添加数据集
    addDataList() {
      const data = this.multipleSelection
      if (!data.length) return this.$message.warning('请选择数据!')
      data.forEach(item => {
        item.id = item.name
        item.odValue = item.od
        item.osValue = item.os
      })
      eventBus.$emit('sendForData', data)
    }
  }
}
</script>
<style lang="scss" scoped>
.specialBox{
  width: 100%;
  height: 100%;
  display: flex;
  box-sizing: border-box;
  overflow-y: auto;
  .examineBox{
    height: 100%;
    overflow: auto;
    position: relative;

    .refresh{
      position: absolute;
      right: 18px;
      top: 35px;
      z-index: 999;
      cursor: pointer;
      color: #409EFF;
    }
  }
  .examineData{
    padding: 16px 0 0 16px;
    height: 100%;
    flex: 1;
    overflow-y: auto;
    box-sizing: border-box;
    position: relative;

    .refresh-r{
      position: absolute;
      left: 90px;
      top: 25px;
      z-index: 999;
      cursor: pointer;
      color: #409EFF;
    }
  }
  .header{
    width: 100%;
    display: flex;
    justify-content: space-between;
    height: 49px;
    line-height: 49px;
    padding: 0px 16px;
    box-sizing: border-box;
    margin-bottom: 32px;
    border: 1px solid rgba(0, 0, 0, 0.06);
  }
  .content{
    width: 100%;
    //display: flex;
    //justify-content: space-between;
    box-sizing: border-box;

  }
  .lineBox{
    //width: 48%;
    width: 100%;
    height: 260px;
    padding: 16px;
    box-sizing: border-box;
    border: 1px solid rgba(0, 0, 0, 0.06);
    margin-bottom: 32px;
  }
  .scroll-echearts {
    padding: 5px 0;
    flex: 1;
    margin-bottom: 16px;
    //background: #171515;
    border-radius: 4px;
  }
  .eyeBox{
    width: 480px;
    height: 180px;
    display: flex;
    margin-left: 32px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    .eye{
      width: 50%;
      display: flex;
      flex-direction: column;

      div{
        height: 45px;
        line-height: 45px;
        text-align: center;
      }
      .info{
        display: flex;
        justify-content: space-between;
        padding: 0 14px;
        border-top: 1px solid rgba(0, 0, 0, 0.06);
      }
    }
    .el{
      background: rgba(0, 0, 0, 0.04);
    }
  }
  .mr30{
    margin-right: 30px;
  }
}
</style>
<style lang="scss">
.specialBox{
  .el-table th{
    background-color: #FAFAFA;
  }
}
</style>
