{% load i18n %}


<style>
    #tb tbody .r{
        font-weight:bold;
        color:red;
    }
    tbody tr.row_selected{
        color:black;
        background: -moz-linear-gradient(center top , #ff8e1f, #ff7217) repeat scroll 0 0 rgba(0, 0, 0, 0);
        background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ff8e1f), to(#ff7217));
    }
    #tb tfoot input{
        width:95%;
    }

</style>


<ol class="breadcrumb">
    <li>  {% trans "进出存报表" %}</li> 
    <li> 标签替换 </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(){     
            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)};

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

        {% ifnotequal params.dt_fr '' %}
            $('#dt_fr').val('{{params.dt_fr}}');
        {% endifnotequal  %}
        {% ifnotequal params.dt_to '' %}
            $('#dt_to').val('{{params.dt_to}}');
        {% endifnotequal  %}
       
       
       
        var tb_batch=$('#tb').DataTable({
            //"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            //"bLengthChange":true,
            dom: 'Bfrtip',
            autoWidth: false,
            buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
            language:lng,  
            columns:{{clmns|safe}},
            data:{{data|safe}}
        });       

        var flds='';
        {% for c in  clmns %}
            flds=flds+'<th><input type="text" placeholder="{{c.title}}" /></th>';                            
        {% endfor %}
        $('#tb tfoot').html(flds);
        
        tb_batch.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        });  



         //单击，选择行
        $("#tb tbody tr").click(function (e) {
            $('#tb tbody tr').removeClass('row_selected'); 
            $(this).addClass('row_selected');
            $('form .btn-delete').removeClass('disabled');
        });
        

        $('#tb').on("click","td a.btn-view",function(event){
            //$(event.target.parentNode).addClass('row_selected');
             event.preventDefault();
             $.OpenDlg($(this).attr('href'),'标签替换-明细列表',1000,700);
        });   


        //编辑 
        $(".btn-save").click(function () {
            var url='/inventory/label/replace/update/'+$('#row-id').val()+'/?obj=details'+
                '&code0='+$('#code0').val()+'&code='+$('#code').val()+'&remark='+$('#remark').val();                      
            $.ajax({
                type:'GET',
                processData: false,               
                url:url,
                success:function(data){                    
                    if(data.e==''){
                        toastr.success('修改完成!', '操作成功：',
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }else{
                        toastr.error(data.e, "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }                      
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {                                      
                    $('#dlg-edit').modal("hide");                    
                    alert('连接服务器失败');                        
                }
            });    
        });

        

        //整笔删除 
        $(".btn-delete").click(function () {   
            if(confirm("确定要将这笔替换数据全部删除吗?")){
                var batch_id=tb_batch.rows('.row_selected').data()[0].DT_RowId;
                var url='/inventory/label/replace/delete/'+batch_id+'/?obj=batch'; 
                $.ajax({
                    type:'GET',
                    processData: false,               
                    url:url,
                    success:function(data){                    
                        if(data.e==''){
                            toastr.success('删除完成!', '操作成功：',
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );
                        
                            tb_batch.rows('.row_selected').remove().draw(false);

                        }else{
                            toastr.error(data.e, "操作错误：",
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );
                        };
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {                                      
                        $('#dlg-edit').modal("hide");                    
                        alert('连接服务器失败');                        
                    }
                });
            };
        });        


    });
</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-btn'>
            <a type="button" class='btn btn-primary btn-qry'>
                <span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans '查询' %}
            </a>           
        </span>   
        <span class='input-group-btn'>
            <a type="button" class='btn btn-danger btn-delete disabled'>
                <span class='glyphicon glyphicon-remove' style='padding-right:5px;'></span>{% trans '删除' %}
            </a>
        </span>
    </div>
  
    


</form>
<div class="clearfix"></div>
<div id="inventory-list" class="table-responsive">
    <div class='x_panel'>    
    <table id="tb" class="table table-striped table-bordered dt-responsive" width="100%" >
        <thead></thead>
        <tbody></tbody>
        <tfoot></tfoot>
    </table>   
    </div>
</div>





<!--编辑修改明细对话框-->
<div class="modal fade bs-example-modal-lg" id='dlg-edit' tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="bgModalLabel">编辑修改：</h4>
            </div>
            
            <div class="modal-body"> 
                <form role="form"       class="form-horizontal">             
                <input type='hidden' id='row-id' />
                <div class="form-group ">
                    <label class="col-sm-2 control-label ">{% trans '旧标签号码:' %} </label>
                    <div class="col-sm-10"><input id="code0" class="form-control"></div>
                </div>
                <div class="form-group ">
                    <label class="col-sm-2 control-label ">{% trans '新标签号码:' %} </label>
                    <div class="col-sm-10"><input id="code"  class="form-control"></div>
                </div>
                <div class="form-group ">
                    <label class="col-sm-2 control-label ">{% trans '备注说明:' %} </label>
                    <div class="col-sm-10"><input id="remark"  class="form-control"></div>
                </div>    
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-save"  data-dismiss="modal">保存</button>  
                <button type="button" class="btn btn-default"  data-dismiss="modal">取消</button> 
            </div>
        </div>
    </div>
</div>


