<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="header-info">
      <div class="user-info">
        <div class="avatar">
          <img src="@/assets/hongqi.png" alt="红旗">
        </div>
        <div class="account-info">
          <div>账号：{{ userInfo.mobile }}</div>
          <div class="invite-code">
            <span>邀请码:{{ userInfo.salt }}</span>
            <button class="copy-btn" @click="copyInviteCode">复制</button>
          </div>
        </div>
      </div>

      <div class="title-text">我的团队</div>

      <!-- 团队数据 -->
      <div class="team-stats">
        <div class="stat-item">
          <div class="stat-num">{{ userInfo.totleone || 0 }}</div>
          <div class="stat-label">一级人数</div>
        </div>
        <div class="stat-item">
          <div class="stat-num">{{ userInfo.totletwo || 0 }}</div>
          <div class="stat-label">二级人数</div>
        </div>
        <div class="stat-item">
          <div class="stat-num">{{ userInfo.totlethree || 0 }}</div>
          <div class="stat-label">三级人数</div>
        </div>
      </div>

      <!-- 功能列表 -->
      <div class="function-list">
        <div class="function-item" @click="$router.push('/share')">
          <span>邀请好友</span>
        </div>
        <div class="function-item" @click="$router.push('/team-detail')">
          <span>团队明细</span>
        </div>
        <div class="function-item" @click="$router.push('/asset-center')">
          <span>收益记录</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/home';
import { getBankInfo } from '@/api/profile';

export default {
  name: 'Member',
  data() {
    return {
      userInfo: {},
      bankInfo: {}
    }
  },
  created() {
    this.getUserInfo();
    // this.getBankInfo();
  },
  methods: {
    async getUserInfo() {
      try {
        const res = await getUserInfo();
        this.userInfo = res.data;
      } catch (error) {
        console.error('获取用户信息失败:', error);
      }
    },
    async getBankInfo() {
      try {
        const res = await getBankInfo();
        this.bankInfo = res.data;
      } catch (error) {
        console.error('获取银行卡信息失败:', error);
      }
    },
    copyInviteCode() {
      if (this.userInfo.salt) {
        navigator.clipboard.writeText(this.userInfo.salt)
          .then(() => {
            alert('邀请码已复制');
          })
          .catch(() => {
            alert('复制失败，请手动复制');
          });
      }
    }
  }
}
</script>

<style scoped>
.container {
  min-height: 100vh;
  /* background: url('../assets/dabag.png') no-repeat; */
  background-color: #b43a39;
  background-size: cover;
  background-position: center;
}

.nav-bar {
  height: 44px;
  background-color: transparent;
  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;
}

.header-info {
  padding: 20px;
  color: #fff;
}

.user-info {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
}

.avatar {
  width: 60px;
  height: 60px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
}

.avatar img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.account-info {
  flex: 1;
  font-size: 14px;
}

.invite-code {
  display: flex;
  align-items: center;
  margin-top: 10px;
  justify-content: space-between;
}

.copy-btn {
  margin-left: 15px;
  padding: 2px 15px;
  background: #fff;
  border: none;
  font-size: 12px;
  cursor: pointer;
  color: #bb2d5c;
  font-weight: bold;
}

.title-text {
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  margin: 30px 0;
}

.team-stats {
  background: #fff;
  border-radius: 8px;
  display: flex;
  margin-bottom: 20px;
}

.stat-item {
  flex: 1;
  text-align: center;
  padding: 15px 0;
  color: #333;
}

.stat-num {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  color: #666;
}

.function-list {
  background: #fff;
  border-radius: 8px;
}

.function-item {
  padding: 15px;
  border-bottom: 1px solid #eee;
  color: #333;
  font-size: 14px;
}

.function-item:last-child {
  border-bottom: none;
}
</style> 