123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- var _page = {
- searchInput: $('.index-search-container .search-input'),
- searchConfMap: {
- zb: {
- placeholder: '请输入搜项目名称等关键词,例如:医疗设备',
- target: '/jylab/supsearch/index.html',
- },
- qy: {
- placeholder: '请输入企业名称',
- target: '/jylab/entSearch/index.html',
- },
- cg: {
- placeholder: '请输入采购单位名称',
- target: '/jylab/purSearch/index.html',
- },
- gy: {
- placeholder: '请输入您想要查询的供应信息,多个关键词用空格隔开',
- target: '/swordfish/page_web_pc/search/issued',
- },
- },
- init: function () {
- headerNavMini.changeHeaderPlaceholder(true)
- this.initEvents()
- this.initHotBuyerShortName()
- this.initHotIndustryTwoLine()
- },
- initEvents: function () {
- this.initSearchEvents()
- this.initBiddingDescTab()
- this.initImportantGovTab()
- },
- initSearchEvents: function () {
- var _this = this
- // 切换筛选项
- $('.search-type-list').on('click', '.search-type-item', function () {
- var dataId = $(this).attr('data-id')
- $(this).addClass('active').siblings().removeClass('active')
- var searchInput = _this.searchInput
- var conf = _this.searchConfMap[dataId]
- if (dataId == 'zb') {
- searchInput.attr('placeholder', conf.placeholder)
- } else if (dataId == 'qy') {
- searchInput.attr('placeholder', conf.placeholder)
- // entAssoc.getAssocList()
- } else if (dataId == 'cg') {
- searchInput.attr('placeholder', conf.placeholder)
- // entAssoc.getAssocList()
- } else if (dataId == 'gy') {
- searchInput.attr('placeholder', conf.placeholder)
- }
- })
- // 确认搜索
- $('#doSearch').on('click', function () {
- var dataId = $('.search-type-list .search-type-item.active').attr('data-id') || 'zb'
- var searchInput = _this.searchInput
- var searchValue = searchInput.val()
- var conf = _this.searchConfMap[dataId]
- if (!conf) return
- // console.log(searchValue, conf)
- var targetUrl = ''
- if (conf) {
- var url = conf.target
- if (dataId == 'zb') {
- // /jylab/supsearch/index.html?keywords=&searchvalue=&selectType=title%2Ccontent
- targetUrl = url + '?keywords=' + searchValue + '&selectType=title'
- } else if (dataId == 'qy') {
- targetUrl = url + '?searchvalue=' + searchValue
- } else if (dataId == 'cg') {
- targetUrl = url + '?searchvalue=' + searchValue
- } else if (dataId == 'gy') {
- targetUrl = url + '?keywords=' + searchValue
- }
- if (targetUrl) {
- window.open(targetUrl)
- }
- }
- })
- // 回车搜索
- this.searchInput.on('keydown', function (e) {
- if (e.keyCode === 13) {
- $('#doSearch').trigger('click')
- }
- })
- },
- initBiddingDescTab: function () {
- var tabWrapper = $('.bidding-desc-module')
- tabWrapper.find('.bidding-desc-item').on('click', function () {
- var key = $(this).attr('data-name')
- $(this).addClass('active').siblings().removeClass('active')
- tabWrapper.find('.bidding-desc-content-card-list[data-value='+ key +']').show().siblings().hide()
- })
- tabWrapper.find('.bidding-desc-item:eq(0)').trigger('click')
- },
- initHotBuyerShortName: function () {
- $('.hot-buyer-list .list-info-item-head').each(function() {
- var head_text = $(this).text()
- if (head_text) {
- var sort_text = __helper.getShortName(head_text)
- $(this).text(sort_text)
- }
- })
- },
- initImportantGovTab: function () {
- var tabWrapper = $('.important-gov-card')
- tabWrapper.find('.i-g-card-header-tab').on('click', function () {
- var key = $(this).attr('data-name')
- $(this).addClass('active').siblings().removeClass('active')
- tabWrapper.find('.i-g-card-list-item[data-value='+ key +']').show().siblings().hide()
- })
- tabWrapper.find('.i-g-card-header-tab:eq(0)').trigger('click')
- },
- initHotIndustryTwoLine: function () {
- var _this = this
- $('.hot-industry .industry-aside-item-content.max-line-2').each(function () {
- // 获取第二行最后一个元素
- var $s = _page.getLine2LastDom($(this), $(this).find('li'))
- $s.attr('data-simple-hidden', '')
- $s.nextAll(':not(.more)').attr('data-simple-hidden', '')
- $('.hot-industry [data-simple-hidden]').addClass('hidden')
- })
- // $('.hot-industry .more').on('click', function () {
- // $(this).parents('.industry-aside-item-content').find('[data-simple-hidden]').removeClass('hidden')
- // $(this).hide()
- // })
- },
- // 获取第二行最后一个元素
- getLine2LastDom: function ($container, $items) {
- // 获取每个列表项的高度和相对于列表容器顶部的距离
- var domList = []
- var distances = [];
- $items.each(function() {
- domList.push($(this))
- distances.push($(this).offset().top - $container.offset().top);
- });
- var firstRowLastIndex = -1;
- // 第一行最后一个元素
- for (var i = 0; i < distances.length; i++) {
- if (i < distances.length && distances[i] !== distances[i + 1]) {
- firstRowLastIndex = i;
- break;
- }
- }
- var secondRowLastIndex = -1;
- // 找到第二行最后一个元素的索引
- for (var j = firstRowLastIndex + 1; j < distances.length; j++) {
- if (j < distances.length && distances[j] !== distances[j + 1]) {
- secondRowLastIndex = j;
- break;
- }
- }
- if (secondRowLastIndex !== -1) {
- return domList[secondRowLastIndex]
- } else {
- return domList[0]
- }
- },
- }
- $(function () {
- _page.init()
- })
|