123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- var req_base = '/'
- function changeHorse(timp) {
- return Math.floor(timp / 1000 / 60 / 60)
- }
- // 格式化数字,没三位添加分号
- function toThousands(num) {
- return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
- }
- $(function () {
- // 搜索框类型选择
- $("#index .search .tips span").on("click",function(){
- var i = $(this).index();
- $(this).parent().find('i').animate({
- left: 14+(95*i) +'px'
- },200)
- $("#index .search .tips span").removeClass('active')
- $(this).addClass('active')
- if(i == 0){
- $("#zbIndex").attr("action", '/jylab/supsearch/index.html');
- $("#zbIndex .ser").attr("name",'keywords')
- $("#index .search .index_search_thikn").hide()
- $("#zbIndex input").attr('placeholder', '请输入您想要查询的招标信息')
- }else{
- $("#zbIndex").attr("action", '/jylab/entSearch/index.html');
- $("#zbIndex .ser").attr("name",'searchvalue')
- $("#zbIndex input").attr('placeholder', '请输入企业名称')
- }
- })
- function thinkList(){
- var entName = $("#index .ser").val()
- $.ajax({
- type: "POST",
- url: req_base + 'jylab/bidsearchforent/recList',
- data: {
- entName: entName
- },
- success: function (result) {
- if(result.recList){
- $("#index .search .index_search_thikn").show()
- var str = ''
- result.recList.forEach(function(v,i){
- str += '<li><a href="/jylab/bidsearchforent/index.html?searchvalue='+v.name+'">'+v.name+'</a></li>'
- })
- $("#index .search .index_search_thikn ul").html(str)
- }else{
- $("#index .search .index_search_thikn").hide()
- }
- },
- })
- }
- function debounce(fn,delay) {
- var timeout = null; // 创建一个标记用来存放定时器的返回值
- return function (e) {
- // 每当用户输入的时候把前一个 setTimeout clear 掉
- clearTimeout(timeout);
- // 然后又创建一个新的 setTimeout, 这样就能保证interval 间隔内如果时间持续触发,就不会执行 fn 函数
- var _this = this
- timeout = setTimeout(function () {
- fn.apply(_this, arguments);
- }, delay);
- };
- }
- $("#index .ser").bind("input propertychange",function(){
- if($("#zbIndex").attr("action") == '/jylab/bidsearchforent/index.html'){
- debounce(thinkList(),500)
- }
- })
- });
- (function animateUp(){
- var obj = $('.CfadeInUp');
- var objH= $('.CfadeInUp').outerHeight();
- var num = [];
- var wH = $(window).height();
- var wScrollTop = $(window).scrollTop();
- // 获取页面所有obj的top位置,存入数组
- for(var i=0; i<obj.length;i++){
- num.push(obj.eq(i).offset().top+(objH/3));
- }
- // console.log(num)
- // 循环数组,判断obj的位置是否在可视区中
- function judgeTop(){
- for(var j=0; j<num.length;j++){
- if (num[j] >= wScrollTop && num[j] < (wScrollTop+wH-50)) {
- console.log(j)
- if(j == 0){
- obj.eq(j).css({
- 'animation-name':'CfadeInUp',
- 'animation-duration': 0.8 +'s',
- 'opacity':'1'
- });
- }else{
- obj.eq(j).css({
- 'animation-name':'CfadeInUp',
- 'animation-duration': 1.4 +'s',
- 'opacity':'1'
- });
- }
- }
- }
- };
- // 页面初始化时先调用一次
- judgeTop();
- // 触发滚动事件调用判断函数
- $(window).scroll(function(event) {
- wH = $(window).height();
- wScrollTop = $(window).scrollTop();
- 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()
|