var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    info: [],
    member_info:[],
    bank_info:{},
    tixian_free1:0,
    tixian_free:0,
    msg:[],
    banks:0,
    param: {
      unique: 2,
      type: 3
    },
    banks_name:'选择提现方式',
    is_show:false,
    is_show1:0,
    //公共提示
    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.getIndex();
    });

  },
  getIndex: function () {
    var self = this;
    var action = 'c=Extension&a=withdrawals';
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', '', function (ret) {
      if (ret.status == 1) {
        console.log(ret.data)
        self.setData({
          info: ret.data,
          tixian_free: ret.data.tixian_free,
          tixian_free1: ret.data.tixian_free,
          member_info:ret.data.member_info,
          bank_info: ret.data.banks
        })
      }
    }, true);
  },
  bindPickerChange:function(e){
    var value=parseInt(e.detail.value);
    var banks_name = this.data.banks_name;
    var bank_info = this.data.bank_info;
  
    banks_name = bank_info[value];
    value=value+1;
    if(value==1){
      this.setData({
        msg:"请输入支付宝账号",
        is_show:true,
        is_show1:1,
        tixian_free: this.data.tixian_free1
      })
    } else if (value == 3){
      this.setData({
        msg: "请输入微信账号",
        is_show: true,
        is_show1: 3,
        tixian_free: this.data.tixian_free1
      })
    }else if(value==4){
      this.setData({
        msg: "请输入提现账号",
        is_show: true,
        is_bank:true,
        is_show1: 4,
        tixian_free: this.data.tixian_free1
      })
    }else if(value == 2){
     this.setData({
       is_show1: 0,
       tixian_free:0
     })
    }
    
    this.setData({
      banks:value,
      banks_name: banks_name
    })
  },
  sendMessage:function(){
    var self = this;
    var param=self.data.param;
    param.mobile=self.data.member_info.mobile;
    var action = 'c=Ajax&a=sendsms';
    app.showLoading('加载中...');
    console.log(self.data.param);
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      if (ret.status == 1) {
        app.HCtoast('发送成功！');
      } else {
        app.HCerror('提示', ret.msg); return;
      }
    }, true);
  },
  sub_tixian:function(){
    if (!this.data.member_info.real_name) {
      wx.showModal({
        title: '提示',
        content: '请先设置真实姓名',
        showCancel: true,
        success: function (res) {

        },
        complete: function (res) {
          wx.navigateTo({
            url: '../edit_userinfo/edit'
          })
        },
      })
      return false
    }

    this.setData({

      is_pwd: true,
      is_showmask: true
    });


  },
  formSubmit: function (event){
    var self = this;
    var value = event.detail.value;
    value.withdraw_status = self.data.banks;
    value.mobile = self.data.member_info.mobile;
    var action = 'c=Extension&a=sub_ti';
    app.showLoading('加载中...');
    console.log(value);
    app.ajaxRequest(action, 'GET', $.ObjectToStr(value), function (ret) {
      console.log(ret);
      if (ret.status == 1) {
        app.HCtoast('提交成功！');
        app.HCnavigateTo('../money/list/list');
      }else if(ret.status==2){
        app.HCerror('提示', ret.msg, true, function (ret) {
          if (ret.confirm) {
            self.jumprespwd();
          }
        }); return;
      } else {
        app.HCerror('提示', ret.msg); return;
      }
    }, true);
  },
  jumprespwd: function () {
    app.HCnavigateTo('../reset_pwd/reset_pwd');
  },
  //关闭遮罩
  cloce_mask: function () {
    if (this.data.is_pwd == true) {
      this.setData({
        is_pwd: false,
      })
    }
    this.setData({
      is_showmask: false,
    })
  },
})