user.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
  2. var validatoroptions = {
  3. invalid: function (form, errors) {
  4. $.each(errors, function (i, j) {
  5. Layer.msg(j);
  6. });
  7. }
  8. };
  9. var Controller = {
  10. login: function () {
  11. //本地验证未通过时提示
  12. $("#login-form").data("validator-options", validatoroptions);
  13. $(document).on("change", "input[name=type]", function () {
  14. var type = $(this).val();
  15. $("div.form-group[data-type]").addClass("hide");
  16. $("div.form-group[data-type='" + type + "']").removeClass("hide");
  17. $('#resetpwd-form').validator("setField", {
  18. captcha: "required;length(4);integer[+];remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")",
  19. });
  20. $(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
  21. });
  22. //为表单绑定事件
  23. Form.api.bindevent($("#login-form"), function (data, ret) {
  24. setTimeout(function () {
  25. location.href = ret.url ? ret.url : "/";
  26. }, 1000);
  27. });
  28. Form.api.bindevent($("#resetpwd-form"), function (data) {
  29. Layer.closeAll();
  30. });
  31. $(document).on("click", ".btn-forgot", function () {
  32. var id = "resetpwdtpl";
  33. var content = Template(id, {});
  34. Layer.open({
  35. type: 1,
  36. title: __('Reset password'),
  37. area: ["450px", "355px"],
  38. content: content,
  39. success: function (layero) {
  40. Form.api.bindevent($("#resetpwd-form", layero), function (data) {
  41. Layer.closeAll();
  42. });
  43. }
  44. });
  45. });
  46. },
  47. register: function () {
  48. //本地验证未通过时提示
  49. $("#register-form").data("validator-options", validatoroptions);
  50. //为表单绑定事件
  51. Form.api.bindevent($("#register-form"), function (data, ret) {
  52. setTimeout(function () {
  53. location.href = ret.url ? ret.url : "/";
  54. }, 1000);
  55. }, function (data) {
  56. $("input[name=captcha]").next(".input-group-addon").find("img").trigger("click");
  57. });
  58. },
  59. changepwd: function () {
  60. //本地验证未通过时提示
  61. $("#changepwd-form").data("validator-options", validatoroptions);
  62. //为表单绑定事件
  63. Form.api.bindevent($("#changepwd-form"), function (data, ret) {
  64. setTimeout(function () {
  65. location.href = ret.url ? ret.url : "/";
  66. }, 1000);
  67. });
  68. },
  69. profile: function () {
  70. // 给上传按钮添加上传成功事件
  71. $("#plupload-avatar").data("upload-success", function (data) {
  72. var url = Fast.api.cdnurl(data.url);
  73. $(".profile-user-img").prop("src", url);
  74. Toastr.success(__('Upload successful'));
  75. });
  76. Form.api.bindevent($("#profile-form"));
  77. $(document).on("click", ".btn-change", function () {
  78. var that = this;
  79. var id = $(this).data("type") + "tpl";
  80. var content = Template(id, {});
  81. Layer.open({
  82. type: 1,
  83. title: "修改",
  84. area: ["400px", "250px"],
  85. content: content,
  86. success: function (layero) {
  87. var form = $("form", layero);
  88. Form.api.bindevent(form, function (data) {
  89. location.reload();
  90. Layer.closeAll();
  91. });
  92. }
  93. });
  94. });
  95. },
  96. goods: function () {
  97. $(document).on("click", ".row-money label[data-type]", function () {
  98. $(".row-money label[data-type]").removeClass("active");
  99. $(this).addClass("active");
  100. $("#col-custom").toggleClass("hidden", $(this).data("type") === "fixed");
  101. $("input[name=money]").val($(this).data("value"));
  102. if ($(this).data("type") === 'custom') {
  103. $("input[name=custommoney]").trigger("focus").trigger("change");
  104. }
  105. });
  106. $(document).on("click", ".row-paytype label", function () {
  107. $(".row-paytype label").removeClass("active");
  108. $(this).addClass("active");
  109. $("input[name=paytype]").val($(this).data("value"));
  110. });
  111. $(document).on("keyup change", ".custommoney", function () {
  112. $("input[name=money]").val($(this).val());
  113. });
  114. $(document).on("click", ".row-recharge input", function () {
  115. $.ajax({
  116. url: '/index/user/buy_traffic',
  117. type: 'POST',
  118. data: {money: $("input[name=money]").val()},
  119. dataType: 'json',
  120. success:function (res) {
  121. if(res.code != 1){
  122. layer.msg(res.msg);
  123. return false;
  124. }else{
  125. layer.msg(res.msg);
  126. setTimeout(function() {
  127. window.location.reload();
  128. },2000);
  129. }
  130. }
  131. });
  132. });
  133. }
  134. };
  135. return Controller;
  136. });