// pages/member/rankingListSecond/rankingListSecond.js
var yz_pay = require("../../../mycomponent/yz_pay/yz_pay");
var app = getApp();
Page({
  behaviors: [yz_pay],
  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    val: '',
    recharge_val: '',
    alipay_show: false,
    wechat_show: false,
    // 支付方式
    pay_type: '',
    buttons: {}, // 按钮
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.getData();
  },

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

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

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},
  getData() {
    let urlStr = app.getNetAddresss('plugin.froze.Frontend.Controllers.page.index');
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resData = res.data;
        if (resData.result === 1) {
          this.setData({
            val: resData.data.froze,
            every_value: resData.data.recharge_rate_money,
            transform_value: resData.data.recharge_rate_love,
            // buttons: resData.data.buttons
          });
          resData.data.buttons.map(item => {
            if (item.value == 28) {
              this.setData({
                buttons: item
              });
            }
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },

  // 充值
  rechargeHandel(e) {
    this.setData({
      pay_type: e.target.dataset.index
    });
    if (!this.data.recharge_val) {
      wx.showToast({
        title: '充值数量不能为空',
        icon: 'none',
        duration: 1500
      });
      return;
    }
    let urlStr = app.getNetAddresss('plugin.froze.Frontend.Modules.Froze.Controllers.recharge.index');
    urlStr += '&pay_way=' + this.data.pay_type;
    urlStr += '&change_value=' + this.data.recharge_val;
    urlStr += '&client_type=2';
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result === 1) {
          this.rechargePay(this.data.pay_type, res.data, res.data.ordersn);
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            image: '',
            duration: 1500,
            mask: false
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 输入框被改变的时候
  onChange(val) {
    this.setData({
      recharge_val: val.detail
    });
  }
});
