{% load i18n %}

<style>

    .inventory-tt .g{
        color:green;
        margin-right:10px;
    }
</style>





<script type="text/javascript">    
    $(document).ready(function(){    
        
        var table=$('#tb-dlg').DataTable({
            dom: 'Bfrtip',
            autoWidth: false,
            buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
            language:lng,            
            destroy:true,
            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();
                }
           });
        }); 

     

        $('.btn-check').click(function(){
                var msg = "您确定要将这些替换记录生效吗？\n\n请确认！";                 
                if (confirm(msg)==true){
                    $.ajax({
                        type:'GET',
                        processData: false,
                        contentType: 'application/json; charset=utf-8',
                        url:'/inventory/label/replace/check/{{batch.id}}/?',
                        success:function(data){
                                if (data.e==''){
                                    var date_from,date_to;           
                                    date_fr=$('#dt_fr').val();
                                    date_to=$('#dt_to').val();
                                    var params=[];
                                    if(date_fr!=''){params.push('dt_fr='+date_fr)};
                                    if(date_to!=''){params.push('dt_to='+date_to)};
                                    $("#bg-modal").modal('hide');                
                                    $.RefreshContent('/inventory/label/replace/list/?'+params.join('&'));   
                                }else{
                                    toastr.error(
                                        data.e,
                                        "错误：",
                                        {timeOut: 800, positionClass: "toast-center-center"}
                                    );                        
                                }      
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                                alert('连接服务器失败');
                                return;
                        }
                    }); 
                
                };        
                         
        });    


    });
</script>

<div class='inventory-tt'>
    <span>替换来源:<span class='g'>{{batch.src}}</span></span>  
    <span>替换记录总数:<span class='g'>{{batch.qty}}</span></span>   
    {% if  batch.checked_by %}
        <span>审核人:<span class='g'>{{batch.checked_by}}</span></span>
        <span>时间:<span class='g'>{{batch.checked_tm}}</span></span>
    {% else %}
        {% if batch.can_edit %}
            <button type="button" class="btn btn-primary btn-sm btn-check" >审核通过</button> 
        {% endif %}
    {% endif %}
</div>

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


<div id="inventory-list" class="table-responsive">    

    <table id="tb-dlg" class="table table-striped table-bordered dt-responsive" width="100%">
        <thead>
            {% for c in clmns %}
                <th>{{c}}</th>
            {% endfor %}            
        </thead><tbody></tbody>
        <tfoot>
            {% for c in clmns %}
                <th><input tyext='text' placeholder='{{c}}' /></th>
            {% endfor %}            
        </tfoot>
    
    </table>       
</div>



