{% load i18n %}


<style> 
    #tb .btn{
        margin-top:0px;
        margin-bottom:0px;
    }

    #tb .btn-generate{
        margin-left:5px;
    }
</style>



<script type="text/javascript">
    $(document).ready(function(){     
        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: 10,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,	
            columns:{{clmns|safe}},			
            data:{{data|safe}},
            //如果业务通知单码数据未从内网同步到云平台，显示同步按钮;zip文件生成按钮 
            createdRow: function( nRow, aData, iDataIndex ) {                          
                if ( aData.qty_sync==0 ) {
                    $('td:eq(10)', nRow).html( 
                        '<button class="btn btn-primary btn-xs btn-sync"  '+
                            'href="/bottlecap/ajax/codes/sync/?inform_id='+aData.inform_id+'">同步</button>' 
                    );                    
                }else{
                    if(aData.zipfile==''){
                        if(aData.codetype=='盖外码'){
                            $('td:eq(11)', nRow).html(
                                '<label>'+
                                '<input name="clmns'+iDataIndex+'" type="radio" value="1" checked/>1列</label>'+ 
                                '<label>'+
                                '<input name="clmns'+iDataIndex+'" type="radio" value="2" />2列</label>'+
                                '<button class="btn btn-primary btn-xs btn-generate"  '+
                                'href="/bottlecap/ajax/zip/generate/?inform_id='+aData.inform_id+'">生成</button>'
                            )
                        }else{
                            $('td:eq(11)', nRow).html(
                                '<button class="btn btn-primary btn-xs btn-generate"  '+
                                'href="/bottlecap/ajax/zip/generate/?inform_id='+aData.inform_id+'">生成</button>' 
                            )
                        }                           
                    } 
                }                              
            }

        });    
    
        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();
                }
            });
        });    
        
        // 隐藏id
        $('#tb').DataTable().column(0).visible(false);
        //隐藏企业信息
        $('#tb').DataTable().column(12).visible(false);

        $('#tb').on("click","button",function(event){
            event.preventDefault();
            var url=$(this).attr('href');
            var act=url.split("/")[4];  
            var me=$(this);

            if (act=='generate'){
                var clmns=$(this).closest('td').find('input[type="radio"]:checked').val();   
                if(clmns=='2'){
                    url=url+"&clmns=2"
                };  
            };  
            
            $.ajax({
                type:'GET',                           
                url:url,                
                dataType:'json',
                success: function(d) {
                    if (d.e==''){
                        if(act=='sync'){
                            toastr.success(d.cnt+" 盖码数据同步完成。",
                                {timeOut: 2000, positionClass: "toast-center-center"}            
                            );
                            $(me).hide();

                        }else{
                            toastr.success(d.cnt+" 码文件已生成,  密码: "+d.password,
                                {timeOut: 2000, positionClass: "toast-center-center"}            
                            );     
                            $.RefreshContent('{{request.path}}'); 
                        }
                        //$.RefreshContent('{{request.path}}'); 

                    }else{                        
                        toastr.error(
                            d.e,
                            "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }
                }
            });
            

        });   

        //内网取相关业务通知单信息
        $('.btn-inform-sync').click(function(){
            $.ajax({
                type:'GET',                           
                url:"/bottlecap/ajax/inform/sync/",                
                dataType:'json',
                success: function(d) {
                    if (d.e==''){
                       
                        toastr.success(d.cnt+" 业务通知单已同步。",
                                {timeOut: 2000, positionClass: "toast-center-center"}            
                        );                            
                        
                        $.RefreshContent('{{request.path}}'); 
                    }else{                        
                        toastr.error(
                            d.e,
                            "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }
                }
            });                      
            
        
        });

    });
</script>



<ol class="breadcrumb">
        <li>瓶盖码数据</li>
        <li>业务单信息</li>     
</ol>




<div class='clear-fix'></div>
   
   
       
<div class="x_panel">
    <button class='btn btn-primary btn-inform-sync'>同步业务通知单信息</button>

    <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.title}}</th>
            {% endfor %}
                
        </thead>
        <tbody></tbody>
        <tfoot>
            {% for c in clmns %}
                <th><input type="text" placeholder="{{c.title}}"></th>            
            {% endfor %}            
        </tfoot>
    </table></div> 
</div>
