{% load i18n %}


<style>
   
     #tb tbody img{
        height:32px;
        margin-left:10px;    
    
    }
</style>


<script type="text/javascript">
    $(document).ready(function(){   

        var page_length=10;      


        $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
        $('.datepicker').datepicker('setDate',new Date());
        setDatePickerZh();
        $('#dt_fr').val('{{date_from}}');
        $('#dt_to').val('{{date_to}}');
        $('#status').val('{{status_id}}');
        $('.btn-qry').click(function(){
            var date_from,date_to,status_id;
            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)};            
            params.push('status_id='+$('#status').val()); 
            if(params.length==0){
                bootbox.alert("{% trans '请先输入查询条件！'%}");
            }else{
                $.RefreshContent('{{request.path}}?'+params.join('&'));
            }
        });





        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: true,
            pageLength: page_length,          

            buttons: [{extend:'excelHtml5',text: '导出到Excel'}],   
            language:lng,          
            data:{{data|safe}},    


            createdRow: function( nRow, aData, iDataIndex ) {
                $(nRow).attr('id', aData[0]);
            },

            //drawCallback: function () {
            //    $("[data-toggle='popover']").popover({
            //        html:true,
            //        placement:'bottom'
            //    });  
            //}


        });     
        table.column(0).visible(false);  
        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();
                }
            });

            
        });  




        $('#tb').on("change","td input[type='checkbox']",function(event){
            var tr=$(this).closest('tr');
            var td=$(this).closest('td');
            var app_id=$(this).attr('app_id');
            var user_group_id=$(this).attr('user_group_id');
            var checked=$(this).prop("checked");            
            var url='/company/application/approve/';
            $.ajax({
                type:'POST',
                data:{
                    'checked':checked,
                    'content_type':'{{content_type}}',
                    'app_id':app_id,                    
                    'user_group_id':user_group_id,
                },
                datatype: 'json',
                url:url,
                success:function(data){     
                    $(tr).find('td:nth-child(3)').text(data.status);     
                    $(td).html('');
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('连接服务器失败');
                    return;
                },
                beforeSend: function(xhr) {                    
                    xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
                }
            });   
        });        
    


        function CallBack(){   
            var app_id=$('#confirm-modal').find('.app_id').val();
            var comment=$('#confirm-modal').find('.comment').val();      
            if ($.isEmpty(comment)){
                toastr.error('驳回请输入驳回原因。', "输入错误：",
                    {timeOut: 800, positionClass: "toast-center-center"}
                );
                return true;
            }else{
                $.ajax({
                    type:'POST',
                    data:{                    
                        'content_type':'{{content_type}}',
                        'app_id':app_id, 
                        'action':'reject',
                        'comment':comment
                    },
                    datatype: 'json',
                    url:"/company/application/approve/",
                    success:function(data){     
                        $('#tb').find("[app_id='"+app_id+"']").parent().text('驳回');
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert('连接服务器失败');
                        return;
                    },
                    beforeSend: function(xhr) {                    
                        xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
                    }            
                });
            }
        };


        //2021-04-05
        $('#tb').on('click','td a.log',function(event){  
            event.preventDefault();
            var tr=$(this).closest('tr');
            var agent=$(tr).find('td:nth-child(6)').text();  
            $.OpenDlg($(this).attr('href'),agent+'-审核日志:',1000,700);
        });

        //2021-04-05
        $('#tb').on('click','td a.edit',function(event){  
            event.preventDefault();
            //var tr=$(this).closest('tr');
            //var id=$(tr).find('td:nth-child(0)').text();  
            $.OpenUrlCfmDlg($(this).attr('href'),'编辑修改：','确定','取消');
            
        });

        $('#tb').on('click','td a.act',function(event){  
            event.preventDefault();    
            var app_id=$(this).attr('app_id');
            var tr=$(this).closest('tr');
            var agent=$(tr).find('td:nth-child(6)').text();            
            
            if('{{content_type}}'=='wxwalletapplication'){    
                var wx=$(tr).find('td:nth-child(8)').html();
                var realname=$(tr).find('td:nth-child(9)').text();
                var content='<form class="form-horizontal" role="form" >'+   
                    '<input type="hidden" class="app_id" value="'+app_id+'" />'+
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">微信绑定</label>'+
                        '<div class="col-sm-9">'+wx+'</div>'+
                    '</div>'+
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">收款人实名</label>'+
                        '<div class="col-sm-9" style="padding-top:8px;">'+realname+'</div>'+ 
                    '</div>'+
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">驳回原因</label>'+
                        '<div class="col-sm-9"><input class="comment form-control"/></div>'+
                    '</div>'+
                    '</form>';
            }else{
                var bank_name=$(tr).find('td:nth-child(7)').text();
                var bank_account=$(tr).find('td:nth-child(8)').html();
                var name=$(tr).find('td:nth-child(9)').text();
                var content='<form class="form-horizontal" role="form" >'+   
                    '<input type="hidden" class="app_id" value="'+app_id+'" />'+                    
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">收款行</label>'+
                        '<div class="col-sm-9" style="padding-top:8px;">'+bank_name+'</div>'+ 
                    '</div>'+
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">帐号</label>'+
                        '<div class="col-sm-9" style="padding-top:8px;">'+bank_account+'</div>'+ 
                    '</div>'+
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">收款人</label>'+
                        '<div class="col-sm-9" style="padding-top:8px;">'+name+'</div>'+ 
                    '</div>'+
                    '<div class="form-group">'+
                        '<label class="col-sm-3 control-label">驳回原因</label>'+
                        '<div class="col-sm-9"><input class="comment form-control"/></div>'+
                    '</div>'+
                    '</form>';            
            }
            $.OpenCfmDlg(agent+":",content,CallBack);
        });
        


       
        //$('#tb').on("click","td a.btn-details",function(event){
        //    event.preventDefault(); 
        //    $.OpenDlg($(this).attr('href'),'渠道返利-扫码明细',1000,700);                  
        //});     

        $('#tb').on("click","td a.btn-confirm",function(event){
            event.preventDefault(); 
            $.ajax({
                url:$(this).attr('href'),
                success:function(data){                   
                    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){                        
                        $.RefreshContent('{{request.path}}');
                    }else{
                        $.RefreshContent('{{request.path}}?'+params.join('&'));
                    }
                },
                error:function(){
                    toastr.error("连接服务器失败！", "操作失败：",
                        {timeOut: 800, positionClass: "toast-center-center"}
                    );
                }

            });                   
        });  

        
        
    });
</script>




<div>
    <ol class="breadcrumb">
        <li>经销商管理</li>
        <li>{{subtt}}</li>     
    </ol>
   
    <form class='form-inline'>
    <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>    
    
    <label class='col-sm-1' style='padding-top:5px;'>{% trans "申请状态:"%}</label>
    <div class='col-sm-1'><select id='status' class='form-control'>
        <option value='0'>所有</option>
        {% for s in status %}
            <option value='{{s.0}}'>{{s.1}}</option>
        {% endfor %}             
    </select></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>

    <div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
        <div  class="table-responsive" style=''>
            <table id='tb'  class="table table-striped table-bordered" cellspacing="0" width="100%">
            <thead>
                {% for c in clmns %}
                    <th>{{c}}</th>
                {% endfor %}
            </thead>
            <tbody></tbody>
            <tfoot>
                <tr>
                    {% for c in clmns %}                    
                        <th><input type="text" placeholder="{{c}}"></th>                  
                    {% endfor %}
                </tr>
            </tfoot>
            </table>
        </div>
    </div>
    </div>
</div>
