<!-- 实验室与人员匹配 -->
<template>
  <div class="lab-person-card">
    <div class="card-header">
      <span class="card-title">实验室与人员匹配</span>
      <div class="header-right">
        <p class="export-btn export-btn--blue" @click="() => {}">
          <i class="el-icon-download"></i> 导出各学院数据
        </p>
        <p class="export-btn export-btn--green" @click="() => {}">
          <i class="el-icon-download"></i> 导出实验室人员明细
        </p>
      </div>
    </div>

    <!-- 柱状图 -->
    <div class="chart-wrap">
      <div class="bar-chart">
        <div class="y-axis">
          <span v-for="y in yLabels" :key="y">{{ y }}</span>
        </div>
        <div class="bars-container">
          <div v-for="(g, i) in chartData" :key="i" class="bar-group">
            <div class="bar-value">{{ g.value }}</div>
            <div class="bar-body" :style="{height: scaleH(g.value) + 'px', background: g.color}"></div>
            <div class="bar-label">{{ g.label }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 筛选 -->
    <div class="filter-row">
      <el-select v-model="filterData.college" placeholder="筛选学院" size="small" clearable style="width:130px">
        <el-option v-for="c in filterData.colleges" :key="c" :label="c" :value="c" />
      </el-select>
      <el-select v-model="filterData.level" placeholder="实验室等级" size="small" clearable style="width:120px">
        <el-option label="Ⅰ级" value="1" />
        <el-option label="Ⅱ级" value="2" />
        <el-option label="Ⅲ级" value="3" />
        <el-option label="Ⅳ级" value="4" />
      </el-select>
    </div>

    <!-- 表格 -->
    <el-table :data="tableData" border size="small">
      <el-table-column prop="college" label="学院" min-width="140" />
      <el-table-column prop="l1" label="Ⅰ级人数" width="100" align="center" />
      <el-table-column prop="l2" label="Ⅱ级人数" width="100" align="center" />
      <el-table-column prop="l3" label="Ⅲ级人数" width="100" align="center" />
      <el-table-column prop="l4" label="Ⅳ级人数" width="100" align="center" />
      <el-table-column prop="total" label="总人数" width="100" align="center">
        <template slot-scope="scope">
          <span class="total-link">{{ scope.row.total }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'LabPersonMatch',
  data() {
    return {
      filterData: {
        college: '',
        level: '',
        colleges: ['化学与化工学院','生命科学学院','物理学院','电气工程学院','材料科学学院','机械工程学院','自动化学院','资源环境学院'],
      },
      yLabels: [600, 500, 400, 300, 200, 100, 0],
      chartData: [
        { label: 'Ⅰ级（重大风险）', value: 156, color: '#f56c6c' },
        { label: 'Ⅱ级（高风险）',   value: 342, color: '#f59e42' },
        { label: 'Ⅲ级（中风险）',   value: 528, color: '#f59e42' },
        { label: 'Ⅳ级（低风险）',   value: 215, color: '#6ea8f7' },
      ],
      tableData: [
        { college: '化学与化工学院', l1: 18, l2: 45, l3: 62, l4: 25, total: 150 },
        { college: '生命科学学院',   l1: 32, l2: 38, l3: 48, l4: 20, total: 138 },
        { college: '物理学院',       l1: 25, l2: 30, l3: 42, l4: 18, total: 115 },
        { college: '电气工程学院',   l1: 15, l2: 42, l3: 58, l4: 30, total: 145 },
        { college: '材料科学学院',   l1: 20, l2: 35, l3: 50, l4: 22, total: 127 },
        { college: '机械工程学院',   l1: 12, l2: 38, l3: 55, l4: 28, total: 133 },
        { college: '自动化学院',     l1: 18, l2: 32, l3: 45, l4: 20, total: 115 },
        { college: '资源环境学院',   l1: 16, l2: 28, l3: 40, l4: 18, total: 102 },
      ]
    }
  },
  methods: {
    scaleH(val) {
      return Math.round(val / 600 * 240)
    }
  }
}
</script>

<style scoped lang="scss">
.lab-person-card {
  background: #fff;
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    .card-title { font-size: 16px; font-weight: 700; color: #222; }
    .header-right { display: flex; gap: 20px; }
  }

  .export-btn {
    display: inline-block;
    padding: 0 16px;
    height: 40px;
    line-height: 40px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    color: #fff;

    &--blue  { background-color: #0183fa; border: 1px solid #0183fa; }
    &--green { background-color: #00B176; border: 1px solid #00B176; }
  }

  .chart-wrap {
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 20px 20px 30px;
    margin-bottom: 16px;

    .bar-chart {
      display: flex;
      gap: 8px;
      align-items: flex-end;
      height: 280px;

      .y-axis {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        font-size: 11px;
        color: #aaa;
        height: 260px;
        min-width: 32px;
        text-align: right;
      }

      .bars-container {
        flex: 1;
        display: flex;
        align-items: flex-end;
        justify-content: space-around;
        height: 260px;
        border-bottom: 1px solid #e8e8e8;
        padding: 0 40px 24px;
        position: relative;

        &::before {
          content: '';
          position: absolute;
          left: 0; right: 0; top: 0; bottom: 24px;
          background: repeating-linear-gradient(to bottom, #f5f5f5 0, #f5f5f5 1px, transparent 1px, transparent calc(100% / 6));
          pointer-events: none;
        }

        .bar-group {
          display: flex;
          flex-direction: column;
          align-items: center;
          position: relative;
          z-index: 1;

          .bar-value {
            font-size: 12px;
            color: #333;
            font-weight: 600;
            margin-bottom: 4px;
          }

          .bar-body {
            width: 60px;
            border-radius: 2px 2px 0 0;
          }

          .bar-label {
            position: absolute;
            bottom: -20px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 11px;
            color: #555;
            white-space: nowrap;
          }
        }
      }
    }
  }

  .filter-row {
    display: flex;
    gap: 20px;
    margin-bottom: 12px;
  }

  .total-link { color: #409eff; }
}
</style>
