var home = { init: function () { home.initScroll(); home.initLogin(); home.initSearch(); }, initSearch: function(){ var isLogin = "0"; $("#createask").click(function () { if(isLogin=="0"){ alert("请先登录"); return; } if ($("#txtask").val() == "") { $("#txtask").focus(); alert("请输入问题"); return; } net.page( "/home/home.aspx", "create_question", { subject: $("#txtask").val(), author: $("#txtask").attr("data-author"), avatar: $("#txtask").attr("data-avatar") }, function (e) { if (e.success) { window.location = "/ask/" + e.id + ".html"; } }); }) }, initLogin: function () { var data = JSON.parse($("#json_data").html()); var html = un.t($("#partner_tpl").html(), data); $("#partner_box").append(html); var random = 0; //登陆 $(".login_iscontain").keypress(function (e) { if (e.which == 13) { $(".userlogin").trigger("click"); return; } }); $(".userlogin").click(function () { var _this = this; var txt_login_uname = $(".login_ul .login_uname").val().trim(); var txt_login_upass = $(".login_ul .login_upass").val().trim(); if (txt_login_uname == "") { alert("请输入用户名"); return; } else if (txt_login_upass == "") { alert("请输入密码"); return; } else { $(_this).parent("li").hide(); $("#lgn_loading").show(); //检测用户是否存在 net.get("login_check", { uname: txt_login_uname, upass: txt_login_upass, rempass: $(".login_rempass").attr("checked") ? "true" : "false" }, function (e) { if (e.success) { //if (e.goto_erp) // window.location = "/erp/"; //else // window.location = "/m/?s=" + e.def_uid; window.location.reload(); } else { $(_this).parent("li").show(); $("#lgn_loading").hide(); alert(e.message); } }); } }); //注册 $(".regist_iscontain").keypress(function (e) { if (e.which == 13) { $(".btnregist").trigger("click"); return; } }); $(".btnregist").click(function () { var _this = this; var txt_reg_code = $(".register_ul .reg_code").val().trim(); var txt_reg_upass = $(".register_ul .reg_upass").val().trim(); var txt_reg_reupass = $(".register_ul .reg_reupass").val().trim(); var txt_reg_phone = $(".register_ul .reg_number").val().trim(); var txt_reg_email = $(".register_ul .reg_email").val().trim(); if (!isMobile(txt_reg_phone)) { alert("请输入正确手机号码") return; } else if (txt_reg_code == "") { alert("请输入验证码"); return; }else if (txt_reg_email ==""){ alert("请输入邮箱地址") return; } else if (txt_reg_upass == "") { alert("请输入密码"); return; } else if (txt_reg_reupass == "") { alert("请确认输入密码"); return; } else if (txt_reg_reupass != txt_reg_upass) { alert("两次输入的密码不同"); return; } else { $(_this).parent("li").hide(); $("#reg_loading").show(); net.save("master_user_reg", { tel: txt_reg_phone, upass: txt_reg_reupass, code: txt_reg_code, email: txt_reg_email }, function (e) { if (e.success) { window.location = "/m/"; } else { alert(e.message); $("#reg_loading").hide(); $(_this).parent("li").show(); } }); } }); // 注册发送短信验证码 $("#get_sms_code").click(function (e) { var _this = this; if ($(_this).hasClass("active")) return; $(".input_register_code").val(""); $("#random_code_img").attr("src", "/sys/VerifyCode.aspx?v=" + Math.random()); var mobile = $(".reg_number").val().trim(); if (!isMobile(mobile)) { alert("请输入正确手机号码") return; } net.page(//验证图像验证码 "/home/home.aspx", "check_mobile_exist", { tel: mobile }, function (e) { if (e.success) { $(".register_ul").hide(); $(".register_verify_ul").show(); } else alert(e.message); }); }); $(".input_register_code").keypress(function (e) { if (e.which == 13) { $("#send_verigy_code").trigger("click"); return; } }); $("#send_verigy_code").click(function () { var _this = this; net.page(//验证图像验证码 "/home/home.aspx", "check_verify_code", { code: $(".input_register_code").val().trim() }, function (e) { if (e.success) { net.page(//发送短信验证码 "/home/home.aspx", "get_verification_code", { mobile: $(".reg_number").val().trim() }, function (e) { }); $("#get_sms_code").text("还有60秒重发"); $("#get_sms_code").addClass("active"); var seconds = 60; var timer = setInterval(function () { if (seconds <= 1) { clearInterval(timer); $("#get_sms_code").removeClass("active"); $("#get_sms_code").text("发送验证码"); } else { seconds--; $("#get_sms_code").text("还有" + seconds + "秒重发"); } }, 1000); $(".register_ul").show(); $(".register_verify_ul").hide(); } else alert(e.message); }); }); $("#verigy_code_cancel").click(function () {//取消发送验证码 $(".register_ul").show(); $(".register_verify_ul").hide(); }); $("#random_code_img").click(function () {//刷新图片验证码 $("#random_code_img").attr("src", "/sys/VerifyCode.aspx?v=" + Math.random()); $(".input_register_code").val(""); }); //进入后台缓冲窗 $(".btn_entry").click(function () { $(".logined").addClass("loading"); }); }, initScroll: function () { if (window.innerWidth) { var winWidth = window.innerWidth; $(".slide").find(".scrollitem").css("width", Number(winWidth) + "px"); $("#img_box").find(".scrollitem").css("width", "127px"); $("#img_box").find("li").css("width", "127px"); if (winWidth < 500) { $(".slide").css("height", "0px"); $("#img_box").find("li").css("width", parseInt(Number(winWidth) * 158 / 1000) + "px"); $("#img_box").find("ul").css("line-height", ""); $("#img_box").find("ul").css("top", "0px"); $("#img_box").css("height", parseInt(Number(winWidth)) / 25 + 9 + "px"); } else if (winWidth < 1218) { $(".slide").css("width", "100%"); $(".slide").find(".scrollitem").css("width", "100%"); } } var items = Number($(".slide").find(".scrollitem").length); var winWidth = null; var scroll_picture = new ScrollAD($(".slide")); scroll_picture.Events.Scroll = function (index) { for (var count = 0; count < items; count++) { $("#a_active_" + (count + 1)).removeClass("active"); } $("#a_active_" + index).addClass("active"); }; scroll_picture.Config.Speed = "5000"; scroll_picture.Show(); $(".notice_pos a").click(function () { var a_id = $(this).attr("id"); var index = $("#" + a_id).attr("data-value"); scroll_picture.MoveTo(index); }); var scroll_icon = new ScrollAD($("#img_box")); scroll_icon.Config.Auto = false; scroll_icon.Show(); $(".img_moveback").click(function () { scroll_icon.MoveBack(); }); $(".img_moveforward").click(function () { scroll_icon.MoveForward(); }); $("#slide > .slide_bg").click(function () { var url = $(this).attr("data-url"); window.open(url); }); } } $(document).ready(function () { home.init(); });