layui.use(['layer','element','form','util'], function(){
var layer = layui.layer,
element = layui.element,
form = layui.form,
util = layui.util;
util.fixbar({});
form.verify({
// title: function(value){
// if(value.length < 2){
// return '主题请至少填写2个字';
// }
// if(value.length > 20){
// return '主题请最多填写2个字';
// }
// }
// ,address: function(value){
// if(value.length < 5){
// return '您的联系方式请至少填写5个字,可以是您的电话或地址';
// }
// }
// ,contents: function(value){
// if(value.length < 15){
// return '请至少填写15个字';
// }
// }
pass: [
/^[\S]{6,12}$/
,'密码必须6到12位,且不能出现空格'
]
});
// var uploadInst = upload.render({
// elem: '#head_pic'
// ,url: '/upload/'
// ,before: function(obj){
// //预读本地文件示例,不支持ie8
// obj.preview(function(index, file, result){
// $('#demo1').attr('src', result); //图片链接(base64)
// });
// }
// ,done: function(res){
// //如果上传失败
// if(res.code > 0){
// return layer.msg('上传失败');
// }
// //上传成功
// }
// ,error: function(){
// //演示失败状态,并实现重传
// var demoText = $('#demoText');
// demoText.html('上传失败 重试');
// demoText.find('.demo-reload').on('click', function(){
// uploadInst.upload();
// });
// }
// });
//注册提交
form.on('submit(regnew)', function(data){
if($('#password').val() !== $('#repassword').val()){
layer.msg("两次密码不一致");
return false;
}
if(!$("#chkagree").prop('checked')){
layer.msg("请先阅读并同意《用户注册协议》");
return false;
}
var params = {
url: "/ucenter/Login/reg",
type:"POST",
data:JSON.stringify(data.field),
Callback: function (data) {
if(data.errorCode != 0){
$("#img2").attr('src','/ucenter/Login/Verify?'+Math.random());
ybd.msg({msg:data.msg,icon:{icon: 5}});
}else{
ybd.msg({msg:data.msg,icon:{icon: 1}});
setTimeout(function(){
showLogin();
}, 2000);
}
}
};
ybd.ajaxSend(params);
return false;
});
// 登录提交
form.on('submit(frmlogin)', function(data){
var params = {
url: "/ucenter/Login/index",
type:"POST",
data:JSON.stringify(data.field),
Callback: function (data) {
if(data.errorCode != 0){
$("#img").attr('src','/ucenter/Login/Verify?'+Math.random());
ybd.msg({msg:data.msg,icon:{icon: 5}});
}else{
ybd.msg({msg:data.msg,icon:{icon: 1}});
setTimeout(function(){
location.href="/ucenter/My.Baoming/index";
}, 1000);
}
}
};
ybd.ajaxSend(params);
return false;
});
});
var ybd = {
closeAll: function closeAll(){
layer.closeAll();
},
// ajax 简单封装
ajaxSend: function ajaxCall(params){
$.ajax({
type: params.type || "POST",
url: params.url,
data: params.data || null,
dataType: "json",
success: function (data){
params.Callback(data)
},
error:function(error){
console.log(error);
layer.msg("服务器错误!请联系管理员",{icon:5});
}
});
},
open: function open(params){
layer.closeAll();
layer.open({
type: params.type || 1,
title: params.title || false,
closeBtn: params.title || 0, //不显示关闭按钮
anim: params.anim || 2,
area: params.area || ['auto', 'auto'],
shade: params.shade || 0.7,
shadeClose: params.shadeClose || true, //开启遮罩关闭
content: params.content
});
},
msg: function msg(params){
layer.msg(params.msg,params.icon);
}
}
// 登录弹窗
function showLogin(){
var params = {
area:['420px', '420px'],
content:$("#ybd-login")
}
ybd.open(params);
}
// 注册弹窗
function showReg(){
var params = {
area:['420px'],
content:$("#ybd-reg")
}
ybd.open(params);
}
// 退出
//
function logout(){
var params = {
url: "/ucenter/Login/out",
Callback: function (data) {
console.log(data);
if(data.errorCode != 0){
ybd.msg({msg:data.msg,icon:{icon: 5}});
setTimeout(function(){
location.reload();
}, 1000);
}else{
ybd.msg({msg:data.msg,icon:{icon: 1}});
setTimeout(function(){
location.href="/";
}, 1000);
}
}
};
ybd.ajaxSend(params);
return false;
}
/*发送验证码*/
function sendMsg(obj,id,typ){
console.log("sdf");
if($("#"+id).val()=='' || $("#"+id).val()==null){
ybd.msg({msg:'请先输入手机号!'});
$("#"+id).focus();
return false;
}
var phone2 =$("#"+id).val();
regphone2=/^1(3|4|5|6|7|8|9)\d{9}$/;
if ( regphone2.test(phone2)==false)
{
ybd.msg({msg:'请输入正确的手机号码'});
return false;
}else{
var userphone = {
mobile:$("#"+id).val().trim(),
types:typ
}
$.ajax({
type:"POST",
dataType:'json',
headers:{"Content-Type":"application/json"},
url:'/ucenter/Login/sendSms',
data : JSON.stringify(userphone),
success:function(data){
if(data.errorCode == 0){
layer.msg("短信已发送,请在1分钟内输入,过期作废,需重新发送");
$("#"+obj+" .get-codes").hide();
$("#"+obj+" .wait-p").show();
var waitTime = parseInt($("#"+obj+" .cods-wait").html());
var interval = setInterval(function(){
var time = $("#"+obj+" .cods-wait").html(--waitTime);
if(parseInt(waitTime) <= 0) {
$("#"+obj+" .wait-p").hide();
$("#"+obj+" .get-codes").show();
$("#"+obj+" .cods-wait").html("60");
clearInterval(interval);
};
}, 1000);
// layer.msg("短信已发送,请在1分钟内输入,过期作废,需重新发送");
// $("#get-codes").hide();
// $("#wait-p").show();
// var wait = document.getElementById('cods-wait');
// var interval = setInterval(function(){
// var time = --wait.innerHTML;
// if(time <= 0) {
// $("#wait-p").hide();
// $("#get-codes").show();
// $('#cods-wait').html("60");
// clearInterval(interval);
// };
// }, 1000);
return false;
}else{
layer.msg(data.info);
return false;
}
}
});
console.log("sdfads");
}
}
// $("#get-codes").click(function(){
// if($("#phone").val()=='' || $("#phone").val()==null){
// ybd.msg({msg:'请先输入手机号!'});
// $("#phone").focus();
// return false;
// }
// var phone2 =$("#phone").val();
// regphone2=/^1(3|4|5|6|7|8|9)\d{9}$/;
// if ( regphone2.test(phone2)==false)
// {
// ybd.msg({msg:'请输入正确的手机号码'});
// return false;
// }else{
// var userphone = {
// mobile:$("#phone").val().trim()
// }
// layer.msg("短信已发送,请在1分钟内输入,过期作废,需重新发送");
// $("#get-codes").hide();
// $("#wait-p").show();
// var wait = document.getElementById('cods-wait');
// var interval = setInterval(function(){
// var time = --wait.innerHTML;
// if(time <= 0) {
// $("#wait-p").hide();
// $("#get-codes").show();
// $('#cods-wait').html("60");
// clearInterval(interval);
// };
// }, 1000);
// // $.ajax({
// // type : "POST",
// // dataType:'json',
// // url:'/sms-sendSms',
// // data : userphone,
// // success:function(data){
// // if(data.status > 0){
// // layer.msg("短信已发送,请在1分钟内输入,过期作废,需重新发送");
// // $("#get-codes").hide();
// // $("#wait-p").show();
// // var wait = document.getElementById('cods-wait');
// // var interval = setInterval(function(){
// // var time = --wait.innerHTML;
// // if(time <= 0) {
// // $("#wait-p").hide();
// // $("#get-codes").show();
// // $('#cods-wait').html("60");
// // clearInterval(interval);
// // };
// // }, 1000);
// // return false;
// // }else{
// // layer.msg(data.info);
// // return false;
// // }
// // }
// // });
// }
// })