<template>
  <div class="teamdetail-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-card">
        <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>

      <!-- 统计信息 -->
      <div class="stats-card">
        <div class="card-header">
          <div class="header-title">统计信息</div>
        </div>
        <div class="stats-content">
          <div class="stats-item">
            <div class="stats-label">总人数</div>
            <div class="stats-value">{{ teamList.length || 0 }}人</div>
          </div>
          <div class="stats-divider"></div>
          <div class="stats-item">
            <div class="stats-label">有效总人数</div>
            <div class="stats-value">{{ teamInfo.yxuser || 0 }}人</div>
          </div>
        </div>
      </div>

      <!-- 团队列表 -->
      <div class="team-card">
        <div class="card-header">
          <div class="header-title">团队成员</div>
        </div>
        <div class="team-list">
          <div v-if="teamList.length === 0" class="empty-state">
            <div class="empty-text">暂无团队成员</div>
          </div>
          <div v-else v-for="item in teamList" :key="item.userId" class="member-card">
            <div class="member-header">
              <div class="member-id">{{ item.id }}</div>
              <div class="member-level">{{ item.level }}级</div>
              <div class="member-mobile">{{ item.mobile }}</div>
            </div>
            <div class="member-info">
              <div class="info-item">
                <span class="info-label">直推人数：</span>
                <span class="info-value">{{ item.zhituicount }}人</span>
              </div>
              <div class="info-item">
                <span class="info-label">邀请时间：</span>
                <span class="info-value">{{ item.createtime }}</span>
              </div>
            </div>
          </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>
.teamdetail-container {
  min-height: 100vh;
  background: linear-gradient(to bottom, #2f9580 0%, #4fb3a1 100%);
}

.nav-bar {
  height: 56px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #fff;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.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: 18px;
  font-weight: 600;
}

.content {
  padding: 20px;
  min-height: calc(100vh - 56px);
}

.tab-card,
.stats-card,
.team-card {
  background: #fff;
  border-radius: 16px;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.tab-card {
  padding: 24px 20px;
}

.tab-group {
  display: flex;
  background: #f8f9fa;
  border-radius: 12px;
  padding: 4px;
}

.tab-item {
  flex: 1;
  height: 44px;
  line-height: 44px;
  text-align: center;
  cursor: pointer;
  color: #6b7280;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.tab-item:hover {
  color: #374151;
}

.tab-item.active {
  background: #2f9580;
  color: #fff;
  box-shadow: 0 2px 8px rgba(47, 149, 128, 0.3);
}

.card-header {
  background: linear-gradient(135deg, #2f9580 0%, #4fb3a1 100%);
  padding: 16px 20px;
}

.header-title {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.stats-content {
  padding: 24px 20px;
  display: flex;
  align-items: center;
}

.stats-item {
  flex: 1;
  text-align: center;
}

.stats-label {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 8px;
}

.stats-value {
  font-size: 20px;
  font-weight: 700;
  color: #2f9580;
}

.stats-divider {
  width: 1px;
  height: 40px;
  background: #e5e7eb;
  margin: 0 20px;
}

.team-list {
  padding: 8px 0;
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
}

.empty-text {
  color: #9ca3af;
  font-size: 16px;
}

.member-card {
  margin: 0 20px 16px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 12px;
  border: 2px solid #e5e7eb;
  transition: all 0.3s ease;
}

.member-card:hover {
  border-color: #2f9580;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(47, 149, 128, 0.2);
}

.member-card:last-child {
  margin-bottom: 8px;
}

.member-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}

.member-id {
  color: #6b7280;
  font-size: 14px;
  background: #e5e7eb;
  padding: 4px 8px;
  border-radius: 6px;
}

.member-level {
  background: #2f9580;
  color: #fff;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.member-mobile {
  font-weight: 600;
  color: #374151;
  font-size: 16px;
}

.member-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-item {
  display: flex;
  align-items: center;
  font-size: 14px;
}

.info-label {
  color: #6b7280;
  font-weight: 500;
  min-width: 80px;
}

.info-value {
  color: #374151;
  font-weight: 600;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .nav-bar {
    height: 50px;
    padding: 0 12px;
  }
  
  .back-btn {
    width: 36px;
    height: 36px;
  }
  
  .title {
    font-size: 16px;
  }
  
  .content {
    padding: 16px;
  }
  
  .tab-card {
    padding: 20px 16px;
  }
  
  .tab-item {
    height: 40px;
    line-height: 40px;
    font-size: 14px;
  }
  
  .card-header {
    padding: 12px 16px;
  }
  
  .header-title {
    font-size: 15px;
  }
  
  .stats-content {
    padding: 20px 16px;
  }
  
  .stats-label {
    font-size: 13px;
  }
  
  .stats-value {
    font-size: 18px;
  }
  
  .stats-divider {
    margin: 0 16px;
  }
  
  .member-card {
    margin: 0 16px 14px;
    padding: 16px;
  }
  
  .member-header {
    gap: 10px;
    margin-bottom: 14px;
  }
  
  .member-id {
    font-size: 13px;
  }
  
  .member-level {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  
  .member-mobile {
    font-size: 15px;
  }
  
  .info-item {
    font-size: 13px;
  }
  
  .info-label {
    min-width: 70px;
  }
  
  .empty-state {
    padding: 40px 16px;
  }
  
  .empty-text {
    font-size: 14px;
  }
}
</style> 