<template>
  <div class="card">
    <div class="header_title">
      <div>
        欢迎回来！{{ storeUser.userInfo.username }}
      </div>
      <div v-if="storeUser.userInfo.invite">邀请码:{{ storeUser.userInfo.invite }}</div>
    </div>
    <div class="data_row">
      <div class="item">
        <div class="icon">
          <img class="img" src="../assets/home_icon1.png">
        </div>
        <div class="info">
          <div class="title">团队总流水</div>
          <div class="num">
            <!-- <count-to :start-val="0" :decimals="2" :end-val="homeData.sumConsumeFee" :duration="1000" /> -->
            {{ homeData.sumConsumeFee }}
            <span class="i">元</span>
          </div>
        </div>
      </div>
      <div class="item">
        <div class="icon">
          <img class="img" src="../assets/home_icon2.png">
        </div>
        <div class="info">
          <div class="title">总收益</div>
          <div class="num">
            <!-- <count-to :start-val="0" :decimals="2" :end-val="homeData.sumfansShareMoney" :duration="1000" /> -->
            {{ homeData.sumfansShareMoney }}
            <span class="i">元</span>
          </div>
        </div>
      </div>
      <div class="item">
        <div class="icon">
          <img class="img" src="../assets/home_icon3.png">
        </div>
        <div class="info">
          <div class="title">今日收益</div>
          <div class="num">
            <!-- <count-to :start-val="0" :decimals="2" :end-val="homeData.yestedayShareMoney" :duration="1000" /> -->
            {{ homeData.yestedayShareMoney }}
            <span class="i">元</span>
          </div>
        </div>
      </div>
      <div class="item" v-if="storeUser.userInfo.is_admin != 1">
        <div class="icon">
          <img class="img" src="../assets/home_icon4.png">
        </div>
        <div class="info">
          <div class="title">推广费率</div>
          <div class="num">
            {{ homeData.currentFee }}
            <span class="i">%</span>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="card mt15">
    <chart-card :user-id="storeUser.userInfo.userId" />
  </div>
</template>

<script setup>
import { getIndexData } from '@/api/home.js'
import { useUser } from "@/store/user.js";
import chartCard from '@/components/chartCard.vue';

const storeUser = useUser();

let homeData = reactive({
  sumConsumeFee: 0,
  sumfansShareMoney: 0,
  yestedayShareMoney: 0,
  currentFee: 0
})

// 获取首页数据
async function getIndexDataHandle() {
  try {
    const res = await getIndexData()
    homeData.sumConsumeFee = res.amount_price
    homeData.sumfansShareMoney = res.amount_price_income
    homeData.yestedayShareMoney = res.amount_price_income_day
    homeData.currentFee = res.rate
  } catch (error) {
    console.log(error)
  }
}

onMounted(() => {
  getIndexDataHandle()
});
</script>

<style lang="scss" scoped>
.header_title {
  font-size: 18px;
  font-weight: bold;
  padding: 15px 50px 30px 50px;
  border-bottom: 1px solid #ececec;
  display: flex;
  justify-content: space-between;
}

.data_row {
  display: flex;
  padding: 50px 0;

  .item {
    flex: 1;
    display: flex;
    padding-left: 50px;

    &:not(:last-child) {
      position: relative;

      &::after {
        content: "";
        height: 100%;
        border-right: 1px solid #ececec;
        position: absolute;
        top: 0;
        right: 0;
      }
    }

    .icon {
      $size: 55px;
      width: $size;
      height: $size;
      border-radius: 50%;
      background-color: #F2F3F5;
      display: flex;
      justify-content: center;
      align-items: center;

      .img {
        $size: 30px;
        width: $size;
        height: $size;
        object-fit: contain;
      }
    }

    .info {
      flex: 1;
      padding-left: 20px;
      display: flex;
      flex-direction: column;
      justify-content: center;

      .title {
        font-size: 14px;
        color: #666;
        font-weight: 300;
      }

      .num {
        font-size: 24px;
        font-weight: bold;
        padding-top: 10px;

        .i {
          font-size: 12px;
          position: relative;
          bottom: 1px;
          right: -4px;
        }
      }
    }
  }
}


.userInfo {
  padding: 20px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0 20px;
  border: 1px solid #eee;
  background-color: #fff;

  .name {
    font-size: 20px;
    font-weight: 600;
  }
}

.charts-case {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(2, 1fr);
  gap: 10px;
  grid-template-areas:
    "a b"
    "c c";
  margin-top: 10px;
}

.charts-chunk {
  border: 1px solid #eee;
  background-color: #fff;
}

.charts-chunk:nth-child(0) {
  grid-area: a;
}

.charts-chunk:nth-child(1) {
  grid-area: b;
}

.charts-chunk:last-child {
  grid-area: c;
}
</style>
