<template>
  <div>
    <div class="container-title">
      <span class="line"></span>
      <span class="title">应急队伍</span>
    </div>
    <div class="organization-container">
      <el-tabs v-model="activeTeamId" tab-position="left" @tab-change="fetchTeamMembers">
        <el-tab-pane v-for="team in teamList" :key="team.id" :label="team.teamName" :name="team.id">
          <div v-if="teamMembers.length === 0" class="no-team-member">暂无人员信息</div>
          <div class="team-member" v-for="member in teamMembers" :key="member.id">
            <div class="member-info">
              <div class="member-name">{{ member.realname }}</div>
              <div class="mobile">{{ member.mobile }}</div>
            </div>
            <div class="member-job">{{ member.title }}</div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import {
    QueryTeamListRes,
    getEmergencyTeamList,
    QueryTeamPersonnelListRes,
    getEmergencyTeamMemberList,
  } from '@/api/command-center';

  const activeTeamId = ref<number>();
  const teamList = ref<QueryTeamListRes[]>([]);
  const teamMembers = ref<QueryTeamPersonnelListRes[]>([]);

  const fetchTeamMembers = async () => {
    if (!activeTeamId.value) return;
    teamMembers.value = await getEmergencyTeamMemberList(activeTeamId.value);
  };

  onMounted(async () => {
    teamList.value = await getEmergencyTeamList();
    if (teamList.value.length > 0) {
      activeTeamId.value = teamList.value[0].id;
      fetchTeamMembers();
    }
  });
</script>

<style scoped lang="scss">
  .container-title {
    height: 24px;
    display: flex;
    align-items: center;
    margin: 10px 0;
    font-weight: 500;
    font-size: 16px;
    color: #000000;

    .line {
      width: 3px;
      height: 16px;
      background: #1777ff;
      margin-right: 10px;
    }

    .title {
      margin-right: 12px;
    }
  }

  .organization-container {
    height: calc(100% - 49px);
    margin-top: 15px;
    padding-bottom: 10px;

    .team-member {
      width: 100%;
      height: 51px;
      border-bottom: 1px solid rgba(151, 151, 151, 0.13);
      padding: 0 10px 0 0;
      margin-bottom: 10px;

      .member-info {
        display: flex;
        justify-content: space-between;
        font-weight: 500;
        font-size: 16px;
        color: #333333;

        .member-name {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .mobile {
          font-weight: 400;
        }
      }

      .member-job {
        font-weight: 400;
        font-size: 14px;
        color: #666666;
        margin-top: 5px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .no-team-member {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }

  :deep(.el-tabs) {
    width: 100%;
    height: 100%;

    .el-tabs__header {
      width: 130px;
      border-right: 1px solid #e9e9e9;
    }

    .el-tabs__nav-wrap {
      width: 100%;
    }

    .el-tabs__nav {
      white-space: unset;
    }

    .el-tabs__item {
      height: auto;
      font-weight: 400;
      font-size: 14px;
      color: rgba(0, 0, 0, 0.65);
      padding: 10px;
    }

    .el-tabs__item.is-active {
      font-weight: 500;
      font-size: 14px;
      color: #1890ff;
      background: #e7f7ff;
    }

    .el-tabs__content {
      overflow: auto;
    }
  }
</style>
