<template>
  <div class="container">
    <!-- 导航栏 -->
    <div class="nav-bar">
      <div class="back-btn" @click="$router.back()">
        <i class="arrow-left"></i>
      </div>
      <div class="title">团队明细</div>
    </div>

    <div class="content">
      <!-- 切换按钮组 -->
      <div class="tab-group">
        <div 
          class="tab-item" 
          :class="{ active: currentType === 1 }"
          @click="switchType(1)"
        >一代</div>
        <div 
          class="tab-item" 
          :class="{ active: currentType === 2 }"
          @click="switchType(2)"
        >二代</div>
        <div 
          class="tab-item" 
          :class="{ active: currentType === 3 }"
          @click="switchType(3)"
        >三代</div>
      </div>

      <!-- 统计信息 -->
      <div class="stats-bar">
        <div class="stats-item">总人数：{{ teamList.length || 0 }}人</div>
        <div class="stats-item">有效总人数：{{ teamInfo.yxuser || 0 }}人</div>
      </div>

      <!-- 团队列表 -->
      <div class="team-list">
        <div v-for="item in teamList" :key="item.userId" class="member-card">
          <div style="display: flex; align-items: center; margin-bottom: 8px;">
            <span style="color: #888;">{{ item.id }}</span>
            <span style="background: #e6b7e6; color: #fff; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; margin-right: 10px;margin-left: 10px;">{{ item.level }}</span>
            <span style="font-weight: bold; margin-right: 10px;">{{ item.mobile }}</span>
          </div>
          <div style="margin-bottom: 4px;">直推人数 {{ item.zhituicount }}人</div>
          <div>邀请时间 {{ item.createtime }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getMyTeam } from '@/api/profile';

export default {
  name: 'TeamDetail',
  data() {
    return {
      currentType: 1,
      teamInfo: {
        yxuser: 0
      },
      teamList: []
    }
  },
  created() {
    this.getTeamInfo();
  },
  methods: {
    async getTeamInfo() {
      try {
        const res = await getMyTeam(this.currentType);
        if (res && res.data) {
          this.teamInfo = {
            yxuser: res.data.yxuser || 0
          };
          this.teamList = res.data.list || [];
        }
      } catch (error) {
        console.error('获取团队信息失败:', error);
        this.teamInfo = {
          yxuser: 0
        };
        this.teamList = [];
      }
    },
    switchType(type) {
      this.currentType = type;
      this.getTeamInfo();
    }
  }
}
</script>

<style scoped>
.container {
  min-height: 100vh;
  background: #f5f5f5;
}

.nav-bar {
  height: 44px;
  background-color: #ed4b39;
  color: #fff;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
}

.back-btn {
  width: 24px;
  height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.arrow-left {
  width: 12px;
  height: 12px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

.title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  font-weight: 500;
}

.content {
  padding: 15px;
}

.tab-group {
  width: 96%;
  height: 40px;
  background-color: #f8f8f8;
  display: flex;
  justify-content: space-between;
  line-height: 40px;
  text-align: center;
  margin: 20px auto;
  border-radius: 2px;
}

.tab-item {
  width: 33.33%;
  cursor: pointer;
  color: #333;
  transition: all 0.3s;
}

.tab-item:first-child {
  border-radius: 2px 0 0 2px;
}

.tab-item:last-child {
  border-radius: 0 2px 2px 0;
}

.tab-item.active {
  background: #2196f3;
  color: #fff;
}

.stats-bar {
  width: 96%;
  height: 40px;
  background-color: #f8f8f8;
  display: flex;
  justify-content: space-between;
  line-height: 40px;
  text-align: center;
  margin: 10px auto;
  border-radius: 2px;
}

.stats-item {
  width: 50%;
  font-size: 14px;
  color: #333;
}

.stats-item:first-child {
  border-right: 0.5px solid #ccc;
}

.team-list {
  margin-top: 15px;
}

.member-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
</style> 