index_content.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. var req_base = '/'
  2. function changeHorse(timp) {
  3. return Math.floor(timp / 1000 / 60 / 60)
  4. }
  5. // 格式化数字,没三位添加分号
  6. function toThousands(num) {
  7. return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
  8. }
  9. $(function () {
  10. // 搜索框类型选择
  11. $("#index .search .tips span").on("click",function(){
  12. var i = $(this).index();
  13. $(this).parent().find('i').animate({
  14. left: 14+(95*i) +'px'
  15. },200)
  16. $("#index .search .tips span").removeClass('active')
  17. $(this).addClass('active')
  18. if(i == 0){
  19. $("#zbIndex").attr("action", '/jylab/supsearch/index.html');
  20. $("#zbIndex .ser").attr("name",'keywords')
  21. $("#index .search .index_search_thikn").hide()
  22. $("#zbIndex input").attr('placeholder', '请输入您想要查询的招标信息')
  23. }else{
  24. $("#zbIndex").attr("action", '/jylab/entSearch/index.html');
  25. $("#zbIndex .ser").attr("name",'searchvalue')
  26. $("#zbIndex input").attr('placeholder', '请输入企业名称')
  27. }
  28. })
  29. function thinkList(){
  30. var entName = $("#index .ser").val()
  31. $.ajax({
  32. type: "POST",
  33. url: req_base + 'jylab/bidsearchforent/recList',
  34. data: {
  35. entName: entName
  36. },
  37. success: function (result) {
  38. if(result.recList){
  39. $("#index .search .index_search_thikn").show()
  40. var str = ''
  41. result.recList.forEach(function(v,i){
  42. str += '<li><a href="/jylab/bidsearchforent/index.html?searchvalue='+v.name+'">'+v.name+'</a></li>'
  43. })
  44. $("#index .search .index_search_thikn ul").html(str)
  45. }else{
  46. $("#index .search .index_search_thikn").hide()
  47. }
  48. },
  49. })
  50. }
  51. function debounce(fn,delay) {
  52. var timeout = null; // 创建一个标记用来存放定时器的返回值
  53. return function (e) {
  54. // 每当用户输入的时候把前一个 setTimeout clear 掉
  55. clearTimeout(timeout);
  56. // 然后又创建一个新的 setTimeout, 这样就能保证interval 间隔内如果时间持续触发,就不会执行 fn 函数
  57. var _this = this
  58. timeout = setTimeout(function () {
  59. fn.apply(_this, arguments);
  60. }, delay);
  61. };
  62. }
  63. $("#index .ser").bind("input propertychange",function(){
  64. if($("#zbIndex").attr("action") == '/jylab/bidsearchforent/index.html'){
  65. debounce(thinkList(),500)
  66. }
  67. })
  68. });
  69. (function animateUp(){
  70. var obj = $('.CfadeInUp');
  71. var objH= $('.CfadeInUp').outerHeight();
  72. var num = [];
  73. var wH = $(window).height();
  74. var wScrollTop = $(window).scrollTop();
  75. // 获取页面所有obj的top位置,存入数组
  76. for(var i=0; i<obj.length;i++){
  77. num.push(obj.eq(i).offset().top+(objH/3));
  78. }
  79. // console.log(num)
  80. // 循环数组,判断obj的位置是否在可视区中
  81. function judgeTop(){
  82. for(var j=0; j<num.length;j++){
  83. if (num[j] >= wScrollTop && num[j] < (wScrollTop+wH-50)) {
  84. console.log(j)
  85. if(j == 0){
  86. obj.eq(j).css({
  87. 'animation-name':'CfadeInUp',
  88. 'animation-duration': 0.8 +'s',
  89. 'opacity':'1'
  90. });
  91. }else{
  92. obj.eq(j).css({
  93. 'animation-name':'CfadeInUp',
  94. 'animation-duration': 1.4 +'s',
  95. 'opacity':'1'
  96. });
  97. }
  98. }
  99. }
  100. };
  101. // 页面初始化时先调用一次
  102. judgeTop();
  103. // 触发滚动事件调用判断函数
  104. $(window).scroll(function(event) {
  105. wH = $(window).height();
  106. wScrollTop = $(window).scrollTop();
  107. judgeTop();
  108. });
  109. })();
  110. var entAssoc = {
  111. list: [],
  112. preSearch: {
  113. hover: false,
  114. focus: false
  115. },
  116. init: function () {
  117. this.initDOMEvents()
  118. },
  119. initDOMEvents: function () {
  120. var _this = this
  121. $('#keywords').on('input', this.debounce(function () {
  122. var isEntSearch = $('.search .tips .active').text().indexOf('企业搜索') !== -1
  123. if (isEntSearch) {
  124. _this.getAssocList()
  125. _this.checkListShow()
  126. }
  127. }, 300))
  128. $('.pre-search-list').on('click', '.pre-search-item', function () {
  129. var id = $(this).attr('data-id')
  130. window.open('/swordfish/page_big_pc/svip/ent_ser_portrait/' + id)
  131. })
  132. // 控制list显示隐藏
  133. $('#keywords').on('focus', function () {
  134. _this.preSearch.focus = true
  135. _this.checkListShow()
  136. }).on('blur', function () {
  137. _this.preSearch.focus = false
  138. _this.checkListShow()
  139. })
  140. $('.pre-search-list').on('mouseout', function () {
  141. _this.preSearch.hover = false
  142. _this.checkListShow()
  143. }).on('mouseover', function () {
  144. _this.preSearch.hover = true
  145. _this.checkListShow()
  146. })
  147. },
  148. checkListShow: function () {
  149. var show = $('#keywords').val().length >= 2 && this.list.length && (this.preSearch.focus || this.preSearch.hover)
  150. this.listShow(show)
  151. },
  152. getAssocList: function () {
  153. var _this = this
  154. var data = {
  155. name: $('#keywords').val()
  156. }
  157. if (data.name.length < 2) return
  158. $.ajax({
  159. url: '/bigmember/search/ent/association',
  160. method: 'POST',
  161. data: data,
  162. success: function (res) {
  163. if (res.error_code === 0) {
  164. if (res.data) {
  165. _this.list = res.data.list || []
  166. if (_this.list.length) {
  167. _this.render()
  168. _this.checkListShow()
  169. }
  170. }
  171. }
  172. }
  173. })
  174. },
  175. render: function () {
  176. var container = $('.pre-search-list')
  177. var html = ''
  178. this.list.forEach(function (item) {
  179. html += ('<div class="pre-search-item ellipsis" data-id='+ item.entId +'>' + item.name + '</div>')
  180. })
  181. container.html(html)
  182. },
  183. listShow: function (f) {
  184. if (f) {
  185. $('.pre-search-list').show()
  186. } else {
  187. $('.pre-search-list').hide()
  188. }
  189. },
  190. debounce: function (func, delay, immediate){
  191. var timer = null;
  192. delay = delay || 200
  193. return function() {
  194. var context = this;
  195. var args = arguments;
  196. if(timer) clearTimeout(timer);
  197. if(immediate){
  198. var doNow = !timer;
  199. timer = setTimeout(function(){
  200. timer = null;
  201. },delay);
  202. if(doNow){
  203. func.apply(context,args);
  204. }
  205. }else{
  206. timer = setTimeout(function(){
  207. func.apply(context,args);
  208. },delay);
  209. }
  210. }
  211. }
  212. }
  213. entAssoc.init()