$(function(){
// 账号安全页面
if($('.member-profile').length){
// 邮箱修改
$('.emailedit').click(function(){
var $self = $(this);
$(this).addclass('loading');
$.ajax({
type: 'get',
url: $(this).data('mailedit'),
datatype:'json',
success: function(result){
if(!parseint(result.status)){
result.msg_str=result.msg;
result.msg='';
}
metajaxfun({
result:result,
true_fun:function(){
$self.removeclass('loading');
},
false_fun:function(){
alertify.alert(result.msg_str);
$self.removeclass('loading');
}
});
}
});
});
// 手机绑定-获取短信验证码
$('.safety-modal-teladd .phone-code').click(function(){
var $self = $(this),
$tel = $('.safety-modal-teladd input[name="tel"]'),
$code = $('.safety-modal-teladd input[name="code"]');
if($tel.val()==''||!/^1[0-9]{10}$/.test($tel.val())){
$tel.focus();
$.include(m['plugin']['alertify'],function(){
alertify.error($tel.data('fv-integer-message'));
});
}else if($code.val()==''){
$code.focus();
$.include(m['plugin']['alertify'],function(){
alertify.error($code.data('fv-notempty-message'));
});
}else{
$.ajax({
url: $(this).data('url'),
type: 'post',
data:{tel:$tel.val(),code:$code.val(),random:$('.safety-modal-teladd [name="random"]').val()},
datatype:'json',
success: function(result){
metajaxfun({
result:result,
true_fun:function(){
$self.attr('disabled',true);
$self.html($self.data('retxt') + ' ');
identifytime($self,90);
}
});
}
});
}
});
// 手机号码修改-获取短信验证码
$('.safety-modal-teledit .phone-code').click(function(){
var $self = $(this);
$.ajax({
type: 'get',
url: $(this).data('url'),
datatype:'json',
success: function(result){
metajaxfun({
result:result,
true_fun:function(){
$self.attr('disabled',true);
$self.html($self.data('retxt') + ' ');
identifytime($self,90);
}
});
}
});
});
// 手机号码修改提交
if($('.safety-modal-teledit form').length){
metformvalidationloadfun(function(){
var safety_teledit_form_index=$('.safety-modal-teledit form').index('form');
validate[safety_teledit_form_index].success(function(result,form){
metajaxfun({
result:result,
true_fun:function(){
alertify.success(metlang.usercheckok);
$('.safety-modal-teledit').modal('hide');
$('.safety-modal-teladd').modal('show');
}
});
});
});
}
}
// 注册页面
if($('.register-index').length){
// 获取短信验证码
var $phone = $('button.phone-code');
if($phone.length){
$phone.click(function(){
var $self = $(this),
$phone = $('input[name="username"]').length?$('input[name="username"]'):$('input[name="phone"]'),
$code = $('input[name="code"]'),
$phonecode = $('input[name="phonecode"]');
if($phone.val()==''){
$phone.focus();
$.include(m['plugin']['alertify'],function(){
alertify.error($phone.data('fv-notempty-message'));
});
}else if($phone.attr('name')=='phone' && !/^1[0-9]{10}$/.test($phone.val())){
$phone.focus();
$.include(m['plugin']['alertify'],function(){
alertify.error($phone.data('fv-phone-message'));
});
}else if($code.val()==''){
$code.focus();
$.include(m['plugin']['alertify'],function(){
alertify.error($code.data('fv-notempty-message'));
});
}else{
$.ajax({
type: 'post',
url: $(this).data('url'),
data:{phone:$phone.val(),code:$code.val(),random:$('.form-register [name="random"]').val()},
datatype:'json',
success: function(result){
metajaxfun({
result:result,
true_fun:function(){
$self.attr('disabled',true);
$self.html($self.data('retxt') + ' ');
identifytime($self,90);
}
});
}
});
}
});
}
}
// 邮箱验证
if($('.send-email').length){
$('.send-email').click(function(e){
e.preventdefault();
var $li = $(this).parent('li');
$li.addclass('loading');
$.ajax({
type: 'get',
url: $(this).attr('href'),
datatype:'json',
success: function(result){
metajaxfun({result:result,true_fun:function(){}});
$li.removeclass('loading');
}
});
});
}
})
// 验证码发送倒计时
function identifytime(o,wait) {
var $badge=o.find('span.badge'),
countdown=setinterval(function(){
if (wait == 0) {
o.attr('disabled',false);
$badge.html('');
wait = 90;
clearinterval(countdown);
} else {
wait--;
$badge.html(wait);
}
},1000);
$badge.html(wait);
}