user.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * 用户相关js
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/6/13
  6. * @version
  7. */
  8. $(document).ready(function() {
  9. $("#info-form").submit(function() {
  10. if (!valid()) {
  11. return false;
  12. }
  13. });
  14. $("#freeVersionText").text(commonUtil.getVersionText());
  15. $("input").blur(function () {
  16. cleanError();
  17. });
  18. //获取cld接口手机号码和数据
  19. $('.getcategory').on('click', function () {
  20. let category = $(this).attr('data-category');
  21. let isupgrade = $(this).attr('data-upgrade');
  22. if (isupgrade === 'true') {
  23. $('#upgrade-title').text($(this).attr('data-title') + ' 售后服务');
  24. } else {
  25. $('#upgrade-title').text('联系销售代表激活');
  26. }
  27. CommonHeader.getCategoryList(category);
  28. });
  29. // 关闭和开启账号登录
  30. $('#isSmsLogin').click(function () {
  31. let status = $(this).is(':checked') ? 1 : 0;
  32. $.ajax({
  33. type: 'post',
  34. url: '/user/change/isSmsLogin',
  35. data: { status: status },
  36. success: function (response) {
  37. if (response.error !== 0) {
  38. alert(response.msg);
  39. }
  40. }
  41. })
  42. });
  43. // 关闭和开启异常登录提醒
  44. $('#isLoginValid').click(function () {
  45. let status = $(this).is(':checked') ? 1 : 0;
  46. $.ajax({
  47. type: 'post',
  48. url: '/user/change/isLoginValid',
  49. data: { status: status },
  50. success: function (response) {
  51. if (response.error !== 0) {
  52. alert(response.msg);
  53. }
  54. }
  55. })
  56. })
  57. });
  58. /**
  59. * 验证数据
  60. *
  61. * @return {boolean}
  62. */
  63. function valid() {
  64. let result = true;
  65. let name = $("#name").val();
  66. if (name === undefined || name === '') {
  67. showError('您得填上姓名!', $("#name"));
  68. return false;
  69. }
  70. let company = $("#company").val();
  71. if (company === undefined || company === '') {
  72. showError('您得填上公司名称!', $("#company"));
  73. return false;
  74. }
  75. let province = $("#province").val();
  76. if (province === undefined || province === '') {
  77. showError('您得选择企业所在地区!', $("#province"));
  78. return false;
  79. }
  80. return result;
  81. }
  82. /**
  83. * 提示错误
  84. *
  85. * @param {string} msg
  86. * @param {object} element
  87. * @return {void}
  88. */
  89. function showError(msg, element) {
  90. element.addClass('orm-control-danger');
  91. if (element !== null) {
  92. element.parent().addClass('has-danger');
  93. }
  94. let html = '<div class="form-control-feedback" style="color: red">' + msg + '</div>';
  95. if (element.siblings('.form-control-feedback').length > 0) {
  96. element.siblings('.form-control-feedback').text(msg);
  97. } else {
  98. element.after(html);
  99. }
  100. }
  101. /**
  102. * 清除错误提示
  103. *
  104. * @return {void}
  105. */
  106. function cleanError() {
  107. $("input").removeClass('orm-control-danger');
  108. $("input").parent().removeClass('has-danger');
  109. $(".form-control-feedback").remove();
  110. }