// packageB/member/addressAdd/addressAdd.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    start: false,
    address: "",
    is_default: false,
    mobile: "",
    code: "",
    imgCode: "",
    captcha: "",
    qr: "",
    start1: false,
    codetext: '获取短信验证码',
  },

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

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {

  },
  captchainp(e) {
    let val = e.detail.value;
    this.setData({
      captcha: val
    });
  },
  sendCode(e) {
    if (this.data.start1) {
      return false;
    }
    let time = 60;
    let that = this;
    that.setData({
      "start1": true,
      "codetext": "(" + time + ")秒后重新获取"
    });
    let set = setInterval(function() {
      that.setData({
        codetext: "(" + --time + ")秒后重新获取",
      });
    }, 1000);
    setTimeout(function() {
      that.setData({
        codetext: "获取短信验证码",
        start1: false
      });
      clearInterval(set);
    }, 60000);
    that.verificationCode(set);
  },
  changeImg() {
    this.getMobbile();
  },
  mobileinp(e) {
    let val = e.detail.value;
    this.setData({
      mobile: val
    });
  },
  getMobbile() {
    var that = this;
    let urlStr = app.getNetAddresss(
      "plugin.integral.Frontend.Modules.Integral.Controllers.integral-currency-withdraw-address.fillInAddress");
    app._getNetWork({
      url: urlStr,
      data: {},
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
          wx.navigateTo({
            url: '/packageA/member/editmobile/editmobile'
          });
        } else {
          that.setData({
            mobile: res.data.mobile,
            imgCode: res.data.captcha ? res.data.captcha.img : ''
          });
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      }
    });
  },
  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
});
