<template>
  <div class="caseQualityBox">
    <div class="score-box">
      {{ data.score }}分
      <span class="level">{{ scoreLevel }}</span>
    </div>
    <el-table
      :data="tableData"
      default-expand-all
      style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-card v-for="(item, index) of props.row.children" :key="index" class="box-card" shadow="hover">
            <el-row>
              <el-col :span="24">
                <el-descriptions title="" :column="1" direction="vertical">
                  <el-descriptions-item label="质控项目">
                    <el-tag>{{ item.error_field }}</el-tag>
                    <span class="koufen">-{{ item.score }}分</span>
                  </el-descriptions-item>
                  <el-descriptions-item label="错误描述">{{ item.notice }}</el-descriptions-item>
                  <el-descriptions-item label="质控依据">
                    <div v-for="(yItem, yIndex) of item.basis" :key="yIndex" style="margin-bottom: 10px;">
                      <div v-for="(cItem, cIndex) of yItem" :key="cIndex">{{ cItem }}</div>
                    </div>
                  </el-descriptions-item>
              </el-descriptions>
              </el-col>
            </el-row>
          </el-card>
        </template>
      </el-table-column>
      <el-table-column
        label=""
        prop="category">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  export default {
    props: {
      data: {
        type: Object,
        default() {
          return {
            score: 0,
            data: {}
          }
        }
      }
    },
    computed: {
      tableData() {
        let arr = []
        const keys = Object.keys(this.data.data)
        for(let i=0; i<keys.length; i++) {
          let obj = {
            category: keys[i],
            children: this.data.data[keys[i]]
          }
          arr.push(obj)
        }
        return arr
      },
      scoreLevel() {
        /**
         * 甲＞90分
         * 乙75-90分
         * 丙＜75分
         * */ 
        let str
        const { score } = this.data
        if (score > 90) {
          str = '甲'
        } else if (score < 75) {
          str = '丙'
        } else {
          str = '乙'
        }
        return str
      }
    }
  }
</script>

<style lang="scss" scoped>
.caseQualityBox {
  width: 340px;
  height: 820px;
  overflow-x: hidden;
  overflow-y: scroll;
  background: #ffffff;
  border: 1px solid #e2e2e2;
  box-sizing: border-box;
  padding: 20px;
  ::v-deep .el-descriptions-item__container .el-descriptions-item__content {
    display: block;
  }
  ::v-deep .el-descriptions-item__label:not(.is-bordered-label) {
    font-weight: 600;
    display: inline-table;
  }
  ::v-deep .el-descriptions-item__content {
    padding-top: 12px;
  }
  .box-card {
    margin-bottom: 10px;
  }
  .score-box {
    width: 100%;
    height: 120px;
    line-height: 120px;
    font-size: 32px;
    font-weight: bold;
    text-align: center;
    border-radius: 5px;
    border: 1px solid #dddddd;
    position: relative;
    overflow: hidden;
    &::before {
      content: "";
      position: absolute;
      width: 200px;
      height: 200px;
      top: -120px;
      right: -160px;
      z-index: 1;
      background-color: red;
      transform: rotate(45deg);
    }
    .level {
      position: absolute;
      top: 5px;
      right: 10px;
      z-index: 2;
      line-height: 30px;
      color: #ffffff;
      font-size: 16px;
    }
  }
}
.koufen {
  color: red;
  float: right;
  line-height: 32px;
  font-size: 16px;
  font-weight: bold;
}
</style>