<template>
  <div class="wallet">
    <div class="content">
      <img class="balance-img" src="@/assets/images/余额.png" alt />
      <p class="currentprofitlabel">
        当月收益
      </p>
      <div class="currentprofit" @click="jumpToIncomeDetail">
        <span class="month-income">{{ walletInfo.moneyIncome }}</span>
        <img src="@/assets/images/右箭头.png" alt class="month-income-arrow" />
      </div>
      <div class="bottom-box">
        <div class="income-item">
          <img src="@/assets/images/待结算.png" alt />
          <p>累计收益</p>
          <div @click="jumpToAll">
            <span class="money">{{ walletInfo.totalIncome }}</span>
            <img src="@/assets/images/右箭头.png" alt class="arrow" />
          </div>
        </div>
        <div class="income-item">
          <img src="@/assets/images/累计收入.png" alt />
          <p>未提余额</p>
          <div @click="jumpToCanCashOut">
            <span class="money">{{ walletInfo.currentMoneyCan }}</span>
            <img src="@/assets/images/右箭头.png" alt class="arrow" />
          </div>
        </div>
      </div>
      <div class="cash-out-btn">
        <van-button type="primary" color="#88c678" @click="onToCashOut"
          >提现</van-button
        >
        <p @click="onToRecord">查看提现记录</p>
      </div>
    </div>
  </div>
</template>

<script>
import { getMoneyPackage } from "@/api/wallet";
export default {
  name: "Wallet",
  data() {
    return {
      walletInfo: {
        currentMoneyCan: 0, // 本月可提现
        moneyIncome: 0, // 本月收益
        totalIncome: 0 // 累计收益
      }
    };
  },
  mounted() {
    this.getWalletInfo();
  },
  methods: {
    // 跳转到可提现界面
    jumpToCanCashOut() {
      this.$router.push("/canCashOut");
    },
    // 跳转至收益明细
    jumpToIncomeDetail() {
      this.$router.push("/income/detail");
    },
    // 跳转至累计收益
    jumpToAll() {
      this.$router.push("/income/all");
    },
    onToCashOut() {
      this.$router.push("/cash-out");
    },
    onToRecord() {
      this.$router.push("/cash-out-record");
    },
    // 获取用户钱包展示信息
    getWalletInfo() {
      const params = {
        userId: this.$userId
      };
      getMoneyPackage(params)
        .then(res => {
          if (res.code === 0) {
            this.walletInfo = res.data;
          } else {
            this.$toast.fail(res.message);
          }
        })
        .catch(error => {
          console.log("catch", error);
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.wallet {
  box-sizing: border-box;
  height: calc(100vh - 48px);
  overflow: hidden;
  padding: 15px;
  box-sizing: border-box;
  .content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 345px;
    height: 100%;
    text-align: center;
    background-color: #ffffff;
    .currentprofitlabel {
      width: 100%;
      font-size: 18px;
      color: #333333;
    }
    .currentprofit {
      width: 100%;
      top: 178px;
    }
    .balance-img {
      width: 34px;
      height: 34px;
    }

    .month-income {
      margin-right: 10px;
      font-size: 28px;
      color: #333333;
    }
    .month-income-arrow {
      width: 11px;
      height: 18px;
    }

    .bottom-box {
      display: flex;
      justify-content: space-around;
      align-items: center;
      width: 100%;
      margin: 20px 0;
      font-size: 14px;
      color: #666666;
      img {
        width: 30px;
        height: 29px;
        &.arrow {
          width: 12px;
          height: 18px;
        }
      }
      .income-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        height: 120px;
      }
      .money {
        font-size: 20px;
        color: #333333;
        margin-right: 10px;
      }
    }

    .cash-out-btn {
      .van-button {
        width: 160px;
      }
      p {
        margin-top: 20px;
        font-size: 14px;
        color: #88c678;
      }
    }
  }
}
</style>