<template>
  <div class="month-award">
    <div class="nav">
      <van-icon
        name="arrow-left"
        size="20"
        class="nav-left"
        @click="handlerBack"
      />
      <span class="nav-title">月度奖励</span>
    </div>
    <div class="notice">
      <van-notice-bar
        left-icon="volume-o"
        color="#333333"
        background="transparent"
      >
        <div slot="left-icon" style="margin-right: 10px">
          <img class="notice-icon" src="@/assets/images/notice.png" alt />
        </div>
        <van-swipe
          vertical
          class="notice-swipe"
          :autoplay="3000"
          :show-indicators="false"
        >
          <!-- TODO 后端列表循环 -->
          <van-swipe-item class="swipe-item">
            <span>{{ awardInfo.growthAward }}</span>
            <span>{{ awardInfo.awardTime }}</span>
          </van-swipe-item>
          <van-swipe-item class="swipe-item">
            <span>{{ awardInfo.growthAward }}</span>
            <span>{{ awardInfo.awardTime }}</span>
          </van-swipe-item>
          <van-swipe-item class="swipe-item">
            <span>{{ awardInfo.growthAward }}</span>
            <span>{{ awardInfo.awardTime }}</span>
          </van-swipe-item>
        </van-swipe>
      </van-notice-bar>
    </div>
    <div class="content">
      <p style="font-size: 16px; font-weight: bold">本月累计奖金</p>
      <countTo
        :startVal="awardInfo.lastToatal"
        :endVal="awardInfo.monthAwardTotal"
        :duration="3000"
        style="font-weight: bold"
      ></countTo>
      <p v-if="awardInfo" style="font-size: 14px;color:#333333">
        历史累计奖金：￥{{ awardInfo.awardTotal || 0 }}
      </p>
    </div>
    <div class="newAdd-my">
      <div class="newAdd">
        <p>￥{{ awardInfo.monthIncreased || 0 }}</p>
        <div class="bottom">
          <img src="@/assets/images/本月新增.png" alt />
          <span>本月新增</span>
        </div>
      </div>
      <div class="my">
        <p>￥{{ awardInfo.userMonthAward || 0 }}</p>
        <div class="bottom">
          <img src="@/assets/images/我的份额.png" alt />
          <span>我的份额</span>
        </div>
      </div>
    </div>
    <div class="level-pool">
      <p class="level-pool-title">各等级本月累计奖励池</p>
      <p class="level-pool-item">
        <span>黄金树等级</span>
        <span> ￥{{ awardInfo.goldAward || 0 }}</span>
      </p>
      <p class="level-pool-item">
        <span>农场主等级</span>
        <span> ￥{{ awardInfo.farmerAward || 0 }}</span>
      </p>
      <p class="level-pool-item">
        <span>森林之星等级</span>
        <span> ￥{{ awardInfo.forestStartAward || 0 }}</span>
      </p>
      <p class="level-pool-item">
        <span>西田森合伙人等级</span>
        <span> ￥{{ awardInfo.partnerAward || 0 }}</span>
      </p>
    </div>
  </div>
</template>

<script>
import countTo from "vue-count-to";
import { monthRewards } from "@/api/reward";
export default {
  name: "MonthAward",
  components: { countTo },
  data() {
    return {
      awardInfo: {
        goldAward: 0,
        farmerAward: 0,
        forestStartAward: 0,
        partnerAward: 0
      }
    };
  },
  created() {
    this.getData();
  },
  methods: {
    handlerBack() {
      try {
        this.$bridgeToAppFun.navigateBack();
      } catch {
        console.log("不能和App交互");
        this.$router.go(-1);
      }
    },
    getData() {
      const params = {
        userId: JSON.parse(localStorage.getItem("user")).userId
      };
      monthRewards(params).then(res => {
        if (res.code === 0) {
          this.awardInfo = res.data;
          this.awardInfo.lastToatal =
            res.data.monthAwardTotal - res.data.growthAward;
          this.awardInfo.awardTotal = res.data.awardTotal.toFixed(2);
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.month-award {
  width: 100%;
  height: 447px;
  background-image: url("../../assets/images/月度奖励背景图.png");
  background-size: cover;
}
.nav {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 46px;
  .nav-left {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 52px;
    height: 100%;
    line-height: 46px;
    text-align: center;
  }
  .nav-title {
    max-width: 60%;
    margin: 0 auto;
    color: #333333;
    font-weight: bold;
    font-size: 16px;
  }
}
.notice {
  box-sizing: border-box;
  min-width: 345px;
  height: 44px;
  line-height: 44px;
  margin: 28px auto 47px;
  background-image: url("../../assets/images/公告.png");
  background-size: cover;

  .van-notice-bar {
    height: 44px;
    line-height: 0;
  }

  .notice-icon {
    width: 16px;
    height: 14px;
  }
  ::v-deep .van-notice-bar__content {
    width: 100%;
  }
  .notice-swipe {
    height: 44px;
    line-height: 44px;

    .swipe-item {
      display: flex;
      justify-content: space-between;
      width: 100%;
    }
  }
}
.content {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  height: 120px;
  margin-bottom: 90px;
  font-family: PingFang-SC;
  p {
    margin: 0;
  }
}
.newAdd-my {
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  width: 345px;
  margin: 0 auto 15px;
  p {
    margin: 0;
  }
  .newAdd,
  .my {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 169px;
    height: 98px;
    padding: 13px 20px 15px 17px;
    font-size: 14px;
    background-color: #ffffff;
    p {
      font-weight: bold;
    }
    img {
      width: 24px;
      height: 21px;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      span {
        font-family: PingFang-SC-Bold;
        color: #666666;
      }
    }
  }
}
.level-pool {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 345px;
  height: 170px;
  margin: 0 auto;
  padding: 18px 15px 19px;
  font-family: PingFang-SC-Medium;
  background-color: #ffffff;
  p {
    margin: 0;
  }
  &-title {
    font-size: 16px;
    color: #333333;
  }
  &-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: #666666;
  }
}
</style>
