{% load i18n %}


<style> 
    #tb .btn{
        margin-top:0px;
        margin-bottom:0px;
    }
    #tb tbody td span.r {
        color:red;
        font-weight:bold;
    }
    
</style>



<script type="text/javascript">
    $(document).ready(function(){ 
        var table;
        var clmns=[                 
            {'title':'batch_id', 'data':'batch_id'}, 
            {'title':'上传时间', 'data':'tm'},    
            {'title':'压缩文件名', 'data':'file_name'},
            {'title':'瓶盖厂', 'data':'factory'},              
            {'title':'大小(MB)', 'data':'file_size'},
            {'title':'txt总行数', 'data':'lines'}, 
            {'title':'数据行', 'data':'cnt'},
            {'title':'实际写入', 'data':'cnt_ok'},
            {'title':'操作人', 'data':'user'},
            {'title':'txt文件名', 'data':'txts'},            
            {'title':'备注说明', 'data':'remark'},
        ];
       

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

        //2024-08-02
        $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
        var now=new Date();      

        $('#dt_to').datepicker('setDate',now);
        $('#dt_fr').datepicker('setDate',now.getDate() - 7);

        setDatePickerZh();   

        function tbRefresh(){
            var cid=$('#sel-company').val();
            var dt_fr=$('#dt_fr').val();
            var dt_to=$('#dt_to').val();

            $.ajax({
                type:'GET',                           
                url:"/bottlecap/ajax/zip/uploadlog/?dt_fr="+dt_fr+"&dt_to="+dt_to,                
                dataType:'json',                
                success: function(d) {
                    if (d.e==''){
                        table=$('#tb').DataTable({
                            dom: 'Bfrtip',
                            autoWidth: true,
                            pageLength: 10,
                            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
                            language:lng,	
                            columns:clmns,			
                            data:d.data,  
                            destroy:true,                            
                        });       

                        //2024-08-02 
                        $('#dt_fr').val(d.dt_fr);
                        $('#dt_to').val(d.dt_to);
    
                        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();
                                    }
                                });
                        }); 


                        // 隐藏batcg_id
                        $('#tb').DataTable().column(0).visible(false);
                        
                    }else{                        
                        toastr.error(
                            d.e,
                            "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }
                }
            });        
        };
        tbRefresh();
        $('.btn-qry').click(function(){
            tbRefresh();        
        });
        

        //2024-04-19
        $('#tb tbody').on("click","a",function(event){                
            var sub=$(this).attr('cid')+'\\'+$(this).attr('dt');   
            var fn=$(this).text();

            /*
            $.ajax({
                type:'GET',                           
                url:'/bottlecap/ajax/zip/downloadfile/?sub='+sub+"&fn="+fn,      
                //dataType:'json', 
                //data: {filename: fn},
                xhrFields: {
                    responseType: 'blob'
                },
                success: function (data) { 
                    var url = window.URL.createObjectURL(data);
                    var a = document.createElement('a');
                    a.href = url;
                    a.download = fn;
                    a.click();
                    window.URL.revokeObjectURL(url);                    
                }               
            });
            */

            window.location.href='/bottlecap/ajax/zip/downloadfile/?sub='+sub+"&fn="+fn;

        });
        

       
        
       
    });
</script>



<ol class="breadcrumb">
        <li>瓶盖码数据管理</li> 
        <li>绑定数据上传日志</li>            
</ol>




<div class='clear-fix'></div> 
<div class="x_panel">  
    <div class="form-inline" style='margin-bottom:15px;'>        
        <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'>
            <button class='btn btn-primary btn-qry'  style='margin-top:3px;margin-left:20px'>查询</button>
        </div>
    </div>

    <div  class="table-responsive">
    <table id='tb'  class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead></thead>
        <tbody></tbody>
        <tfoot>
            <th><input type="text" placeholder="batch_id"></th>
            <th><input type="text" placeholder="公司名称"></th>  
            <th><input type="text" placeholder="上传时间"></th>  
            <th><input type="text" placeholder="压缩文件名"></th>  
            <th><input type="text" placeholder="大小(MB)"></th>  
            <th><input type="text" placeholder="总行数"></th>  
            <th><input type="text" placeholder="数据"></th> 
            <th><input type="text" placeholder="写入"></th>  
            <th><input type="text" placeholder="操作人"></th>  
            <th><input type="text" placeholder="txt文件名"></th>  
            <th><input type="text" placeholder="备注说明"></th>  
        </tfoot>
    </table>
    </div>
    
</div>
