|
@@ -121,3 +121,108 @@ $("#index .ser").bind("input propertychange",function(){
|
|
|
judgeTop();
|
|
|
});
|
|
|
})();
|
|
|
+
|
|
|
+var entAssoc = {
|
|
|
+ list: [],
|
|
|
+ preSearch: {
|
|
|
+ hover: false,
|
|
|
+ focus: false
|
|
|
+ },
|
|
|
+ init: function () {
|
|
|
+ this.initDOMEvents()
|
|
|
+ },
|
|
|
+ initDOMEvents: function () {
|
|
|
+ var _this = this
|
|
|
+ $('#keywords').on('input', this.debounce(function () {
|
|
|
+ var isEntSearch = $('.search .tips .active').text().indexOf('企业搜索') !== -1
|
|
|
+ if (isEntSearch) {
|
|
|
+ _this.getAssocList()
|
|
|
+ _this.checkListShow()
|
|
|
+ }
|
|
|
+ }, 300))
|
|
|
+ $('.pre-search-list').on('click', '.pre-search-item', function () {
|
|
|
+ var id = $(this).attr('data-id')
|
|
|
+ window.open('/swordfish/page_big_pc/svip/ent_ser_portrait/' + id)
|
|
|
+ })
|
|
|
+ // 控制list显示隐藏
|
|
|
+ $('#keywords').on('focus', function () {
|
|
|
+ _this.preSearch.focus = true
|
|
|
+ _this.checkListShow()
|
|
|
+ }).on('blur', function () {
|
|
|
+ _this.preSearch.focus = false
|
|
|
+ _this.checkListShow()
|
|
|
+ })
|
|
|
+ $('.pre-search-list').on('mouseout', function () {
|
|
|
+ _this.preSearch.hover = false
|
|
|
+ _this.checkListShow()
|
|
|
+ }).on('mouseover', function () {
|
|
|
+ _this.preSearch.hover = true
|
|
|
+ _this.checkListShow()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ checkListShow: function () {
|
|
|
+ var show = $('#keywords').val().length >= 2 && this.list.length && (this.preSearch.focus || this.preSearch.hover)
|
|
|
+ this.listShow(show)
|
|
|
+ },
|
|
|
+ getAssocList: function () {
|
|
|
+ var _this = this
|
|
|
+ var data = {
|
|
|
+ name: $('#keywords').val()
|
|
|
+ }
|
|
|
+ if (data.name.length < 2) return
|
|
|
+ $.ajax({
|
|
|
+ url: '/bigmember/search/ent/association',
|
|
|
+ method: 'POST',
|
|
|
+ data: data,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.error_code === 0) {
|
|
|
+ if (res.data) {
|
|
|
+ _this.list = res.data.list || []
|
|
|
+ if (_this.list.length) {
|
|
|
+ _this.render()
|
|
|
+ _this.checkListShow()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ render: function () {
|
|
|
+ var container = $('.pre-search-list')
|
|
|
+ var html = ''
|
|
|
+ this.list.forEach(function (item) {
|
|
|
+ html += ('<div class="pre-search-item ellipsis" data-id='+ item.entId +'>' + item.name + '</div>')
|
|
|
+ })
|
|
|
+ container.html(html)
|
|
|
+ },
|
|
|
+ listShow: function (f) {
|
|
|
+ if (f) {
|
|
|
+ $('.pre-search-list').show()
|
|
|
+ } else {
|
|
|
+ $('.pre-search-list').hide()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ debounce: function (func, delay, immediate){
|
|
|
+ var timer = null;
|
|
|
+ delay = delay || 200
|
|
|
+ return function() {
|
|
|
+ var context = this;
|
|
|
+ var args = arguments;
|
|
|
+ if(timer) clearTimeout(timer);
|
|
|
+ if(immediate){
|
|
|
+ var doNow = !timer;
|
|
|
+ timer = setTimeout(function(){
|
|
|
+ timer = null;
|
|
|
+ },delay);
|
|
|
+ if(doNow){
|
|
|
+ func.apply(context,args);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ timer = setTimeout(function(){
|
|
|
+ func.apply(context,args);
|
|
|
+ },delay);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+entAssoc.init()
|