<?php $this->beginBlock('header_script'); ?>
<style>
    .paging_input{
    }
    .paging_input span{
        padding:3px 10px;
    }
    .paging_input input{
        width:40px;
        text-align:center;
    }
</style>
<?php $this->endBlock(); ?>

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-12">
        <h2>代理商管理</h2>
        <ol class="breadcrumb">
            <li>
                <a href="/admin/dashboard">管理首页</a>
            </li>
            <li class="active">
                <strong>代理商管理</strong>
            </li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="btn-group">
                        <button id="add" class="btn btn-default">添加</button>
                        <button id="view" class="btn btn-default">查看</button>
                        <button id="tree" class="btn btn-default">名下代理</button>
                        <button id="users" class="btn btn-default">名下客户</button>
                    </div>

                    <div class="btn-group pull-right">
                        <button id="del" class="btn btn-danger">删除</button>
                    </div>
                </div>

                <div class="ibox-content">

                    <div class="table-responsive">
                        <table id="datatables" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>上级代理商</th>
                                <th>用户名</th>
                                <th>账户</th>
                                <th>邮箱</th>
                                <th>姓名</th>
                                <th>状态</th>
                                <th>注册时间</th>
                            </tr>
                            </thead>
                            <tfoot>
                            <tr>
                                <th>ID</th>
                                <th>上级代理商</th>
                                <th>用户名</th>
                                <th>账户</th>
                                <th>邮箱</th>
                                <th>姓名</th>
                                <th>状态</th>
                                <th>注册时间</th>
                            </tr>
                            </tfoot>
                        </table>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footer_script'); ?>
<script>
KindEditor.ready(function(K) {});
</script>

<!-- Page-Level Scripts -->
<script>
var table;
$(document).ready(function() {
    table = $('#datatables').DataTable({
        "pagingType": "input",
        "aLengthMenu": [[20,50,100,500,999999999], [20,50,100,500,"ALL"]],
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        "processing": true,
        "serverSide": true,
        "ajax": '/admin/ib/ajax',
        "order": [[7, "desc"]],
        "columns": [{
            "data": "id"
            },{
                "data": "IBNAME"
            },{
                "data": "ib_old_login_name"
            },{
                "data": "logins"
            },
            {
                "data": "username"
            },
            {
                "data": "name"
            },
            {
                "data": "is_enable"
            },
            {
                "data": "in_time"
            }],
        columnDefs: [{
            targets: 6,
            render: function(data, type, row, meta) {
                if(data==0){
                    return '<span class="label label-danger">禁用</span>';
                }else if(data==1){
                    return '<span class="label label-primary">启用</span>';
                }
            },
            "orderable": true
        },{
            targets: 7,
            render: function(data, type, row, meta) {
                return timeStamp2String(data);
            },
            "orderable": true
        }],
        "sPaginationType": "full_numbers",
        dom: '<"html5buttons"B>lTfgitp',
        buttons: [{
            extend: 'copy'
        },
            {
                extend: 'csv'
            },
            {
                extend: 'excel'
            },
            {
                extend: 'pdf'
            },
            {
                extend: 'print',
                customize: function(win) {
                    $(win.document.body).addClass('white-bg');
                    $(win.document.body).css('font-size', '10px');
                    $(win.document.body).find('table').addClass('compact').css('font-size', 'inherit');
                }
            }]

    });

    $('#datatables tbody').on('click', 'tr',
        function() {
            if ($(this).hasClass('selected')) {
                $(this).removeClass('selected');
            } else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        });

    $('#add').click(function() {
        $("#modal").removeData();
        var data=table.row('.selected').data();
        if(data!=undefined){
            var url="/admin/ib/add?id="+data.id+"&t="+new Date().getTime();
            $("#modal").modal({
                remote:url,
                show:true
            });
        }else{
            var url="/admin/ib/add?t="+new Date().getTime();
            $("#modal").modal({
                remote:url,
                show:true
            });
        }
    });

    $('#tree').click(function() {
        $("#modal").removeData();
        var data=table.row('.selected').data();
        if(data!=undefined){
            var url="/admin/ib/tree?id="+data.id+"&t="+new Date().getTime();
            $("#modal").modal({
                remote:url,
                show:true
            });
        }
    });

    $('#view').click(function() {
        $("#modal").removeData();
        var data=table.row('.selected').data();
        if(data!=undefined){
            var url="/admin/ib/view?id="+data.id+"&t="+new Date().getTime();
            location.href=url;
            //$("#modal").modal({
            //	remote:url,
            //	show:true
            //});
        }
    });

    $('#users').click(function() {
        $("#modal").removeData();
        var data=table.row('.selected').data();
        if(data!=undefined){
            var url="/admin/ib/users?id="+data.id+"&t="+new Date().getTime();
            location.href=url;
            //$("#modal").modal({
            //	remote:url,
            //	show:true
            //});
        }
    });



    $("#modal").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
        KindEditor.remove('#kindeditor');
    });


    $('#del').click(function() {
        var data=table.row('.selected').data();
        if(data!=undefined){
            swal({
                title: "您确定吗?",
                text: "请确定要删除用户么?删除之后不可恢复！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            }, function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        type: "POST",
                        url: "/admin/ib/delete",
                        data: {
                            id:data.id
                        },
                        dataType: "json",
                        beforeSend: function() {},
                        success: function(data) {
                            if(data.isSuccess){
                                table.ajax.reload();
                            }else{
                                toastr.error(data.msg, "提示");
                            }
                        },
                        complete: function(XMLHttpRequest, textStatus) {},
                        error: function() {}
                    });
                }
            });
        }
    });

});
</script>
<?php $this->endBlock(); ?>