<template>
  <view class="withdrawal">
    <!-- 提现头部 -->
    <view class="withdrawal-top">
      <view class="title"> 到账方式 </view>
      <view class="wx">
        <image src="../../static/mine/323.png" class="wx-logo" mode=""></image>
        <text>微信余额</text>
      </view>
    </view>
    <!-- 提现头部 -->
    <view class="content">
      <view class="money"> 提现金额 </view>
      <view class="inp">
        <text>￥</text>
        <input type="number" v-model="money" />
        <text style="color: #f83224" @click="whole">全部提现</text>
      </view>
      <text class="all-money" v-if="type == 'balance'"
        >可提现金额￥{{ userInformation.balance }}</text
      >
      <text class="all-money" v-else
        >可提现金额￥{{ userInformation.deposit }}</text
      >
      <button class="immediately" @click="immediatelyWithdrawal">
        立即提现
      </button>
      <view class="detail" @click="toWithdrawalDetail"> 提现明细 </view>
    </view>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
export default {
  data() {
    return {
      money: "",
      userInformation: {},
      type: "",
    };
  },
  onLoad(options) {
    this.type = options.type;
    if (options.type == "deposit") {
      uni.setNavigationBarTitle({ title: "保证金提现" });
    } else {
      uni.setNavigationBarTitle({ title: "余额提现" });
    }
  },
  methods: {
    toWithdrawalDetail() {
      uni.navigateTo({
        url: "/pageC/withdrawalDetail/withdrawalDetail?type=" + this.type,
      });
    },
    //立即提现
    immediatelyWithdrawal() {
      uni.$u.http
        .post(`/api/withdraw`, { amount: this.money, account_type: this.type })
        .then((res) => {
          this.money = "";
          this.getUserInfo();
          this.$refs.uToast.show({
            type: "default",
            title: "默认主题",
            message: "已提交提现申请",
          });
        });
    },

    whole() {
      this.money = this.userInformation.balance;
    },
    //获取余额
    getUserInfo() {
      uni.$u.http.get(`/api/member/info`).then((res) => {
        this.userInformation = res;
      });
    },
  },
  mounted() {
    this.getUserInfo();
  },
};
</script>

<style scoped lang="scss">
.withdrawal {
  padding: 20rpx 24rpx 0;

  .withdrawal-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 104rpx;
    background-color: #fff;
    border-radius: 16rpx;
    padding: 0 24rpx;
    .title {
      font-size: 30rpx;
    }

    .wx {
      display: flex;
      align-items: center;
      height: 50rpx;
      .wx-logo {
        width: 40rpx;
        height: 40rpx;
        margin-right: 10rpx;
      }
    }
  }
  .content {
    background-color: #fff;
    border-radius: 16rpx;
    margin-top: 16rpx;
    padding: 32rpx 24rpx 46rpx;
    .money {
      font-size: 30rpx;
    }
    .inp {
      display: flex;
      height: 110rpx;
      align-items: center;
      justify-content: space-between;
      border-bottom: 2rpx solid rgba(151, 151, 151, 0.3);
      margin-bottom: 18rpx;
    }
    .all-money {
      font-size: 24rpx;
      color: #555;
    }
    .immediately {
      box-shadow: 0rpx 12rpx 28rpx -12rpx #f83224;
      border-radius: 44rpx;
      background-color: #f83224;
      color: #fff;
      margin-top: 60rpx;
      margin-bottom: 60rpx;
    }
    .detail {
      text-align: center;
      font-size: 26rpx;
      opacity: 0.6;
      color: #131415;
    }
  }
}
</style>
