{% load i18n %}


<style>  
    #tb tbody td img{
        height:30px;
        cursor:pointer;
    }
    
</style>

<style> 
    .word-wrap{
        width: 100%;white-space: normal;word-wrap: break-word;word-break: break-all;
    }
</style>



<script type="text/javascript">
    $(document).ready(function(){
        var table;
        function RefreshTable(){           
            table=$('#tb').DataTable({
                dom: 'Bfrtip',
                autoWidth: true,
                ordering:false,
                searching: false,
                pageLength: 10,
                buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
                language:lng,

			    "destroy":true,
			    "processing": true,
                "serverSide": true,                
                "ajax": {
                    "url":"/company/ajax/datatable/agent/",
                    "data":function(params){   
                        var agent_name=$('#agent_name').val(),level_id=$('#level_id').val(),is_golden=$('#is_golden').val();
                        var parent_id=$('#parent_id').val(),cell_phone=$('#cell_phone').val();
                        params.name__icontains=agent_name;                    
                        params.level_id=level_id;   
                        params.is_golden=is_golden;
                        params.parent_id=parent_id;
                        params.cell_phone=cell_phone;
                    }
                }
            });       
        };   
        
         
        $(".btn-obj-add").click(function () { 
            event.preventDefault();
            $.RefreshContent($(this).attr('href'));        
        });

        $('.btn-qry').click(function(){
            RefreshTable();
        });

        $('#tb').on("click","td a",function(event){			
            event.preventDefault();   
            $.RefreshContent($(this).attr('href'));            
        });    	

        
		RefreshTable();

        $('#parent_name').autocomplete({                
            source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/agent/?query_all=1',
                    dataType: "json",
                    data: {
                        term:   $("#parent_name").val() ,//搜索栏里的内容
                        company_id:  {{request.user.company_id}} //额外参数
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },   
            select: function (event, ui) {
                $("#parent_id").val(ui.item.value);
                $("#parent_name").val(ui.item.label);
                return false;
            }
        });

    });
   
</script>



<ol class="breadcrumb">
    <li>{{tt1}}</li>
    <li>{{tt2}}</li>     
</ol>

<form role="form"  class="form-inline" style="margin-top:0px;margin-left:5px;">
    <div class="col-sm-5">   
        <input id='agent_name' class='form-control' style='width:200px;'  placeholder='经销商名称(模糊查询)' />
        <input id='parent_id' type='hidden' />
        <input id='parent_name' class='form-control' style='width:200px;' placeholder='所属父级' />          
        <input id='cell_phone' class='form-control' style='width:120px;'  placeholder='联系电话' />
    </div>
    <div class='col-sm-4'>
        <span>经销商层级：</span>
        <select class='form-control' id='level_id'>
            <option value='2'>一级</option>
            <option value='4'>二级</option>
            <option value='5'>三级</option>
            <option value='' selected="selected">所有</option>
        </select>


        {% ifequal request.user.company_id 19651 %}
        <span style='margin-left:20px;'>是否金牌客户：</span>
        <select class='form-control' id='is_golden'>
            <option value='1'>是</option>
            <option value='0'>否</option>
            <option value='' selected="selected">所有</option>
        </select>
        {% endifequal %}



    </div>


    <div class='col-sm-1'>
        <span class='input-group-btn'>
            <a type="button" class='btn btn-primary btn-qry'>
                <span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans '查询' %}
            </a>
        </span>
    </div>

        <div class="pull-right">
            <span class='input-group'> 
				{% if btn_name %}
					<a type="button" class='btn btn-obj-add l-a create-btn' href='{{btn_url}}'>
						{% trans btn_name %}
					</a> 
				{% endif %}
				
				{% if show_add %}  
                <button type="button" class='btn btn-obj-add l-a create-btn' href='{{murl}}'>
                    <span class='glyphicon glyphicon-plus' style='padding-right:5px;'></span>{% trans '新建' %}
                </button>
				{% endif %}
				
            </span>
        </div>
</form>

<div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div  class="table-responsive">
            <table id='tb'  class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
            <thead>
                {% for c in clmns %}
                    <th>{{c}}</th>
                {% endfor %}
            </thead>
            <tbody></tbody>
            <tfoot>                  
            </tfoot>
            </table>
        </div>
    </div>
</div>
