let app = getApp();
//替换成开发者后台设置的安全域名
let domain = app.globalData.domain;
//获取用户信息的url
let codeUrl = domain + "/dingding/sendcode";
let bindsUrl = domain + "/dingding/binds";
Page({
  data:{
    time:'获取验证码',
    currentTime:60,
    phone:""
  },

  setPhone:function(e){
   // console.log("电话是", e.detail.value)
      this.setData({

        phone:e.detail.value
      })
 
  },
  submitForm:function (e){
    var userId = app.globalData.userId;
    //console.log(e.detail.value.phonetel);
    dd.httpRequest({
      url: bindsUrl,
      method: 'POST',
      data: {

        phonetel: e.detail.value.phonetel,
        code: e.detail.value.code,
        userId:userId

      },
      dataType: 'json',
      success: function(res) {
        console.log( res);
        console.log('success----', res);

       if( res.data.success){
         dd.alert({
           title: '绑定成功',
           content: '绑定成功',
           buttonText: '确定',
           success: () => {
             dd.reLaunch({
               url: '../conference/index/index'
             });
           },
         });
       }else {
         dd.alert({
           title: '绑定失败',
           content: res.data.message,
           buttonText: '确定',
           success: () => {
             dd.reLaunch({
               url: '.'
             });
           },
         });
       }



        // _this.setData({
        //   conferenceList: res.data.result
        // })
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });


  },
  getCode: function(options) {
    

    var that = this;
    var currentTime = that.data.currentTime;
    var interval;
    interval = setInterval(function() {
      currentTime--;
      that.setData({
        time: currentTime + '秒'
      })
      if (currentTime <= 0) {
        clearInterval(interval);
        that.setData({
          time: '重新获取',
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000);
    dd.httpRequest({
      url: codeUrl,
      method: 'POST',
      data: {

        phone: that.data.phone

      },
      dataType: 'json',
      success: function(res) {
        console.log('success----', res)
       
        
          
         
        
        // _this.setData({
        //   conferenceList: res.data.result
        // })
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });

 
  

  },
  btnTap() {
    this.getCode();
    var that = this;
    that.setData({
      disabled: true
    });
     

  },
  onLoad(query) {
    // 页面加载
    console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
  },
  onReady() {
    // 页面加载完成
  },
 
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    // return {
    //   title: 'My App',
    //   desc: 'My App description',
    //   path: 'pages/index/index',
    // };
  },
});
