var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    info: [],
    param:{
      money:'',
      type:2
    },
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    var self = this;
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
  },
  onShow: function () {
    var self = this;
    app.getUserInfo(function (ret) {
      self.setData({
        info: ret,
      });
      self.getIndex();
    });

  },
  getIndex: function () {
    var self = this;
    var action = 'c=Extension&a=rechange';
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', '', function (ret) {
      if (ret.status == 1) {
        self.setData({
          info: ret.data,
        })
      }
    }, true);
  },
  bindKeyInput:function(e){
    this.setData({
      qt_money: e.detail.value
    })
  
    var param = this.data.param;
    param.money = this.data.qt_money;
    this.setData({
      param: param
    })
  },
  radioChange:function(e){
    var money = e.detail.value;
    console.log(money);
    if(money=='qt'){
      money = this.data.qt_money;
    }
    var param=this.data.param;
    param.money=money;
    this.setData({
      param: param
    })
  },
  radiopayChange: function (e) {
    var payment_id = e.detail.value;
    var param = this.data.param;
    param.paytype = payment_id;
    this.setData({
      param: param
    });
  },
  sub_info:function(){
    var self = this;
    var action = 'c=Extension&a=sub_recharge';
    app.showLoading('加载中...');
    console.log(self.data.param);
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      console.log(ret);
      if (ret.status == 1) {
        self.web_pay(ret.log_id);
      } else{
        app.HCerror('提示', ret.msg); return;
      }
    }, true);
  },
  web_pay: function (pay_id) {
    var self = this;
    var action = 'c=Wxsmallpay&a=pay_done';
    var param = self.data.param;
    param.id = pay_id;
    self.setData({
      param: param
    })
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'POST', self.data.param, function (ret) {
      // console.log(ret);
      if (ret.status == 1) {
        app.HCrequestPayment(ret.wxsmallcode, function (ret) {
          if (ret.status == 1) {
            app.HCswitchTab('../../userinfo/index/index');
          } else {
            app.HCerror('提示', '支付失败');
            app.HCswitchTab('../../userinfo/index/index');
            return;
          }
        });
      } else {
        app.HCerror('提示', ret.msg); return;
      }
    }, true);
  },
  goToPoster: function (event) {
    app.HCnavigateTo('../member_poster/member_poster');
  },
  goToExtensionList: function (event) {
    app.HCnavigateTo('../invite_list/invite_list');
  },
  goToExtension: function (event) {
    app.HCnavigateTo('../list/list');
  },
})