|
@@ -27,6 +27,14 @@ var entAssoc = {
|
|
|
var type = $(this).attr('data-type')
|
|
|
var id = $(this).attr('data-id')
|
|
|
var name = $(this).attr('data-name')
|
|
|
+ if (loginflag) {
|
|
|
+ try {
|
|
|
+ searchHistory.saveBrowseRecord({
|
|
|
+ type: type === 'ent' ? 'ent' : 'buyer',
|
|
|
+ name: type === 'ent' ? name +'_' + id : name
|
|
|
+ })
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
if (type === 'ent') {
|
|
|
window.open('/swordfish/page_big_pc/svip/ent_ser_portrait/' + id)
|
|
|
} else {
|
|
@@ -94,7 +102,7 @@ var entAssoc = {
|
|
|
var isEntSearch = this.isEntSearch()
|
|
|
this.list.forEach(function (item) {
|
|
|
if (isEntSearch) {
|
|
|
- html += ('<div class="pre-search-item ellipsis" data-type="ent" data-id=' + item.entId + '>' + item.name + '</div>')
|
|
|
+ html += ('<div class="pre-search-item ellipsis" data-type="ent" data-name=' + item.name + ' data-id=' + item.entId + '>' + item.name + '</div>')
|
|
|
} else {
|
|
|
html += ('<div class="pre-search-item ellipsis" data-type="buyer" data-name=' + item + '>' + item + '</div>')
|
|
|
}
|
|
@@ -132,6 +140,218 @@ var entAssoc = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+var searchHistory = {
|
|
|
+ preSearch: {
|
|
|
+ hover: false,
|
|
|
+ focus: false
|
|
|
+ },
|
|
|
+ searchList: [],
|
|
|
+ browseList: [],
|
|
|
+ init: function () {
|
|
|
+ var _this = this
|
|
|
+ _this.getSearchHistory()
|
|
|
+ // 控制list显示隐藏
|
|
|
+ $('#keywords').on('focus', function () {
|
|
|
+ _this.preSearch.focus = true
|
|
|
+ _this.checkListShow()
|
|
|
+ }).on('blur', function () {
|
|
|
+ setTimeout(() => {
|
|
|
+ _this.preSearch.focus = false
|
|
|
+ _this.checkListShow()
|
|
|
+ }, 300)
|
|
|
+ })
|
|
|
+ $('#keywords').on('input', function () {
|
|
|
+ if ($(this).val() === '') {
|
|
|
+ _this.preSearch.focus = true
|
|
|
+ _this.checkListShow()
|
|
|
+ } else {
|
|
|
+ _this.preSearch.focus = false
|
|
|
+ _this.checkListShow()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 清除历史
|
|
|
+ $('.keywords-history-card .delete-img').click(function () {
|
|
|
+ var type = ''
|
|
|
+ if (_this.isBidSearch()) {
|
|
|
+ type = 1
|
|
|
+ } else if (_this.isEntSearch()) {
|
|
|
+ type = 2
|
|
|
+ } else if (_this.isBuyerSearch()) {
|
|
|
+ type = 4
|
|
|
+ }
|
|
|
+ _this.removeSearchHistory(type)
|
|
|
+ })
|
|
|
+ $('.browse-history-card .delete-img').click(function () {
|
|
|
+ var type = ''
|
|
|
+ if (_this.isEntSearch()) {
|
|
|
+ type = 3
|
|
|
+ } else if (_this.isBuyerSearch()) {
|
|
|
+ type = 5
|
|
|
+ }
|
|
|
+ _this.removeSearchHistory(type)
|
|
|
+ })
|
|
|
+ _this.goSearchInitEvent()
|
|
|
+ },
|
|
|
+ getType: function () {
|
|
|
+ var type = 1
|
|
|
+ if (this.isBidSearch()) {
|
|
|
+ type = 1
|
|
|
+ } else if (this.isEntSearch()) {
|
|
|
+ type = '2,3'
|
|
|
+ } else if (this.isBuyerSearch()) {
|
|
|
+ type = '4,5'
|
|
|
+ } else {
|
|
|
+ type = ''
|
|
|
+ }
|
|
|
+ return type
|
|
|
+ },
|
|
|
+ isBidSearch: function () {
|
|
|
+ return $('.index-search-module .search-type-list .active').text().indexOf('招标采购搜索') !== -1
|
|
|
+ },
|
|
|
+ isEntSearch: function () {
|
|
|
+ return $('.index-search-module .search-type-list .active').text().indexOf('企业搜索') !== -1
|
|
|
+ },
|
|
|
+ isBuyerSearch: function () {
|
|
|
+ return $('.index-search-module .search-type-list .active').text().indexOf('采购单位搜索') !== -1
|
|
|
+ },
|
|
|
+ checkListShow: function () {
|
|
|
+ var pass = this.isBidSearch() || this.isEntSearch() || this.isBuyerSearch()
|
|
|
+ var show = $('#keywords').val() === '' && this.preSearch.focus && (this.searchList.length || this.browseList.length) && pass
|
|
|
+ this.listShow(show)
|
|
|
+ },
|
|
|
+ listShow: function (f) {
|
|
|
+ if (f) {
|
|
|
+ $('.search-history-list').show()
|
|
|
+ } else {
|
|
|
+ $('.search-history-list').hide()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ render: function (searchList, browseList) {
|
|
|
+ var searchContainer = $('.search-tag-container')
|
|
|
+ var browseContainer = $('.browse-list-container')
|
|
|
+ searchContainer.empty()
|
|
|
+ browseContainer.empty()
|
|
|
+ var sHtml = ''
|
|
|
+ var bHtml = ''
|
|
|
+ if (searchList && searchList.length) {
|
|
|
+ searchList.forEach(function (item) {
|
|
|
+ sHtml += ('<span class="search-tag-item">' + item + '</span>')
|
|
|
+ })
|
|
|
+ searchContainer.html(sHtml)
|
|
|
+ $('.keywords-history-card').show()
|
|
|
+ } else {
|
|
|
+ $('.keywords-history-card').hide()
|
|
|
+ }
|
|
|
+ if(browseList && browseList.length) {
|
|
|
+ browseList.forEach(function (item) {
|
|
|
+ bHtml += ('<div class="browse-history-item ellipsis" data-id=' + item.id + '>' + item.name + '</div>')
|
|
|
+ })
|
|
|
+ browseContainer.html(bHtml)
|
|
|
+ $('.browse-history-card').show()
|
|
|
+ } else {
|
|
|
+ $('.browse-history-card').hide()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 获取搜索历史记录
|
|
|
+ getSearchHistory: function () {
|
|
|
+ // type: 1-标讯搜索历史记录 2-企业历史搜索 3-企业历史浏览 4-采购单位历史搜索 5-采购单位历史浏览
|
|
|
+ var type = this.getType();
|
|
|
+ console.log(type, loginflag);
|
|
|
+ if(!type) return
|
|
|
+ if(!loginflag) return
|
|
|
+ var _this = this
|
|
|
+ _this.searchList = []
|
|
|
+ _this.browseList = []
|
|
|
+ $.ajax({
|
|
|
+ url: '/publicapply/history/get',
|
|
|
+ method: 'POST',
|
|
|
+ data: { type: type },
|
|
|
+ success: function (res) {
|
|
|
+ if (res.error_code === 0) {
|
|
|
+ _this.searchList = res.data.search
|
|
|
+ if (res.data.browse) {
|
|
|
+ // 格式化浏览历史数据(企业画像浏览记录跳转需要企业id, 存历史记录的时候保存格式为“企业名称_企业id”, 取的时候要分割开)
|
|
|
+ res.data.browse = res.data.browse.map(function(item) {
|
|
|
+ if (item.indexOf('_') > -1) {
|
|
|
+ var name = item.split('_')[0]
|
|
|
+ var id = item.split('_')[1]
|
|
|
+ return {
|
|
|
+ name,
|
|
|
+ id
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ name: item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ _this.browseList = res.data.browse
|
|
|
+ }
|
|
|
+ _this.render(res.data.search, res.data.browse)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 点击搜索记录,跳转到搜索结果页
|
|
|
+ goSearchInitEvent: function () {
|
|
|
+ var _this = this
|
|
|
+ $('.search-tag-container').click('.search-tag-item', function(){
|
|
|
+ var biddingSearch = _this.isBidSearch()
|
|
|
+ var entSearch = _this.isEntSearch()
|
|
|
+ var buyerSearch = _this.isBuyerSearch()
|
|
|
+ var name = $(this).text()
|
|
|
+ if (biddingSearch) {
|
|
|
+ window.location.href = '/jylab/supsearch/index.html?keywords=' + name
|
|
|
+ } else if (entSearch) {
|
|
|
+ window.location.href = '/jylab/entSearch/index.html?searchvalue=' + name
|
|
|
+ } else if (buyerSearch) {
|
|
|
+ window.location.href = '/jylab/buyerSearch/index.html?searchvalue=' + name
|
|
|
+ }
|
|
|
+ })
|
|
|
+ $('.browse-list-container').click('.browse-history-item', function(item){
|
|
|
+ var entSearch = _this.isEntSearch()
|
|
|
+ var buyerSearch = _this.isBuyerSearch()
|
|
|
+ var entId = item.target.dataset.id
|
|
|
+ var buyer = item.target.innerText
|
|
|
+ if (entSearch) {
|
|
|
+ window.open('/swordfish/page_big_pc/free/loading/ent/' + entId)
|
|
|
+ } else if (buyerSearch) {
|
|
|
+ window.open('/swordfish/page_big_pc/free/loading/buyer/' + buyer)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 清除历史搜索记录
|
|
|
+ removeSearchHistory: function(type) {
|
|
|
+ var _this = this
|
|
|
+ if (!type) return
|
|
|
+ $.ajax({
|
|
|
+ url: '/publicapply/history/del',
|
|
|
+ method: 'POST',
|
|
|
+ data: { type: type },
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res)
|
|
|
+ if (res.error_code === 0) {
|
|
|
+ _this.getSearchHistory()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 保存浏览记录(企业画像、采购单位画像)
|
|
|
+ saveBrowseRecord: function (data) {
|
|
|
+ var _this = this
|
|
|
+ $.ajax({
|
|
|
+ url: '/publicapply/history/savePortrait',
|
|
|
+ method: 'POST',
|
|
|
+ data: data,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.error_code === 0 && res.data) {
|
|
|
+ _this.getSearchHistory()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
var _page = {
|
|
|
searchInput: $('.index-search-container .search-input'),
|
|
|
searchConfMap: {
|
|
@@ -226,6 +446,8 @@ var _page = {
|
|
|
} else if (dataId == 'wd') {
|
|
|
searchInput.attr('placeholder', conf.placeholder)
|
|
|
}
|
|
|
+ searchHistory.getSearchHistory()
|
|
|
+ searchHistory.listShow(false)
|
|
|
})
|
|
|
// 确认搜索
|
|
|
$('#doSearch').on('click', function () {
|
|
@@ -401,6 +623,7 @@ var _page = {
|
|
|
$(function () {
|
|
|
entAssoc.init()
|
|
|
_page.init()
|
|
|
+ searchHistory.init()
|
|
|
})
|
|
|
|
|
|
// seo优化-底部广告位html内js迁移
|