{% load i18n %}

{% ifequal obj 'Award' %}
<style>
  
    #tb tbody td img{
        height:30px;
        cursor:pointer;
    }
    
</style>
{% endifequal %}



<script type="text/javascript">
    $(document).ready(function(){    
        var page_length=10;
        {% ifequal obj 'Product' %}
            {% if request.user.company.cfg_company.product_photo %}            
                page_length=5;
            {% endif %}
        {% endifequal %}       


        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,          
            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();
                }
            });
        });    


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

       
        $('#tb tbody').on('click','img',function(){            
            var src=$(this).attr('src');
            var tt=$(this).closest('tr').find('a').text();
            if(tt==''){                
                tt=$(this).attr('tt');
            };
            var i="<div style='text-align:center;'><img src='"+src+"' style='height:400px;'></img></div>";
            $.OpenCfmDlg(tt,i);       
        });

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

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

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

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

        
        //2020-11-07
        $("[data-toggle='popover']").popover({
            html:true,
            placement:'bottom'
        });

        //2020-11-18
        $('#tb').on("click","td a.chk",function(event){
        event.preventDefault();  
        var url=$(this).attr('href');
        $.ajax({
                type:'POST',   
                url:url,
                //data:{'id':id},
                beforeSend: function(xhr,setting) {xhr.setRequestHeader("X-CSRFToken","{{ csrf_token }}")},
                success:function(d){                    
                    toastr.success("！",{timeOut: 800, positionClass: "toast-center-center"});
                    $.RefreshContent('{{request.path}}'); 
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                }
            });            
                   
    });     

    });
</script>



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



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



{% if dt %}
    <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-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>
    </form>
    <div class="clearfix"></div>
{% endif %}




<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>
