<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="userinfo-card">
      <div class="card-box">
        <div class="user-section">
          <div class="avatar-wrap">
            <div class="avatar">
              <img :src="userInfo.avatar" alt="头像">
            </div>
          </div>
          <div class="portrait-box">
            <div class="info-box"></div>
            <div class="tuan">
              <div class="ma">账 号： {{ userInfo.mobile }}</div>
            </div>
            <div class="tuan">
              <div class="ma">邀请码 {{ userInfo.salt }}</div>
              <div class="fuzi" @click="copyInviteCode">复 制</div>
            </div>
          </div>
        </div>
        <div class="balance-card-wrap">
          <div class="balance-card">
            <div class="tit">我的邀请收益</div>
            <div class="xia">
              <div class="num">
                <span>{{ userInfo.xianjin || 0 }}</span>
              </div>
            </div>
            <div class="tit" style="font-size: 3.4vw;">邀请好友立享返佣 ！</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main">
      <!-- 收益卡片 -->
      <div class="income-card funs" style="margin-top: 0;">
        <div class="tit1">
          <span>我的收益</span>
          <div class="arrow-right">
            <img src="@/assets/arrow-right.png" alt="箭头">
          </div>
        </div>
        <div class="show-content">
          <div class="view-category">
            <div class="num1">
              <span>{{ userInfo.totleonemo || 0 }}</span>
            </div>
            <div class="text">一级收益</div>
          </div>
          <div class="line"></div>
          <div class="view-category">
            <div class="num1">
              <span>{{ userInfo.totletwomo || 0 }}</span>
            </div>
            <div class="text">二级收益</div>
          </div>
          <div class="line"></div>
          <div class="view-category">
            <div class="num1">
              <span>{{ userInfo.totlethreemo || 0 }}</span>
            </div>
            <div class="text">三级收益</div>
          </div>
        </div>
      </div>

      <!-- 我的团队卡片 -->
      <div class="income-card funs">
        <div class="tit1">
          <span>我的团队</span>
          <div class="arrow-right">
            <img src="@/assets/arrow-right.png" alt="箭头">
          </div>
        </div>
        <div class="show-content">
          <div class="view-category">
            <div class="num1">
              <span>{{ userInfo.totleone || 0 }}</span>
            </div>
            <div class="text">一级人数</div>
          </div>
          <div class="line"></div>
          <div class="view-category">
            <div class="num1">
              <span>{{ userInfo.totletwo || 0 }}</span>
            </div>
            <div class="text">二级人数</div>
          </div>
          <div class="line"></div>
          <div class="view-category">
            <div class="num1">
              <span>{{ userInfo.totlethree || 0 }}</span>
            </div>
            <div class="text">三级人数</div>
          </div>
        </div>
      </div>

      <!-- 工具卡片 -->
      <div class="tool-card funs">
        <div class="tool-item flex listItem" @click="$router.push('/share')">
          <div class="item-right">
            <div class="view-text">邀请好友</div>
            <div class="view-image-right">
              <img src="@/assets/arrow-right.png" alt="箭头">
            </div>
          </div>
        </div>
        <div class="u-line"></div>
        
        <div class="tool-item flex listItem" @click="$router.push('/team-detail')">
          <div class="item-right">
            <div class="view-text">团队明细</div>
            <div class="view-image-right">
              <img src="@/assets/arrow-right.png" alt="箭头">
            </div>
          </div>
        </div>
        <div class="u-line"></div>
        
        <div class="tool-item flex listItem" @click="$router.push('/asset-center')">
          <div class="item-right">
            <div class="view-text">收益记录</div>
            <div class="view-image-right">
              <img src="@/assets/arrow-right.png" alt="箭头">
            </div>
          </div>
        </div>
        <div class="u-line"></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: #f5f5f5;
  padding-bottom: 20px;
}

.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;
}

.userinfo-card {
  background: #fff;
  padding: 5px;
  margin: 15px;
  border-radius: 12px;
}

.card-box {
  position: relative;
}

.user-section {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.avatar-wrap {
  width: 60px;
  height: 60px;
  margin-right: 15px;
}

.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portrait-box {
  flex: 1;
}

.tuan {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 14px;
  font-weight: bold;
}

.ma {
  color: #333;
}

.fuzi {
  color: #ed4b39;
  padding: 2px 8px;
  border: 1px solid #ed4b39;
  border-radius: 4px;
  cursor: pointer;
}

.balance-card {
  background: url('../assets/memberbg.png');
  background-size: cover;
  background-position: center;
  border-radius: 8px;
  padding: 15px;
  margin-top: 20px;
  
}

.tit {
  color: #fff;
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tit1 {
  color: #000;
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.arrow-right {
  width: 5px;
  height: 10px;
}

.arrow-right img {
  width: 100%;
  height: 100%;
}

.num {
  font-size: 24px;
  color: #fff;
  font-weight: bold;
  margin: 10px 0;
}
.num1{
  font-size: 18px;
  color: #000;
  font-weight: bold;
  margin: 10px 0;
}
.main {
  margin: 15px;
}

.income-card {
  background: #fff;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 10px;
}

.show-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.view-category {
  flex: 1;
  text-align: center;
}

.line {
  width: 1px;
  height: 30px;
  background: rgba(0,0,0,0.1);
}

.text {
  font-size: 12px;
  color: #666;
  margin-top: 5px;
}

.tool-card {
  background: #fff;
  border-radius: 8px;
}

.tool-item {
  padding: 15px;
  cursor: pointer;
}

.item-right {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.view-text {
  font-size: 14px;
  color: #333;
}

.view-image-right {
  width: 5px;
  height: 10px;
}

.view-image-right img {
  width: 100%;
  height: 100%;
}

.u-line {
  height: 1px;
  background: rgba(0,0,0,0.1);
  transform: scaleY(0.5);
}

.flex {
  display: flex;
}

.listItem:active {
  background: rgba(0,0,0,0.05);
}
</style> 