index_2023.12.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var _page = {
  2. searchInput: $('.index-search-container .search-input'),
  3. searchConfMap: {
  4. zb: {
  5. placeholder: '请输入搜项目名称等关键词,例如:医疗设备',
  6. target: '/jylab/supsearch/index.html',
  7. },
  8. qy: {
  9. placeholder: '请输入企业名称',
  10. target: '/jylab/entSearch/index.html',
  11. },
  12. cg: {
  13. placeholder: '请输入采购单位名称',
  14. target: '/jylab/purSearch/index.html',
  15. },
  16. gy: {
  17. placeholder: '请输入您想要查询的供应信息,多个关键词用空格隔开',
  18. target: '/swordfish/page_web_pc/search/issued',
  19. },
  20. },
  21. init: function () {
  22. headerNavMini.changeHeaderPlaceholder(true)
  23. this.initEvents()
  24. this.initHotBuyerShortName()
  25. this.initHotIndustryTwoLine()
  26. },
  27. initEvents: function () {
  28. this.initSearchEvents()
  29. this.initBiddingDescTab()
  30. this.initImportantGovTab()
  31. },
  32. initSearchEvents: function () {
  33. var _this = this
  34. // 切换筛选项
  35. $('.search-type-list').on('click', '.search-type-item', function () {
  36. var dataId = $(this).attr('data-id')
  37. $(this).addClass('active').siblings().removeClass('active')
  38. var searchInput = _this.searchInput
  39. var conf = _this.searchConfMap[dataId]
  40. if (dataId == 'zb') {
  41. searchInput.attr('placeholder', conf.placeholder)
  42. } else if (dataId == 'qy') {
  43. searchInput.attr('placeholder', conf.placeholder)
  44. // entAssoc.getAssocList()
  45. } else if (dataId == 'cg') {
  46. searchInput.attr('placeholder', conf.placeholder)
  47. // entAssoc.getAssocList()
  48. } else if (dataId == 'gy') {
  49. searchInput.attr('placeholder', conf.placeholder)
  50. }
  51. })
  52. // 确认搜索
  53. $('#doSearch').on('click', function () {
  54. var dataId = $('.search-type-list .search-type-item.active').attr('data-id') || 'zb'
  55. var searchInput = _this.searchInput
  56. var searchValue = searchInput.val()
  57. var conf = _this.searchConfMap[dataId]
  58. if (!conf) return
  59. // console.log(searchValue, conf)
  60. var targetUrl = ''
  61. if (conf) {
  62. var url = conf.target
  63. if (dataId == 'zb') {
  64. // /jylab/supsearch/index.html?keywords=&searchvalue=&selectType=title%2Ccontent
  65. targetUrl = url + '?keywords=' + searchValue + '&selectType=title'
  66. } else if (dataId == 'qy') {
  67. targetUrl = url + '?searchvalue=' + searchValue
  68. } else if (dataId == 'cg') {
  69. targetUrl = url + '?searchvalue=' + searchValue
  70. } else if (dataId == 'gy') {
  71. targetUrl = url + '?keywords=' + searchValue
  72. }
  73. if (targetUrl) {
  74. window.open(targetUrl)
  75. }
  76. }
  77. })
  78. // 回车搜索
  79. this.searchInput.on('keydown', function (e) {
  80. if (e.keyCode === 13) {
  81. $('#doSearch').trigger('click')
  82. }
  83. })
  84. },
  85. initBiddingDescTab: function () {
  86. var tabWrapper = $('.bidding-desc-module')
  87. tabWrapper.find('.bidding-desc-item').on('click', function () {
  88. var key = $(this).attr('data-name')
  89. $(this).addClass('active').siblings().removeClass('active')
  90. tabWrapper.find('.bidding-desc-content-card-list[data-value='+ key +']').show().siblings().hide()
  91. })
  92. tabWrapper.find('.bidding-desc-item:eq(0)').trigger('click')
  93. },
  94. initHotBuyerShortName: function () {
  95. $('.hot-buyer-list .list-info-item-head').each(function() {
  96. var head_text = $(this).text()
  97. if (head_text) {
  98. var sort_text = __helper.getShortName(head_text)
  99. $(this).text(sort_text)
  100. }
  101. })
  102. },
  103. initImportantGovTab: function () {
  104. var tabWrapper = $('.important-gov-card')
  105. tabWrapper.find('.i-g-card-header-tab').on('click', function () {
  106. var key = $(this).attr('data-name')
  107. $(this).addClass('active').siblings().removeClass('active')
  108. tabWrapper.find('.i-g-card-list-item[data-value='+ key +']').show().siblings().hide()
  109. })
  110. tabWrapper.find('.i-g-card-header-tab:eq(0)').trigger('click')
  111. },
  112. initHotIndustryTwoLine: function () {
  113. var _this = this
  114. $('.hot-industry .industry-aside-item-content.max-line-2').each(function () {
  115. // 获取第二行最后一个元素
  116. var $s = _page.getLine2LastDom($(this), $(this).find('li'))
  117. $s.attr('data-simple-hidden', '')
  118. $s.nextAll(':not(.more)').attr('data-simple-hidden', '')
  119. $('.hot-industry [data-simple-hidden]').addClass('hidden')
  120. })
  121. // $('.hot-industry .more').on('click', function () {
  122. // $(this).parents('.industry-aside-item-content').find('[data-simple-hidden]').removeClass('hidden')
  123. // $(this).hide()
  124. // })
  125. },
  126. // 获取第二行最后一个元素
  127. getLine2LastDom: function ($container, $items) {
  128. // 获取每个列表项的高度和相对于列表容器顶部的距离
  129. var domList = []
  130. var distances = [];
  131. $items.each(function() {
  132. domList.push($(this))
  133. distances.push($(this).offset().top - $container.offset().top);
  134. });
  135. var firstRowLastIndex = -1;
  136. // 第一行最后一个元素
  137. for (var i = 0; i < distances.length; i++) {
  138. if (i < distances.length && distances[i] !== distances[i + 1]) {
  139. firstRowLastIndex = i;
  140. break;
  141. }
  142. }
  143. var secondRowLastIndex = -1;
  144. // 找到第二行最后一个元素的索引
  145. for (var j = firstRowLastIndex + 1; j < distances.length; j++) {
  146. if (j < distances.length && distances[j] !== distances[j + 1]) {
  147. secondRowLastIndex = j;
  148. break;
  149. }
  150. }
  151. if (secondRowLastIndex !== -1) {
  152. return domList[secondRowLastIndex]
  153. } else {
  154. return domList[0]
  155. }
  156. },
  157. }
  158. $(function () {
  159. _page.init()
  160. })