let app = getApp();
//替换成开发者后台设置的安全域名
let domain = app.globalData.domain;
let updateInfoUrl = domain + "/dingding/updateInfo";
Page({
  data: {
    imageurl: "http://139.159.202.24:8888",
    user:null,
    img: "",
    sexs:[
      { name: 'man', value: '男' , checked:true},
      { name: 'women', value: '女' }
    ],
    inputValue: ''
  },
  selectImg() {
    var _self = this
    a.chooseImage({
      success: function(res) {
        var tempFilePaths = res.tempFilePaths;
        _self.setData({
          img: tempFilePaths
        })
        console.log("file" + ":" + tempFilePaths[0])
        wx.uploadFile({
          url: app.globalData.ip + '/upload.php',
          filePath: tempFilePaths[0],
          name: 'test',
          success(data) {
            console.log(data);
          }
        })
      }
    })
  },
  Phone(e) {
    var phone = e.detail.value;
    if (!(/^1[34578]\d{9}$/.test(phone))) {
    if (phone.length < 11) {
      dd.alert({
        content: '手机号码格式有误',
        buttonText: '我知道了',
      });
    }
    } 
  },
  Email(e) {
    var email = e.detail.value;
    let str = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
      if (str.test(email)) {
      return true
      } 
      else {
      dd.alert({
      content: '请填写正确的邮箱号',
      buttonText: '我知道了',
      })
      }
  },
  // SexChange(e) {
  //   console.log('你选择的是：', e.detail.value)
   
   
  // },
  
  onLoad(query) {
    // 页面加载
     console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
    var user = {};
    user['nickname']=query.nickname;
    user['phonetel']=query.phonetel;
    user['email'] = query.email;
    user['id'] = query.id;
    user['headPortait'] = query.headPortait;
    user['sex'] = query.sex;
    //var sexs=this.data.sexs;
     var sexs = this.data.sexs;
     if (query.sex=='男'){
      sexs[0]["checked"]=true;
      sexs[1]["checked"] = false;
    }else {
      sexs[1]["checked"] = true;
      sexs[0]["checked"] = false;
    }
    this.setData({
        sexs:sexs,
        user

    });
   
  },
  updateInfo:function(e){
    console.log("携带参数", e.detail.value);
    dd.httpRequest({
      url: updateInfoUrl,
      method: 'POST',
      data: {
        id:this.data.user.id,
        phonetel: e.detail.value.phonetel,
        nickname: e.detail.value.nickname,
        email: e.detail.value.email,
        sex: e.detail.value.sex
      },
      dataType: 'json',
      success: function(res) {
           console.log('success----', res)


        if (res.data.success) {
          //console.log("预定成功");
          dd.alert({
            title: '修改成功',
            content: '修改成功',
            buttonText: '确定',
            success: () => {
              dd.navigateBack({
              delta: 1
             })
              // dd.({
              //   url: '../my/my'
              // });
            },
          });
        } else {
          dd.showToast({
            type: 'fail',
            content: res.data.message,
            duration: 3000,
            success: () => {
              //  dd.navigateTo({
              //    url: '../index/index'
              //  });
            },
          });
        }
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });
  },
  onReady() {
    // 页面加载完成
  },

  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息

  },
});