{% load i18n %}





<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,          
            data:{{data|safe}},
            drawCallback: function () {
                var api = this.api();     
                $( api.column(5).footer() ).html(                   
                   api.column(5,{page:'current'}).data().sum()
                );
                $( api.column(6).footer() ).html(                   
                    api.column(6,{page:'current'}).data().sum()
                );
                $( api.column(7).footer() ).html(                   
                   $.formatNum(api.column(7,{page:'current'}).data().sum(),2)
                );
                $( api.column(8).footer() ).html(                   
                    $.formatNum(api.column(8,{page:'current'}).data().sum(),2)
                );
                $( api.column(9).footer() ).html(                   
                    $.formatNum(api.column(9,{page:'current'}).data().sum(),2)
                );
                
                $('#data-content .gtt').text($.formatNum(api.column(9).data().sum(),2));
            }



        });     
       


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


        $('#data-content').on("click","a.btn-obj-add",function(){     
            event.preventDefault(); 
            $.RefreshContent($(this).attr('href'));            
        });  
        $('#tb').on("click","td a",function(event){
            event.preventDefault();    
            $.RefreshContent($(this).attr('href'));            
        });     

       

        
            $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
            $('.datepicker').datepicker('setDate',new Date());
            setDatePickerZh();

            $('#dt_fr').val('{{date_from}}');
            $('#dt_to').val('{{date_to}}');
            $('#agent_id').val('{{agent_id}}');
            $('#agent_label').val('{{agent_name}}');

            $('.btn-qry').click(function(){
                var date_from,date_to,agent_id;
                date_fr=$('#dt_fr').val();
                date_to=$('#dt_to').val();
                agent_id=$('#agent_id').val();
                var params=[];
                if(date_fr!=''){params.push('date_from='+date_fr)};
                if(date_to!=''){params.push('date_to='+date_to)};
                if(agent_id!='' && $('#agent_label').val()!=''){
                    params.push('agent_id='+agent_id);
                };


                if(params.length==0){
                    bootbox.alert("{% trans '请先输入查询条件！'%}");
                }else{
                    $.RefreshContent('{{request.path}}?'+params.join('&'));
                }
            });
       
    });
</script>




<div>
    <ol class="breadcrumb">
        <li>渠道促销</li>
        <li>扫码奖励汇总</li>     
    </ol>

    <form role="form"  class="form-inline" style="margin-top:0px;padding-left:10px;">
        <div class="col-sm-2 input-group">
            <span class="input-group-addon">{% trans "开始日期"%}</span>
            <input class="datepicker form-control" id="dt_fr" />
        </div>
        <div class="col-sm-2 input-group">
            <span class="input-group-addon">{% trans "结束日期"%}</span>
            <input class="datepicker form-control" id="dt_to" />
        </div>    
        <div class='col-sm-3 input-group'>
            <input class='form-control' placeholder='所有经销商' id='agent_label'/>
            <input type='hidden' id='agent_id' />
        </div>
        <div  class="col-sm-2 input-group">
            <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="col-sm-2 input-group">
            扫码奖励总计：<span class='gtt' style='font-weight:bold;'></span>        
        </div>


    </form>
    <div class="clearfix"></div>

    <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 %}
                    {% if forloop.first %}
                        <th>合计：</th>
                    {% else %}
                        <th></th>
                    {% endif %}
                {% endfor %}            
            </tfoot>
            </table>
        </div>
    </div>
    </div>
</div>
