user.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $("input").blur(function () {
  15. cleanError();
  16. });
  17. //获取cld接口手机号码和数据
  18. $('.getcategory').on('click', function () {
  19. let category = $(this).attr('data-category');
  20. let isupgrade = $(this).attr('data-upgrade');
  21. if (isupgrade === 'true') {
  22. $('#upgrade-title').text($(this).attr('data-title') + ' 售后服务');
  23. } else {
  24. $('#upgrade-title').text('联系销售代表激活');
  25. }
  26. CommonHeader.getCategoryList(category);
  27. })
  28. });
  29. /**
  30. * 验证数据
  31. *
  32. * @return {boolean}
  33. */
  34. function valid() {
  35. let result = true;
  36. let name = $("#name").val();
  37. if (name === undefined || name === '') {
  38. showError('您得填上姓名!', $("#name"));
  39. return false;
  40. }
  41. let company = $("#company").val();
  42. if (company === undefined || company === '') {
  43. showError('您得填上公司名称!', $("#company"));
  44. return false;
  45. }
  46. let province = $("#province").val();
  47. if (province === undefined || province === '') {
  48. showError('您得选择企业所在地区!', $("#province"));
  49. return false;
  50. }
  51. return result;
  52. }
  53. /**
  54. * 提示错误
  55. *
  56. * @param {string} msg
  57. * @param {object} element
  58. * @return {void}
  59. */
  60. function showError(msg, element) {
  61. element.addClass('orm-control-danger');
  62. if (element !== null) {
  63. element.parent().addClass('has-danger');
  64. }
  65. let html = '<div class="form-control-feedback" style="color: red">' + msg + '</div>';
  66. if (element.siblings('.form-control-feedback').length > 0) {
  67. element.siblings('.form-control-feedback').text(msg);
  68. } else {
  69. element.after(html);
  70. }
  71. }
  72. /**
  73. * 清除错误提示
  74. *
  75. * @return {void}
  76. */
  77. function cleanError() {
  78. $("input").removeClass('orm-control-danger');
  79. $("input").parent().removeClass('has-danger');
  80. $(".form-control-feedback").remove();
  81. }