// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    //是否提现到微信
    withdrawToWechat: 0,
    //是否提现到支付宝
    withdrawToAlipay: 0,
    //华侨名称
    coin_name: "",
    //登陆会员冻结华侨币
    froze: "0.00",
    //登陆会员可用华侨币
    usable: "0.00",
    //提现手续费比例
    withdraw_proportion: 0,
    //保留两位小数
    bllw: 0, //
    balance: 0,
    balance_money: ""
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    // this.toi = this.fun.getKeyByI();
    this.setData({
      balance_money: ""
    });
    //获取数据
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  //获取数据
  getData() {
    let urlStr = app.getNetAddresss("plugin.coin.Frontend.Controllers.page.index");
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            withdraw_proportion: resData.data.withdraw_proportion,
            froze: resData.data.froze,
            usable: resData.data.usable,
            coin_name: resData.data.coin_name
          });

        } else {
          wx.showToast({
            title: resData.msg,
            icon: "none"
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  confirm() {
    if (!this.data.balance_money) {
      wx.showToast({
        title: "提现金额不能为空",
        icon: "none"
      });
      return;
    }
    let urlStr = app.getNetAddresss("plugin.coin.Frontend.Modules.Coin.Controllers.withdraw.index");
    urlStr += "&change_value=" + this.data.balance_money;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        console.log(res, '数据');
        if (res.data.result === 1) {
          // 跳转到提现页面
          wx.navigateTo({
            url: '/packageA/member/withdrawal/withdrawal'
          });
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 输入框改变的时候触发
  onChange(val) {
    this.setData({
      balance_money: val.detail
    });
  },
});
