{% load i18n %}

<script type="text/javascript">
    $(document).ready(function(){
        var qty_uninbound={{qty_uninbound}};
        var cid={{cid|default:0}};
        if(cid=='212916'){//南京海邦 隐藏入库按钮
          $(".btn-inbound").hide();
        }
        if(qty_uninbound>0){
            $('#qty_uninbound').text(qty_uninbound+" {{unit}}待入库");
        }else{
            $('#qty_uninbound').text("");
            $(".btn-inbound").hide();
        };
        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,          
            data:{{data|safe}},    
            scrollY:        "400px",
            scrollCollapse: true,
            paging:         false,
            drawCallback: function () {
                var api = this.api();  

                //console.log(api.column(6,{page:'current'}).data().sum());
                //console.log($('#tb tfoot tr.tt').find('th.tt'));

                //$('#tb tfoot tr.tt').find('th.tt').html(
                //    api.column(6,{page:'current'}).data().sum()
                //);                   
            },              
        });     
        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();
                }
            });            
        }); 
        
              
        $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});        
        $('#dt_fr').val('{{dt_fr}}');  
        $('#dt_to').val('{{dt_to}}'); 
        setDatePickerZh();


        $('.btn-qry').click(function(){
            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)};

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

        $('.btn-inbound').click(function(){
            var date_from,date_to,url;           
            date_fr=$('#dt_fr').val();
            date_to=$('#dt_to').val();
            url='/mes/product/bind/inbound/?dt_fr='+date_fr+'&dt_to='+date_to;
            $.ajax({
                type:"get",                
                url:url,
                dataType: 'json',    
                success:function(data){   
                    console.log(data);      
                },   
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');                        
                }         
            });                
        });

        const rowData = {{ data|safe }}

        table.on("click","#btn-single-inbound",function(e) {
            e.preventDefault();
            const thisRow = rowData[table.row($(this).closest('tr')).index()];
            const url='/mes/product/bind/inbound';
            const data = {
                singleInbound: true,
                dt: thisRow[0],
                batchNo: thisRow[4],
                productId: thisRow[10],
                storeId: thisRow[11]
            };
            console.log(data);
            $.ajax({
                type:"get",
                url:url,
                data: data,
                dataType: 'json',
                success:function(res){
                    console.log(res);
                    $('.btn-qry').trigger('click');
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                }
            });
        });

         //2024-09-03
        $('#tb').on("click",".btn-details",function(e) {
            //e.preventDefault();
            var url=$(this).attr('href');            
            $.ajax({
                type:"get",
                url:url,                
                dataType: 'json',
                success:function(d){
                    
                    $('#tb-details').DataTable({
                        dom: 'Bfrtip',
                        autoWidth: true,
                        buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
                        language:lng,          
                        data:d,  
                        destroy:true,
                        //scrollY:        "400px",
                        //scrollCollapse: true,
                        //paging:         false,
                        //destroy:true;
                    });
                    
                    
                    $('#dlg-details').modal('show');
                
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                }
            });
        });


    });
</script>



<ol class="breadcrumb">
        <li>{% trans "进销存报表" %}</li>
        <li>{% trans "标签绑定产量查询" %}</li>     
</ol>



<form role="form"  class="form-inline" style="margin-top:0px;">
    <div class="col-sm-3 input-group">
        <span class="input-group-addon">{% trans "开始日期"%}</span>
        <input class="datepicker form-control" id="dt_fr"  value="{{dt_fr}}"/>
    </div>
    <div class="col-sm-3 input-group">
        <span class="input-group-addon">{% trans "结束日期"%}</span>
        <input class="datepicker form-control" id="dt_to" value="{{dt_to}}"/>
    </div>

    <div class="col-sm-1 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>       
    </div>
    <div class='col-sm-4 input-group'>
        <span  id="qty_uninbound" class='col-sm-10'  style='text-align:right;padding-top:8px;'></span>  

            <a type="button" class='btn btn-primary btn-inbound'>
                {% trans '入库' %}
            </a>
             
    </div>
</form>

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



<div class="x_panel">
        <div  class="table-responsive">

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



<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" id="dlg-details">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">绑定明细：</h4>
            </div>
            <div class="modal-body">                
                <table id="tb-details" class="table table-striped table-bordered dt-responsive" width="100%" >
                    <thead>
                        <tr>
                            <th>箱标</th>
							<th>盒标</th>							  
                            <th>NFC</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                    <tfoot><tr>
                        <th><input type="text" placeholder="箱标"></th> 
                        <th><input type="text" placeholder="盒标"></th> 
                        <th><input type="text" placeholder="NFC"></th>                         
                    </tr></tfoot>
                </table>
            </div>  
            <div style='min-height:30px;'></div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

