<style type="text/css">
          .search{position: absolute;z-index: 111; background: white;padding: 10px;min-height: 100px; min-width: 900px; border: 1px solid #eee; border-radius: 2px; display: none }
          .search p{line-height: 35px; color: #888888; cursor: pointer;}
</style>

 <script>
 	  layui.use(['form'], function () {
          $ = layui.jquery;
      
        //  $('#title').on('input',function(){
        //    console.log(1111)
        //   //  throttle(change_title,$(this))
          
        // })
       $("body").on("click input",".title", function(e){  
          throttle(change_title,$(this))
        })
       //点击搜索表中一行
       $("body").on("click",".str", function(e){  
           var title=$(this).attr("title");
           var id=$(this).attr("vid");
           var company_id=$(this).attr("company_id");
           layer.confirm('你确定用'+title+"公司信息覆盖当前拜访记录吗", function (index) {
               layer.close(index);
               $.post("<?=u("app","index",array("act1"=>"fugai"))?>",{id:id,company_id:company_id,id:id}, function(res) {
                     if (res.code==0){
                       jiantable.reload();
                       miniAdmin.success(res.msg)
                      
                     }else{
                        miniAdmin.error(res.msg)
                     }
                    
                   
           },"json");
               
           })
        })
       function change_title(){
       
          if (this.val()=="" || !this.val()){
             $(".search").hide()
             return
          }
           var that=this
           $.post("<?=u("app","index",array("act1"=>"search_v"))?>",{q:this.val(),id:this.attr("id")}, function(res) {
              
              if (res.count==0){
                  $(".search").hide()
                } else{
                	console.log("可以显示search层")
                  $(".search").show();
                  	 var x = that.offset().top;
			         var y = that.offset().left;
			         $(".search").offset({top:x+30,left:y})
                     $(".search").html(res.data)
                }
                   
           },"json");
      }
     function throttle(method, context) {
	     clearTimeout(method.tId);
	     method.tId = setTimeout(function(){
	     
	         method.call(context);
	     },200);
	     } 
        $(document).keydown(function(event){
			 if(event.keyCode == 9){
			     if ($(":focus").length > 0) { 
                      var class1=$(":focus").attr("class");
                      if (class1.indexOf("layui-table-edit") != -1 || class1.indexOf("title") != -1){
                          var obj=$(":focus");
                          var f=obj.parents("td").next();
                    
                          console.log(f.html())
                          f.trigger("click")
                      }
                  }

                    return false;
             }
       });


       $("body").on("blur",".title", function(e){  
          $.post("<?=u("app","index",array("act1"=>"visitCompanyTitle"))?>",{
                id:$(this).attr("id"),
                value:$(this).val()
             }, function(data) {
                  layer.closeAll('loading');         
                  if (data.code==0){
                       //jiantable.reload();
                    }else{
                       miniAdmin.error(data.msg);     
                    }
                                   
            },"json");
        });


	     $(document).bind('click', function(e) {  
                var e = e || window.event; //浏览器兼容性   
                var elem = e.target || e.srcElement;  
                while (elem) { //循环判断至跟节点，防止点击的是div子元素   
                    if (elem.id && elem.id == 'search') {  
                        return;  
                    }  
                    elem = elem.parentNode;  
                }  
                $('#search').css('display', 'none'); //点击的不是div或其子元素   
            });  

 	 })
   

   
 </script>	