{% load i18n %}

{% ifequal obj 'Award' %}
<style>
  
    #tb tbody td img{
        height:30px;
        cursor:pointer;
    }
    
</style>
{% endifequal %}
<style> 
    .word-wrap{
        width: 100%;white-space: normal;word-wrap: break-word;word-break: break-all;
    }
	.ui-datepicker{
		z-index:1051 !important;
	}
	.modal-footer{
		clear: both;
	
	}
	.ui-autocomplete{
		z-index: 9999 !important;
	}
</style>



<script type="text/javascript">
    $(document).ready(function(){    
        var page_length=10;     

        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,
			
			{% if order %}
            order: {{order|safe}},
			{% endif %}
			
            data:{{data|safe}}
        });      
        table.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        });    
		
		$('#id_company_name').autocomplete({
			source: function(request, response) {
                $.ajax({
                    url: '/obj/ajax/autocomplete/agent/',
                    dataType: "json",
                    data: {
                        term:   $("#id_company_name").val()
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },
			select: function (event, ui) {
				$("#id_company").val(ui.item.value);
				$("#id_company_name").val(ui.item.label);
				return false;
			}
		});
    
		var url = '/company/saleman/manage/?obj=agent&uid={{uid}}';
        $('.btn-save').click(function () {
            SubmitThisForm('#form1');
        });
		
		$(".btn-delete").click(function(){
			var id = $(this).data("id");
			console.log(id)
			$.ajax({
				type: 'post',
                url, 
				data:{
					company_id:id,
					delflag:1
				},
                success: function(html) {

                    $('#bg-modal .modal-body').html(html); 
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');                        
                }
			})
		})
		
		SubmitThisForm = function (form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url,    
                    success: function(html) {

                        $('#bg-modal .modal-body').html(html); 
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert('连接服务器失败');                        
                    }
                });
                return; // 阻止表单自动提交事件
		};
	});
</script>



<ol class="breadcrumb">
        <li>{{subtt.0}}</li>
        <li>{{subtt.1}}</li>     
</ol>


<form role="form" method='POST' enctype="multipart/form-data" class="form-horizontal" id="form1"> {% csrf_token %}
   
    <div class="form-group">
        <label class="col-sm-2 control-label ">{% trans '公司名称:' %} </label>
        <div class="col-sm-8">
            <input id='id_company_name' class='form-control' />
			<input id="id_company" name="company_id" type="hidden" />
        </div>
    </div>  

    <div class="form-group">
        <div class="col-sm-offset-2">
            <a class="btn btn-default btn-save">添加</a>
        </div>
    </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>
                {% for c in clmns %}
                    <th><input type="text" placeholder="{{c}}"></th>            
                {% endfor %}            
            </tfoot>
            </table>
        </div>
    </div>
</div>
 