proposal_submit_modal1.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. var SubmitModal = {
  2. showModal: function () {
  3. $('.landing-submit-modal').show();
  4. $('.landing-submit-modal .form-modal').show();
  5. stopBodyScroll(true);
  6. },
  7. closeModal: function () {
  8. $('.landing-submit-modal .center-box').hide();
  9. $('.landing-submit-modal').hide();
  10. stopBodyScroll(false);
  11. },
  12. descriptionAreaInput: function (e) {
  13. if (e.target.value.length >= 5) {
  14. $(e.target).siblings('.form-description-message').hide();
  15. $(e.target).removeClass('form-warning');
  16. }
  17. },
  18. submitProposalForm: function (wrapId,flag) {
  19. var subData = {};
  20. //姓名 手机号 描述 预算 公司名
  21. var filedList = ['name', 'phone', 'description', 'budget', 'company', 'project_category', '_token'];
  22. for (var i = 0; i < filedList.length; i++) {
  23. var filedName = filedList[i];
  24. var selector = "#{wrapId} [name='{filedName}']".replace('{wrapId}', wrapId).replace('{filedName}', filedName);
  25. if ($(selector).length > 0) {
  26. var fieldValue = $(selector).val() && ($(selector).val() instanceof Array)
  27. ?
  28. $(selector).val().join(',').trim()
  29. :
  30. $(selector).val().trim();
  31. // var fieldValue = value;
  32. if (filedName == 'description') {
  33. console.log(filedName)
  34. if (!fieldValue || fieldValue.length < 5) {
  35. $(selector).siblings('.form-description-message').show();
  36. $(selector).addClass('form-warning');
  37. return
  38. }
  39. }
  40. subData[filedName] = fieldValue
  41. }
  42. }
  43. for (var filedName in subData) {
  44. var fieldValue = subData[filedName];
  45. if (!fieldValue) {
  46. return
  47. }
  48. }
  49. $('#' + wrapId + ' .submit-ing-footer').show();
  50. for (var i = 0; i < filedList.length; i++) {
  51. var filedName = filedList[i];
  52. var selector = "#{wrapId} [name='{filedName}']".replace('{wrapId}', wrapId).replace('{filedName}', filedName);
  53. if(flag){
  54. if(filedName != 'description'){
  55. $(selector).val('');
  56. }
  57. }else{
  58. $(selector).val('');
  59. }
  60. }
  61. this.submitProposalData(subData)
  62. },
  63. submitProposalData: function (proposalData) {
  64. var that = this;
  65. $('.landing-submit-modal .form-modal').hide();
  66. $('.landing-submit-modal .loading-modal').show();
  67. commonSubmitProposal(proposalData, function (data) {
  68. if (data.result) {
  69. $('.landing-submit-modal .loading-modal').hide();
  70. $('.landing-submit-modal .success-modal').show();
  71. } else {
  72. $('.landing-submit-modal .loading-modal').hide();
  73. $('.landing-submit-modal .err-modal').show();
  74. }
  75. setTimeout(function () {
  76. that.closeModal()
  77. }, 3600)
  78. });
  79. },
  80. }
  81. //是否允许body滚动
  82. function stopBodyScroll(isFixed) {
  83. if (isFixed) {
  84. var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  85. document.body.style.cssText
  86. +=
  87. 'position:fixed;width:100%;top:-' + scrollTop + 'px;';
  88. } else {
  89. var body = document.body;
  90. body.style.position = 'static';
  91. var top = body.style.top;
  92. document.body.scrollTop = document.documentElement.scrollTop = -parseInt(top);
  93. body.style.top = '';
  94. }
  95. }
  96. $('.open-modal').click(SubmitModal.showModal);
  97. //解决微信浏览器输入框顶部布局不会弹的问题
  98. $("input,textarea,select").blur(function () {
  99. setTimeout(function () {
  100. var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
  101. window.scrollTo(0, Math.max(scrollHeight, 0));
  102. }, 100)
  103. /*setTimeout(() => {
  104. var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
  105. window.scrollTo(0, Math.max(scrollHeight - 1, 0));
  106. }, 100);*/
  107. });
  108. // 底部提交表单
  109. function submitFootForm(wrapId) {
  110. var subData = {};
  111. //姓名 手机号 描述 预算 公司名
  112. var filedList = ['name', 'phone', 'description', 'budget', 'company', 'project_category' , '_token'];
  113. for (var i = 0; i < filedList.length; i++) {
  114. var filedName = filedList[i];
  115. var selector = "#{wrapId} [name='{filedName}']".replace('{wrapId}', wrapId).replace('{filedName}', filedName);
  116. if ($(selector).length > 0) {
  117. var fieldValue = $(selector).val() && ($(selector).val() instanceof Array)
  118. ?
  119. $(selector).val().join(',').trim()
  120. :
  121. $(selector).val().trim();
  122. // var fieldValue = value;
  123. if (filedName == 'description') {
  124. console.log(filedName)
  125. if (!fieldValue || fieldValue.length < 5) {
  126. $(selector).siblings('.form-description-message').show();
  127. $(selector).addClass('form-warning');
  128. return
  129. }
  130. }
  131. subData[filedName] = fieldValue
  132. }
  133. }
  134. for (var filedName in subData) {
  135. var fieldValue = subData[filedName];
  136. if (!fieldValue) {
  137. return
  138. }
  139. }
  140. $('#' + wrapId + ' .submit-ing-footer').show();
  141. for (var i = 0; i < filedList.length; i++) {
  142. var filedName = filedList[i];
  143. var selector = "#{wrapId} [name='{filedName}']".replace('{wrapId}', wrapId).replace('{filedName}', filedName);
  144. $(selector).val('')
  145. }
  146. this.submitFootData(wrapId,subData)
  147. }
  148. function submitFootData(wrapId,proposalData) {
  149. $('#' + wrapId + ' .form-modal').hide();
  150. $('#' + wrapId + ' .loading-modal').show();
  151. commonSubmitProposal(proposalData, function (data) {
  152. if (data.result) {
  153. $('#' + wrapId + ' .loading-modal').hide();
  154. $('#' + wrapId + ' .success-modal').show();
  155. } else {
  156. $('#' + wrapId + ' .loading-modal').hide();
  157. $('#' + wrapId + ' .err-modal').show();
  158. }
  159. setTimeout(function () {
  160. $('#' + wrapId + ' .loading-modal').hide();
  161. $('#' + wrapId + ' .success-modal').hide();
  162. $('#' + wrapId + ' .err-modal').hide();
  163. $('#' + wrapId + ' .form-modal').show();
  164. }, 3600)
  165. });
  166. }
  167. function closeForm(wrapId){
  168. $('#' + wrapId + ' .loading-modal').hide();
  169. $('#' + wrapId + ' .success-modal').hide();
  170. $('#' + wrapId + ' .err-modal').hide();
  171. $('#' + wrapId + ' .form-modal').show();
  172. }