$('.yonghu-choice').attr('readonly',true);
			$.ajax({
				url:yonghu_choice,
				type:"get",
				data:{},
				dataType:"json",
				success:function(r){
					$(".yonghu-choice").each(function(){
						var name = $(this).attr('name');
						$(this).attr('name','');
						var html = '<input type="hidden" name="'+name+'" value="" class="hidden-id">'+
					        '<div class="user-choice choice" style="">'+
					        	'<div class="search-input">'+
					        		'<input type="text" name="keyword" lay-verify="" placeholder="请输入关键字" autocomplete="off" class="layui-input">'+
					        		'<i></i>'+
					        	'</div>'+
					        	'<div class="layui-row">'+
									'<table class="tree-table">'+
										r+
									'</table>'+
									'<table class="search-table"></table>'+
					        	'</div>'+
						    '</div>';
					    $(this).parent().append(html);
					});
					
					
					$(".tree-table").treeTable({
						indent : 20,
						clickableNodeNames:true
					});
				},
				error:function(){
					layer.msg('网络错误！',{anim: 6});//错误提示
				}
			});
  $(document).ready(function(){
  	$('body').on('click','.user-choice table tr',function(e){
		var type = $(this).data('type');
		if (type == 1) {
			var uid = $(this).data('value');
			var name = $(this).data('name');
			$(this).parents('div.user-choice').prev('input[type=hidden]').val(uid).prev('input[type=text]').val(name);
			$(this).parents('div.user-choice').hide();
		}
		e.stopPropagation();
	});

    $('body').on('keyup','.user-choice input',function(e){
    	var txt=$(this).val();
		if (txt!="") {
			$(this).parents('.user-choice').find(".search-table").show();
			$(this).parents('.user-choice').find(".tree-table").hide();
	      $.ajax({
	          url:get_yonghu,
	          type:"get",
	          data:"txt="+txt,
	          dataType:"json",
	          success:function(data){
	            var sousuo = data.district;
	            $(".search-table tr").remove();
	            for(var i in sousuo){
	              var tr=$("<tr></tr>");
	              $(tr).attr("data-name",sousuo[i]['ygmingcheng']);
	              $(tr).attr("data-value",sousuo[i]['id']);
	              $(tr).attr("data-type",1);
		          $(tr).html('<td><i class="layui-icon" style="padding-left: 20px">&#xe612;</i>'+sousuo[i]['ygmingcheng']+'</td>');
		          $(".search-table").append(tr);
	            }
	            
	          }
	        });
		}else{
			$(this).parents('.user-choice').find(".search-table").hide();
			$(this).parents('.user-choice').find(".tree-table").show();
		}

      e.stopPropagation();
    });
    $('body').on('click','.user-choice .search-input input',function(e){
      e.stopPropagation();
    });
    $('body').on('click','.user-choice',function(e){
      e.stopPropagation();
    });

	$('.yonghu-choice').click(function(e) {
		var obj = $(this).next('input[type=hidden]').next('.user-choice');
		$('.choice').hide();
		var is_more_open = obj.css('display');
		if (is_more_open == 'none') {
			obj.show();
		}else{
			obj.hide();
		}
		e.stopPropagation();
    })
	$(document).click(function(){ 
      var obj = $('.choice');
      obj.hide();
    }) 
  })