PassWordForm.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * wms(http://www.learun.cn)
  3. *
  4. * 创建人:前端开发组
  5. * 日 期:2017.04.11
  6. * 描 述:个人中心-修改密码
  7. */
  8. var bootstrap = function ($, learun) {
  9. "use strict";
  10. var page = {
  11. init: function () {
  12. page.bind();
  13. },
  14. bind: function () {
  15. // 点击切换验证码
  16. $("#Verifycode_img").click(function () {
  17. $("#Verifycode").val('');
  18. $.ajax({
  19. type: 'post',
  20. dataType: 'json',
  21. url: top.$.rootUrl + "/UserCenter/VerifyCode",
  22. success: function (data) {
  23. //将图片的Base64编码设置给src
  24. $("#Verifycode_img").attr("src", "data:image/Gif;base64," + data);
  25. }
  26. });
  27. });
  28. $("#Verifycode_img").trigger('click');
  29. // 旧密码验证
  30. $("#OldPassword").blur(function () {
  31. var $this = $(this);
  32. $this.parent().find('.tip').html('');
  33. if ($this.val() == "") {
  34. return false;
  35. }
  36. var password = $this.val();
  37. learun.httpAsyncPost(top.$.rootUrl + "/UserCenter/ValidationOldPassword", { OldPassword: password }, function (res) {
  38. if (res.code<1) {
  39. $this.parent().find('.tip').html('<div class="tip-error"><i class="fa fa-exclamation-circle"></i>密码错误!</div>');
  40. }
  41. else {
  42. $this.parent().find('.tip').html('<div class="tip-success"><i class="fa fa-check-circle"></i></div>');
  43. }
  44. });
  45. });
  46. // 新密码
  47. $("#NewPassword").blur(function () {
  48. var $this = $(this);
  49. $this.parent().find('.tip').html('');
  50. if ($this.val() == "") {
  51. return false;
  52. }
  53. $this.parent().find('.tip').html('<div class="tip-success"><i class="fa fa-check-circle"></i></div>');
  54. });
  55. $("#RedoNewPassword").blur(function () {
  56. var $this = $(this);
  57. $this.parent().find('.tip').html('');
  58. if ($this.val() == "") {
  59. return false;
  60. }
  61. if ($this.val() == $('#NewPassword').val()) {
  62. $this.parent().find('.tip').html('<div class="tip-success"><i class="fa fa-check-circle"></i></div>');
  63. }
  64. else {
  65. $this.parent().find('.tip').html('<div class="tip-error"><i class="fa fa-exclamation-circle"></i>两次密码输入不一样!</div>');
  66. }
  67. });
  68. $('#lr_save_btn').on('click', function () {
  69. if (!$('#form').lrValidform()) {
  70. return false;
  71. }
  72. if ($('#OldPassword').parent().find('.tip-success').length > 0 && $('#NewPassword').parent().find('.tip-success').length > 0 && $('#RedoNewPassword').parent().find('.tip-success').length > 0)
  73. {
  74. var formData = $('#form').lrGetFormData();
  75. var postData = {
  76. password: formData.NewPassword,
  77. oldPassword: formData.OldPassword,
  78. verifyCode: formData.Verifycode
  79. };
  80. learun.layerConfirm('注:请牢记当前设置密码,您确认要修改密码?', function (res, index) {
  81. if (res) {
  82. $.lrSaveForm(top.$.rootUrl + '/UserCenter/SubmitResetPassword', postData, function (res) {
  83. if (res.code >0) {
  84. top.location.href = top.$.rootUrl + "/Login/Index";
  85. }
  86. console.log(res);
  87. });
  88. top.layer.close(index); //再执行关闭
  89. }
  90. });
  91. }
  92. return false;
  93. });
  94. }
  95. };
  96. page.init();
  97. }