<template>
  <div class="component-container searchContent">
    <el-table
      ref="multipleTable"
      v-loading="dataListLoading"
      :data="dataList"
      @select="selectHandle"
      @select-all="selectHandle"
    >
      <el-table-column type="selection" width="55" :selectable="selectable" />
      <!-- 行展开 -->
      <el-table-column type="expand">
        <template slot-scope="scope">
          <el-form label-width="90px" class="expand-form">
            <!-- 摘要 -->
            <el-form-item :label="'主要内容'">
              <div class="overViewHtml" v-html="scope.row.allHighlight" />
            </el-form-item>
            <!-- 检查项目 -->
            <el-form-item :label="'检查计次'">
              <div class="exam">
                <p v-for="(item, index) in getExamItem(scope.row.statsExamItem)" :key="index">
                  <span class="exam-name" :title="item.name">{{ item.name }}</span>
                  <span class="exam-num">{{ item.num }}次</span>
                </p>
              </div>
            </el-form-item>
            <template v-if="visibleChart">
              <!-- 折线图 -->
              <el-form-item :label="'折线图'">
                <el-row :gutter="20">
                  <el-col :span="12">
                    <echarts-line-kpi :chart-data="scope.row.yanya" :title="'眼压'" />
                  </el-col>
                  <el-col :span="12">
                    <echarts-line-kpi-va :chart-data="scope.row.vision" :title="'视力'" />
                  </el-col>
                </el-row>
              </el-form-item>
            </template>
          </el-form>
        </template>
      </el-table-column>
      <!-- 姓名 -->
      <el-table-column :label="'姓名'" header-align="center" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ (scope.row.esPatientInfo?scope.row.esPatientInfo.patientName:'') | f_desensitize_name }}
        </template>
      </el-table-column>
      <!-- 性别 -->
      <el-table-column :label="'性别'" header-align="center" align="center">
        <template slot-scope="scope">
          {{ (scope.row.esPatientInfo?scope.row.esPatientInfo.patientSex:'') | f_sex }}
        </template>
      </el-table-column>
      <!-- 年龄 -->
      <el-table-column :label="'年龄'" header-align="center" align="center">
        <template slot-scope="scope">
          {{ (scope.row.esPatientInfo?scope.row.esPatientInfo.patientAge:'')  }}
        </template>
      </el-table-column>
      <!-- 身份证号 -->
      <el-table-column prop="patientIdNumber" :label="'身份证号'" header-align="center" align="center">
        <template slot-scope="scope">
          {{ (scope.row.id) | f_desensitize_idNumber }}
        </template>
      </el-table-column>
      <!-- 检索内容 -->
      <!-- <el-table-column prop="patientIdNumber" :label="'检索内容'" header-align="center" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <p v-html="scope.row.allHighlight" />
        </template>
      </el-table-column> -->
      <!-- 操作 -->
      <el-table-column label="操作" header-align="center" align="center" width="120">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showDetail(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import echartsLineKpi from '@/components/echarts/line-kpi'
import echartsLineKpiVa from '@/components/echarts/line-kpi-va'
import { findItem } from '@/utils/tree'

export default {
  components: {
    echartsLineKpi,
    echartsLineKpiVa
  },
  props: {
    dataListLoading: { type: Boolean, default: false },
    dataList: { type: Array, default: () => [] },
    visibleChart: { type: Boolean, default: false },
    selectDisableIdList: { type: Array, default: () => [] },
    projectId: { type: String, default: '' }
  },
  data() {
    return {
      selectIdList: [],
      selectList: [],
      patientId: ''
    }
  },
  mounted() {
    console.log(this.dataList)
  },
  methods: {
    getExamItem(obj) {
      const result = []
      for (const key in obj) {
        if (obj[key]) {
          const dictItem = findItem(window.SITE_CONFIG['dict_colSearch'], key, 'name', 'children')
          console.log(window.SITE_CONFIG['dict_colSearch'])
          result.push({ id: key, name: dictItem ? dictItem.label : '', num: obj[key] })
        }
      }
      return result
    },
    selectHandle(selection, row) {
      this.selectIdList = []
      this.selectList = selection
      selection.forEach(item => {
        this.selectIdList.push(item.id)
      })
      this.$emit('vmSelectIdList', this.selectIdList)
      this.$emit('vmSelectList', this.selectList)
    },
    clearSelect() {
      console.log(1)
      this.selectIdList = []
      this.selectList = []
      this.$refs.multipleTable.clearSelection()
    },
    selectable(row, index) {
      return this.selectDisableIdList.indexOf(row.id) < 0
    },
    // 查看详情
    showDetail(scopeRow) {
      this.$emit('viewDetail', scopeRow.esPatientInfo.patientId)
      // this.patientId = scopeRow.patientId
      const mzName = scopeRow.mzDoctorName ? scopeRow.mzDoctorName : ''
      const jzNumber = scopeRow.jzNumber ? scopeRow.jzNumber : ''
      window.localStorage.setItem('mzDoctorName', mzName)
      window.localStorage.setItem('jzNumber', jzNumber)
    }
  }
}
</script>

<style lang="scss" scoped>
.searchContent {
  // 搜索内容
  .overViewHtml {
    font-size: 14px;
    line-height: normal;
    white-space: pre-wrap;
  }

  .exam {
    display: flex;
    flex-wrap: wrap;
    padding-bottom: 10px;
    p {
      display: flex;
      flex-wrap: nowrap;
      height: 32px;
      line-height: 32px;
      width: 18%;
      background-color: #eee;
      padding: 0 10px;
      margin: 6px;
      span {
        display: block;
        // flex: 1;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        text-align: center;
      }

      $width_num: 60px;
      .exam-name {
        width: calc(100% - #{$width_num});
      }
      .exam-num {
        width: $width_num;
        color: #0072f9;
      }
    }
  }
}

::v-deep .el-table__expanded-cell {
  padding: 5px 10px;
  background-color: #f5f7fa;
}

.dialog {
  ::v-deep .el-dialog__header {
    padding: 10px 20px;
    background: #696969;

    .el-dialog__title {
      color: #fff;
    }

    .el-dialog__headerbtn {
      top: 10px;
      font-size: 20px;

      .el-dialog__close {
        color: #fff;
        font-weight: bolder;
      }
    }
  }
  ::v-deep .el-dialog__body {
    min-height: calc(100% - 60px);
    background: #f5f5f5;
  }
}
</style>

