advice.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //字符串去空格
  2. function trim(str) {
  3. return str.replace(/^(\s|\u00A0)+/, '').replace(/(\s|\u00A0)+$/, '');
  4. }
  5. //用户名校验
  6. function checkUserName() {
  7. var str = trim($("#iname").val());
  8. if (str != '匿名用户') {
  9. if (str == "" || str == undefined || str == null) {
  10. $("#iname").focus();
  11. $("#iname").css("border", "1px solid #c31a00");
  12. $('#ruserName').css('display', 'inline-block').text('用户民不能为空!');
  13. return false;
  14. }
  15. else {
  16. var len = 0;
  17. for (var i = 0; i < str.length; i++) {
  18. var a = str.charAt(i);
  19. if (a.match(/[^\x00-\xff]/ig) != null) {
  20. len += 2;
  21. }
  22. else {
  23. len += 1
  24. }
  25. }
  26. if (len > 20) {
  27. $("#iname").focus();
  28. $("#iname").css("border", "1px solid #c31a00");
  29. $('#ruserName').css('display', 'inline-block').text('用户名长度不能超过20个字符');
  30. return false;
  31. }
  32. else {
  33. $('#ruserName').css('display', 'none');
  34. $("#iname").css("border", "1px solid #ccc");
  35. return true;
  36. }
  37. }
  38. }
  39. }
  40. //联系方式校验
  41. function checkContact() {
  42. var str = trim($("#itel").val());
  43. if (str == "" || str == undefined || str == null) {
  44. $("#itel").focus();
  45. $("#itel").css("border", "1px solid #c31a00");
  46. $('#rtel').css('display', 'inline-block').text('请填写有效电话号码或邮箱!');
  47. return false;
  48. }
  49. else {
  50. var rTel = /^1\d{10}$/;
  51. var rEmail = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
  52. if (rTel.test(str) || rEmail.test(str)) {
  53. $('#rtel').css('display', 'none');
  54. $("#itel").css("border", "1px solid #ccc");
  55. return true;
  56. }
  57. else {
  58. $("#itel").focus();
  59. $("#itel").css("border", "1px solid #c31a00");
  60. $('#rtel').css('display', 'inline-block').text('请填写有效电话号码或邮箱');
  61. return false;
  62. }
  63. }
  64. }
  65. //获取验证码
  66. function getVerifyCode() {
  67. $.ajax({
  68. url: getPath() + "/api/v1/Common/GetVerificationCode",
  69. type: "post",
  70. data: {
  71. Type: 1,
  72. Modular: "Feedback",
  73. t: getTime(),
  74. },
  75. success: function (res) {
  76. $("#verifyCode").val(res.Data.Code);
  77. $(".yanz-code").css('border', 'none');
  78. $(".body-yanzlabel").css('display', 'inline-block');
  79. drawPic(res.Data.Code);
  80. $("#time").val(res.Data.ExpiryTime);
  81. $('#countdown').css('display', 'inline-block');
  82. countDownTime(); //倒计时
  83. }
  84. })
  85. }
  86. //倒计时
  87. function countDownTime() {
  88. var time = $("#time").val();
  89. var countdown = formatTime(time);
  90. if (countdown) {
  91. $(".countdown").text(countdown);
  92. setTimeout("countDownTime()", 1000);
  93. } else {
  94. if (time != '') {
  95. //请求验证码
  96. getVerifyCode();
  97. }
  98. }
  99. }
  100. //验证码校验
  101. function checkVerifyCOde() {
  102. if (trim($("#iCode").val().toUpperCase()) != '') {
  103. if (trim($("#iCode").val().toUpperCase()) != $("#verifyCode").val()) {
  104. $("#iCode").css("border", "1px solid #c31a00");
  105. $("#rCode").css('display', 'inline-block');
  106. $("#iCode").focus();
  107. return false;
  108. } else {
  109. $("#iCode").css("border", "1px solid #ccc");
  110. $("#rCode").css('display', 'none');
  111. return true;
  112. }
  113. }
  114. }
  115. function postAdvice() {
  116. if (checkContact && checkUserName && checkVerifyCOde) {
  117. var NickName = trim($("#iname").val()),
  118. Contact = trim($("#itel").val()),
  119. VerificationCode = trim($("#iCode").val()),
  120. Content = trim($("#icontent").val());
  121. if (Content == "") { return false; }
  122. $.ajax({
  123. url: getPath() + "/api/v1/Common/SubmitFeedback",
  124. type: "post",
  125. data: {
  126. VerificationCode: VerificationCode,
  127. NickName: NickName,
  128. Contact: Contact,
  129. Content: Content,
  130. t: getTime(),
  131. },
  132. success: function (res) {
  133. if (res.Status == 200) {
  134. alert("提交成功");
  135. $("#iname").val('匿名用户');
  136. $("#itel").val('');
  137. $("#icontent").val('');
  138. $("#iCode").val('');
  139. $("#rCode").val('');
  140. $("#time").val('');
  141. $(".yanz-code").css('border', '1px solid #ccc');
  142. $(".body-yanzlabel").css('display', 'none');
  143. $('#countdown').css('display', 'none');
  144. $(".post-label").css('display', 'none');
  145. } else {
  146. alert(res.Message);
  147. }
  148. }
  149. })
  150. }
  151. }