<template>
  <view class="page">
    <view class="amount_card">
      <view class="content">
        <view class="amount">
          <view class="text">账户余额</view>
          <view class="price">{{ currency(wallet.amount, {
            symbol: '￥',
            fromCents: true
          }).format() }}</view>
        </view>
        <view class="btn" @click="jump('./withdraw?amount='+wallet.amount)">提现</view>
      </view>
      <view class="footer" @click="jump('./hangingAmount')">
        <view class="item">
          即将到账:{{ currency(wallet.waitAmount, {
            symbol: '￥',
            fromCents: true
          }).format() }}
        </view>
        <u-icon name="arrow-right"></u-icon>
      </view>
    </view>

    <view class="history" @click="jump('./history')">
      提现记录
      <u-icon name="arrow-right"></u-icon>
    </view>

  </view>
</template>

<script>
import { getWallet } from "@/api/wallet"
import currency from "@/utils/currency"
export default {
  data() {
    return {
      wallet: {
        amount: 0,
        waitAmount: 0
      },
      currency

    };
  },
  methods: {
    jump(url) {
      uni.navigateTo({
        url
      });
    }
  },
  onShow() {
    getWallet().then(({ content }) => {
      if (content) {
        this.wallet = content
        if (this.wallet.id) {
          uni.setStorageSync('walletId', this.wallet.id)
        }
      }
    })
  }
};
</script>

<style lang="scss" scoped>
.page {
  background: #F9F9F9F9;
  min-height: 100vh;
  padding: 24rpx 20rpx;

  .amount_card {
    border-radius: 16rpx;
    background-color: #ffffff;

    .content {
      padding: 30rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .amount {
        display: flex;
        flex-direction: column;

        .text {
          font-size: 30rpx;
          color: #AAAAAA;
          margin-bottom: 18rpx;
        }

        .price {
          font-size: 50rpx;
          color: #222;
          font-weight: bold;
        }
      }

      .btn {
        background-color: #FFC000;
        text-align: center;
        padding: 12rpx;
        width: 100rpx;
        border-radius: 32rpx;
        color: #ffffff;
      }
    }

    .footer {
      border-top: 1px solid #F0F0F0;
      padding: 30rpx;
      display: flex;
      color: #AAAAAA;
      justify-content: space-between;
      align-items: center;
    }

  }

  .history {
    margin-top: 20rpx;
    background-color: #ffffff;
    border-radius: 16rpx;
    padding: 30rpx;
    font-size: 30rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
