define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) { var validatoroptions = { invalid: function (form, errors) { $.each(errors, function (i, j) { Layer.msg(j); }); } }; var Controller = { login: function () { //本地验证未通过时提示 $("#login-form").data("validator-options", validatoroptions); $(document).on("change", "input[name=type]", function () { var type = $(this).val(); $("div.form-group[data-type]").addClass("hide"); $("div.form-group[data-type='" + type + "']").removeClass("hide"); $('#resetpwd-form').validator("setField", { captcha: "required;length(4);integer[+];remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")", }); $(".btn-captcha").data("url", $(this).data("send-url")).data("type", type); }); //为表单绑定事件 Form.api.bindevent($("#login-form"), function (data, ret) { setTimeout(function () { location.href = ret.url ? ret.url : "/"; }, 1000); }); Form.api.bindevent($("#resetpwd-form"), function (data) { Layer.closeAll(); }); $(document).on("click", ".btn-forgot", function () { var id = "resetpwdtpl"; var content = Template(id, {}); Layer.open({ type: 1, title: __('Reset password'), area: ["450px", "355px"], content: content, success: function (layero) { Form.api.bindevent($("#resetpwd-form", layero), function (data) { Layer.closeAll(); }); } }); }); }, register: function () { //本地验证未通过时提示 $("#register-form").data("validator-options", validatoroptions); //为表单绑定事件 Form.api.bindevent($("#register-form"), function (data, ret) { setTimeout(function () { location.href = ret.url ? ret.url : "/"; }, 1000); }, function (data) { $("input[name=captcha]").next(".input-group-addon").find("img").trigger("click"); }); }, changepwd: function () { //本地验证未通过时提示 $("#changepwd-form").data("validator-options", validatoroptions); //为表单绑定事件 Form.api.bindevent($("#changepwd-form"), function (data, ret) { setTimeout(function () { location.href = ret.url ? ret.url : "/"; }, 1000); }); }, profile: function () { // 给上传按钮添加上传成功事件 $("#plupload-avatar").data("upload-success", function (data) { var url = Fast.api.cdnurl(data.url); $(".profile-user-img").prop("src", url); Toastr.success(__('Upload successful')); }); Form.api.bindevent($("#profile-form")); $(document).on("click", ".btn-change", function () { var that = this; var id = $(this).data("type") + "tpl"; var content = Template(id, {}); Layer.open({ type: 1, title: "修改", area: ["400px", "250px"], content: content, success: function (layero) { var form = $("form", layero); Form.api.bindevent(form, function (data) { location.reload(); Layer.closeAll(); }); } }); }); }, goods: function () { $(document).on("click", ".row-money label[data-type]", function () { $(".row-money label[data-type]").removeClass("active"); $(this).addClass("active"); $("#col-custom").toggleClass("hidden", $(this).data("type") === "fixed"); $("input[name=money]").val($(this).data("value")); if ($(this).data("type") === 'custom') { $("input[name=custommoney]").trigger("focus").trigger("change"); } }); $(document).on("click", ".row-paytype label", function () { $(".row-paytype label").removeClass("active"); $(this).addClass("active"); $("input[name=paytype]").val($(this).data("value")); }); $(document).on("keyup change", ".custommoney", function () { $("input[name=money]").val($(this).val()); }); $(document).on("click", ".row-recharge input", function () { $.ajax({ url: '/index/user/buy_traffic', type: 'POST', data: {money: $("input[name=money]").val()}, dataType: 'json', success:function (res) { if(res.code != 1){ layer.msg(res.msg); return false; }else{ layer.msg(res.msg); setTimeout(function() { window.location.reload(); },2000); } } }); }); } }; return Controller; });