$(function () {
  var accountType = sessionStorage.getItem("accountType");
  var isWhite = sessionStorage.getItem("isWhite");
  if (accountType == 0) {
    $(".modifyPsd").show();
    $(".modifyInfo").hide();
  } else {
    $(".modifyPsd").hide();
    $(".modifyInfo").show();
  }
  if(isWhite != 0){
    $(".modify-info").show()
  }else{
    $(".modify-info").hide()
  }
  var openId = GetQueryString("openId");
  var organId = GetQueryString("organizationId");
  var developId = GetQueryString("developId");
  var userId = GetQueryString("userId");
  var userStatus = GetQueryString("userStatus");
  var register = GetQueryString("register");
  var account = GetQueryString("virAccount");
  var contextPath = $("#contextPath").val();
  var accountType = sessionStorage.getItem("accountType");
  var accountId = GetQueryString("accountId");
  var ERROR_OK = 200;
  // if(!openId){
  //   openId = sessionStorage.getItem("openId");
  // }
  // if(!userId){
  //   userId = sessionStorage.getItem("userId");
  // }
  // if(!organId){
  //   organId = sessionStorage.getItem("orgId");
  // }
  // if(!account){
  //   accountId = sessionStorage.getItem("accId");
  // }
  //修改密码
  $(".untie").on("click", function () {
    window.location.href = contextPath + "/wechat/appUser/virChangePsd?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + userId + "&register=" + register + "&organizationId=" + organId + "&virAccount=" + account;
  });
  //更换手机号码
  $(".change-phone").on("click", function () {
    window.location.href = contextPath + '/wechat/appUser/modifyPhone?userId=' + userId;
  });
  // 修改个人信息
  $(".modify-info").on("click", function () {
    window.location.href = contextPath + "/wechat/appUser/modifyInfo?userId=" + userId;
  })

  $(".back-login").on("click", function () {
    if (accountType == 1) {
      ajaxDropOut(userId,openId,accountId,organId);
    } else {
      ajaxQuit(openId,organId,accountId)
    }
  })
  /**
   * 获取url的参数
   * @param name 参数名
   */
  function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null
  }
  // 退出个人登录
  function ajaxDropOut(userId,openId,accountId,organId) {
    $.ajax({
      url: contextPath + "/wechat/appUser/exitPersonLogin",
      type: "POST",
      data: {
        userId: userId,
        openId: openId,
        accountId: accountId,
        orgId: organId
      },
      success: function (data) {
        if (data.code == ERROR_OK) {
          sessionStorage.setItem("userId",'');
          var findUrl = "https://s.phone580.com/center/platform/qhcjqt4411.html" ;//生产
		  //var findUrl = "https://s.phone580.com/test/center/platform/qhcjqt4411.html";//测试
         //  var findUrl = "http://test.s.phone580.com:8000/service/test/center/platform/qhcjqt4411.html";//测试-1
		  sessionStorage.setItem('findUrl',findUrl)	
          window.location.reload();
          
          window.location.href = $("#contextPath").val() + "/wechat/appUser/newmine?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + userId + "&register=" + register + "&organizationId=" + organId;
        } else {
          alert(data.msg);
        }
      },
      error: function (error) {
        alert(error);
      }
    });
  }
  // 退出企业登录
  /**
   * 退出登录
   * @param openid
   * @param accountId 企业id
   *  @param callback
   */
  function ajaxQuit(openId,organId, accountId) {
    var _this = this;
    $.ajax({
      url: contextPath + "/wechat/appUser/exitLogin",
      type: "POST",
      dataType: "json",
      data: {
        openId: openId,
        accountId: accountId,
        orgId: organId
      },
      success: function (data) {
        if (data.code == ERROR_OK) {
          window.location.reload();
          window.location.href = $("#contextPath").val() + "/wechat/appUser/newmine?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + userId + "&register=" + register + "&organizationId=" + organId;
        } else {
          layer.open({
            content: data.msg,
            skin: 'msg',
            time: 2
          });
        }
      },
      error: function (data) {
        // alert("系统繁忙,菜单加载失败..");
      }
    });
  }
})