{% load i18n %}


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

    #dlg-log .modal-body{
        max-height:600px;
        overflow-y:auto;
    }

    
</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='',cndtn='',voucher='';     
            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)};
            params.push('cndtn='+$('#sel-cndtn').val());
            params.push('voucher='+$('#sel-voucher').val());
            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  %}    
        
        $('#sel-cndtn').val('{{cndtn}}');
        $('#sel-voucher').val('{{voucher}}');

         var table=$('#tb').DataTable({           
            dom: 'Bfrtip',                                              
            autoWidth: false, 
            buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
            language:lng, 
            columns:{{clmns|safe}},
            data:{{data|safe}},            
            createdRow: function( nRow, aData, iDataIndex ) {   
                $('td:eq(1)', nRow).html( 
                    '<a href="/inventory/batch/details/'+aData.batch_id+'/" >'+aData.batch_code+'</a>' 
                );
                if ( !$.isEmpty(aData.cnt_push)  ) {
                    $('td:eq(9)', 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+'">'+aData.cnt_push+
                        '</button>' 
                    );
                };

            }                        

        });
        table.column(0).visible(false);
                    
        
        $('#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'); 
                }        
            });
        });


        $('#tb').on("click","td a",function(event){
            $(event.target.parentNode).addClass('row_selected');
             event.preventDefault();
             $.OpenDlg($(this).attr('href'),'订单{{voucher.name}}-明细列表',1000,700);
        });   
        

    });

   
</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 class="col-sm-2 input-group">
        <span class="input-group-addon">{% trans "单据类型" %}</span>
        <select class="form-control" id="sel-voucher">
            <option value=''>所有</option>            
            <option value='2'>销售出库</option>
            <option value='4'>销售退库</option>            
        </select>
    </div>
    <div class="col-sm-2 input-group">
        <span class="input-group-addon">{% trans "查询条件" %}</span>
        <select class="form-control" id="sel-cndtn">                        
            <option value=''>所有</option>            
            <option value='nosent'>从未推送</option>
            <option value='success'>已推送成功</option>
            <option value='nosuccess'>已推送但未全部成功</option>            
        </select>
    </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" max-height='500px'>
    <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" max-height="600px;">
                <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>







