{% load i18n %}


<script type="text/javascript">
    $(document).ready(function(){    
        var page_length=10; 
		var value=[]		
        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,          
            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();
                }
            });
        });    
		
		var table2=$('#tb2').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,          
            data:{{cnts|safe}}
        });     
        table2.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        }); 

		var table3=$('#tb3').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,
            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,          
            data:{{cnts2|safe}}
        });     
        table3.columns().every( function () {                        
            var that = this;             
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        }); 

        $('#data-content .btn-obj-add').click(function(){     
            event.preventDefault(); 
            $.RefreshContent($(this).attr('href'));            
        });    

        {% if dt %}
            $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
            $('.datepicker').datepicker('setDate',new Date());
            setDatePickerZh();

            $('#dt_fr').val('{{date_from}}');
            $('#dt_to').val('{{date_to}}');

            $('.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('date_from='+date_fr)};
                if(date_to!=''){params.push('date_to='+date_to)};

                if(params.length==0){
                    bootbox.alert("{% trans '请先输入查询条件！'%}");
                }else{
                    $.RefreshContent('{{request.path}}?'+params.join('&'));
                }
            });
        {% endif %}
		
		
		    $(".checkall").on('click',function () {
            var list_before = $('.checkchild')
            for (var i = 0; i < list_before.length; i++) {
                if (list_before[i].checked) {
                    $(".checkchild").prop("checked", false);
                    break;
                }else { 
                    $(".checkchild").prop("checked", true);
                    break;
                }
            }
            var list = $('.checkchild')
            for (var i = 0; i < list.length; i++) {
                    if (list[i].checked) {
                        if (value.indexOf(parseInt(list[i].value)) !=-1) {
                            {#value.push(parseInt(list[i].value))#}
                        }else{
                            value.push(parseInt(list[i].value))
                        }

                    }else {
                        if ($.inArray(parseInt(list[i].value), value) == -1) {
                            //$.inArray(元素, 数组) == -1 表示要删除的元素不在原数组中
                        } else {
                            value.splice($.inArray(parseInt(list[i].value), value), 1);
                        }
                        $(".checkchild").prop("checked", false);
                    }
            }
        });


    $("#tb").on('click','.checkchild',function (e){
        var check = $(this).prop("checked");
        if (check){
                if (value.indexOf(parseInt(this.value))){
                    value.push(parseInt(this.value))
                }
            }else{
                if($.inArray(parseInt(this.value), value) == -1){
                    //$.inArray(元素, 数组) == -1 表示要删除的元素不在原数组中
                }else{
                    value.splice($.inArray(parseInt(this.value), value), 1);
                }
            }
    })

    var url = 'sales/lotteryseeds/batch_delete/';

    $('.btn-delete-all').click(function () {

            if (value.length > 0) {
                var r = confirm('您确定要删除吗？');
                if (r) {
                    console.log(value)
                    $.ajax({
                        type: 'post',
                        url: url,
                        data: {
                            otteryseeds_ids: value.join(','),
                            delflag: 1
                        },
                        success: function (html) {
                            table.draw();
                            $.RefreshContent('sales/lotteryseeds/')
                            {#$('#bg-modal .modal-body').html(html);#}
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert('连接服务器失败');
                        }
                    })
                }
            } else {
                alert('请勾选需要删除的内容！')
            }

        })


    });

    
    function deleteItem(id){
        var r = confirm('您确定要删除吗？');
        if(r){
            var durl = '{{request.path}}delete/'+id+'/'
            $.RefreshContent(durl);
        }
    }
</script>



<ol class="breadcrumb">
        <li>{{subtt.0}}</li>
        <li>{{subtt.1}}</li>     
</ol>



{% if perms.company.sys_admin %} 
    <div class="title_right">
        <div class="pull-right">
            <span class='input-group'>
                <a type="button" class='btn btn-obj-add l-a create-btn' href='/sales/activity/lottery_single'>
                    <span class='glyphicon glyphicon-plus' style='padding-right:5px;'></span>{% trans '单枚布奖' %}
                </a>
                <a type="button" class='btn btn-obj-add l-a create-btn' href='{{murl}}'>
                    <span class='glyphicon glyphicon-plus' style='padding-right:5px;'></span>{% trans '新建布奖' %}
                </a>
            </span>
        </div>
    </div>  
{% endif%} 



{% if dt %}
    <form role="form"  class="form-inline" style="margin-top:0px;padding-left:10px;">
        <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>        
        </div>
    </form>
    <div class="clearfix"></div>
{% endif %}




<div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div class="table-responsive">
			<h4>明细</h4>
            <table id='tb'  class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
            <thead> 
                <tr>
                    <th>
                        <input type="checkbox" class ="checkall" id="group_checkbox" style="display: none;"/><label for="group_checkbox">全选/反选</label>
                    </th>
                    <th>标签序号</th>
                    <th>活动</th>
                    <th>奖品</th>
                    <th>第二奖品</th>
                    <th>产品</th>
                    <th>批次</th>
                    <th>经销商</th>
                    <th>状态</th>
                    <th>备注</th>
                    <th>时间</th>
                    <th>是否终端返利</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody></tbody>
            <tfoot>
                <th> <span class="btn btn-sm btn-danger btn-delete-all"  >批量删除</span> </th>
                <th><input type="text" placeholder="标签序号"></th>
                <th><input type="text" placeholder="活动"></th>
                <th><input type="text" placeholder="奖品"></th>
                <th><input type="text" placeholder="第二奖品"></th>
                <th><input type="text" placeholder="产品"></th>
                <th><input type="text" placeholder="批次"></th>
                <th><input type="text" placeholder="经销商"></th>
                <th><input type="text" placeholder="状态"></th>
                <th><input type="text" placeholder="备注"></th>
                <th><input type="text" placeholder="时间"></th>
                <th><input type="text" placeholder="是否终端返利"></th>
                <th><input type="text" placeholder="操作"></th>
            </tfoot>
            </table>
        </div>
    </div>
</div>

<div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div  class="table-responsive">
			<h4>按活动汇总</h4>
            <table id='tb2' class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
            <thead>
                {% for c in clmns2 %}
                    <th>{{c}}</th>
                {% endfor %}
            </thead>
            <tbody></tbody>
            <tfoot>
                {% for c in clmns2 %}
                    <th><input type="text" placeholder="{{c}}"></th>            
                {% endfor %}            
            </tfoot>
            </table>
        </div>
    </div>
</div>

<div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div  class="table-responsive">
			<h4>按批次汇总</h4>
            <table id='tb3' class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
            <thead>
                {% for c in clmns3 %}
                    <th>{{c}}</th>
                {% endfor %}
            </thead>
            <tbody></tbody>
            <tfoot>
                {% for c in clmns3 %}
                    <th><input type="text" placeholder="{{c}}"></th>            
                {% endfor %}            
            </tfoot>
            </table>
        </div>
    </div>
</div>