{% load i18n %}


<style>
    #tb tbody .r{
        font-weight:bold;
        color:red;
    }

    
</style>


<ol class="breadcrumb">
    <li>  {% trans "物流查询" %}</li> 
    <li> {% trans  "数据推送" %}</li> 
</ol>



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

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

          

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

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


        {% ifnotequal dt_fr '' %}
            $('#dt_fr').val('{{dt_fr}}');
        {% endifnotequal  %}
        {% ifnotequal dt_to '' %}
            $('#dt_to').val('{{dt_to}}');
        {% endifnotequal  %}            
       
    
        
        function RefreshData(){
            date_fr=$('#dt_fr').val();
            date_to=$('#dt_to').val();            
            var params=[];      
            if(date_fr!=''){params.push('date_fr='+date_fr)};
            if(date_to!=''){params.push('date_to='+date_to)};
            var url='/thirdparty/delivery/post/data/?'+params.join('&');
            $.ajax({
                type:'GET',
                processData: false,
                contentType: 'application/json; charset=utf-8',
                url:url,
                success:function(data){
                    var table=$('#tb').DataTable({           
                        dom: 'Bfrtip',
                        column:data.clmns,                       
                        autoWidth: false, 
                        buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
                        language:lng, 
                        columns:data.clmns,
                        data:data.data,   
                        createdRow: function( nRow, aData, iDataIndex ) {                          
                            if ( !$.isEmpty(aData.tm_push) ) {
                                $('td:eq(11)', nRow).html( 
                                    '<button class="btn btn-primary btn-xs btn-log" batch_code='+aData.batch_code+' '+
                                        'href="/thirdparty/delivery/post/log/?batch_id='+aData.batch_id+'">查看</button>' 
                                );
                            }                              
                        }   
                    });
                    table.column(0).visible(false);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                }
            });          
            

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

        RefreshData();

        $('#tb').on('click','.btn-log',function(){
            var url=$(this).attr('href');
            var code=$(this).attr('batch_code')
            $.ajax({
                type:'GET',
                processData: false,
                contentType: 'application/json; charset=utf-8',
                url:url,
                success:function(data){
                    var html='';
                    for (var i in data){
                        html=html+"<tr>"+
                            "<td>"+data[i].time+"</td>"+
                            "<td>"+data[i].result+"</td>"+
                        "</tr>";                    
                    };                    
                    $('#dlg-log .modal-title').html("单据编号:"+code);
                    $('#tb-post-log tbody').html(html);
                    $('#dlg-log').modal('show'); 
                }        
            });
        });

    });

   
</script>

<form role="form"  class="form-inline" style="margin-top:0px;">
    <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 style="float:right;">
        <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>
<div id="post-list" class="table-responsive">
    <div class='x_panel'>    
    <table id="tb" class="table table-striped table-bordered dt-responsive" width="100%" >        
        <thead><tr>
            {% for c in clmns %}
                <th>{{c.title}}</th>
            {% endfor %}                       
        </tr></thead>
        <tbody></tbody>
        <tfoot>
            {% for c in clmns %}
                <th><input type="text" placeholder="{{c.title}}"></th>
            {% endfor %}
        </tfoot>
    </table>   
    </div>
    
</div>


<div class="modal fade" id="dlg-log" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"></h4>
            </div>
            <div class="modal-body">
                <table id='tb-post-log' class="table table-striped table-bordered dt-responsive" width="100%" >        
                <thead><tr>
                    <th>推送时间</th>
                    <th>返回信息</th>
                </tr></thead>
                <tbody></tbody>                
                </table>           
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>                
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>



