feedback.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * [ONEMAP.M.feedback]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/feedback',
  7. 'css!styles/feedback'
  8. ], function (tplLayout) {
  9. function init() {
  10. setLayout();
  11. bindEvent();
  12. subscribe();
  13. };
  14. function setLayout() {
  15. $(tplLayout).appendTo($("body"));
  16. }
  17. function bindEvent() {
  18. $('.feedbackPanel .close').off('click').on('click', function () {
  19. $('.feedbackPanel').remove();
  20. })
  21. $('.feedbackPanel .submit').off('click').on('click', function () {
  22. var ajaxData = {
  23. gcms_title: $('.feedbackPanel .fk_title').val(),
  24. name: $('.feedbackPanel .name').val(),
  25. company: $('.feedbackPanel .companyName').val(),
  26. phonenum: $('.feedbackPanel .tel').val(),
  27. email: $('.feedbackPanel .e-mail').val(),
  28. question: $('.feedbackPanel .question').val(),
  29. reply: "",
  30. }
  31. var ajaxUrl = onemapUrlConfigNetwork.gcmsServiceUrl + '/content/fankui';
  32. if (ajaxData.company.replace(/ /g, '') === "") {
  33. ONEMAP.C.publisher.publish({
  34. type: "warning",
  35. message: "公司不能为空!"
  36. }, 'noteBar::add');
  37. return false;
  38. }
  39. if (ajaxData.name.replace(/ /g, '') === "") {
  40. ONEMAP.C.publisher.publish({
  41. type: "warning",
  42. message: "名称不能为空!"
  43. }, 'noteBar::add');
  44. return false;
  45. }
  46. if (ajaxData.phonenum.replace(/ /g, '') === "") {
  47. ONEMAP.C.publisher.publish({
  48. type: "warning",
  49. message: "联系电话不能为空!"
  50. }, 'noteBar::add');
  51. return false;
  52. } else {
  53. //验证手机号
  54. var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  55. if (!reg.test(ajaxData.phonenum)) {
  56. ONEMAP.C.publisher.publish({
  57. type: 'warning',
  58. message: '请输入正确的手机号'
  59. }, 'noteBar::add');
  60. return false;
  61. }
  62. }
  63. if (ajaxData.question.replace(/ /g, '') === "") {
  64. ONEMAP.C.publisher.publish({
  65. type: "warning",
  66. message: "需求问题不能为空!"
  67. }, 'noteBar::add');
  68. return false;
  69. }
  70. $.ajax({
  71. url: ajaxUrl,
  72. type: 'POST',
  73. dataType: 'json',
  74. data: ajaxData
  75. })
  76. .done(function (data) {
  77. console.log(data);
  78. if (data.code == 4) {
  79. ONEMAP.C.publisher.publish({
  80. type: "warning",
  81. message: "无权限添加内容"
  82. }, 'noteBar::add');
  83. }
  84. if (data.code == 3) {
  85. // GCMSAPP.C.logout('addArticle');
  86. }
  87. if (data.code == 0) {
  88. ONEMAP.C.publisher.publish({
  89. type: "success",
  90. message: "反馈成功"
  91. }, 'noteBar::add');
  92. $('.feedbackPanel').remove()
  93. }
  94. })
  95. .fail(function () {
  96. ONEMAP.C.publisher.publish({
  97. type: "error",
  98. message: "无权限添加内容"
  99. }, 'noteBar::add');
  100. });
  101. })
  102. };
  103. /**
  104. * 注册订阅
  105. * @type {Function}
  106. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  107. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  108. */
  109. function subscribe() {
  110. }
  111. return ONEMAP.M.feedback = {
  112. init: init,
  113. };
  114. })