<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/28/028
 * Time: 11:43
 */
?>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-12">
        <h2>修改杠杆</h2>
        <ol class="breadcrumb">
            <li>
                <a href="<?= \yii\helpers\Url::to(['/admin/dashboard']) ?>">管理首页</a>
            </li>
            <li class="active">
                <strong>修改杠杆</strong>
            </li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">

    <form>
        <input type="hidden" name="type" value="<?= $type ?>">
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label">会员ID</label>
                        <input type="number" id="memberId" name="memberId" value="<?= $member_id ?>" placeholder="ID" class="form-control">
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label" for="price">开始时间</label>
                        <input readonly="readonly" type="text" id="sTime" name="sTime" value="<?= Yii::$app->getRequest()->get('sTime') ?>" placeholder="开始时间" class="data form-control">
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label" for="quantity">结束时间</label>
                        <input readonly="readonly" type="text" id="eTime" name="eTime" value="<?= Yii::$app->getRequest()->get('eTime') ?>" placeholder="结束时间" class="data form-control">
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label" for="quantity">操作</label>
                        <input type="submit" class="btn btn-primary form-control" value="搜索">
                    </div>
                </div>
            </div>
        </div>
    </form>


    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="btn-group">
                        <button id="view" class="btn btn-default">查看会员</button>
                        <?php if ($type == 0) { ?>
                        <button onclick="w(1)" class="btn btn-default">不通过</button>
                        <button onclick="w(2)" class="btn btn-default">已修改</button>
                        <?php } ?>
                    </div>
                    <div class="btn-group pull-right">
                        <button id="memo" class="btn btn-default">备注</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="ibox-content">

                    <div class="table-responsive">
                        <table id="datatables" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>姓名</th>
                                <th>状态</th>
                                <th>会员ID</th>
                                <th>账户</th>
                                <th>杠杆</th>
                                <th>申请时间</th>
                                <th>备注</th>
                            </tr>
                            </thead>
                            <tfoot>
                            <tr>
                                <th>姓名</th>
                                <th>状态</th>
                                <th>会员ID</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({
            "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": '<?= \yii\helpers\Url::to(['lever-ajax', 'type' => $type, 'member_id'=>Yii::$app->getRequest()->get('memberId'), 'sTime' => Yii::$app->getRequest()->get('sTime'), 'eTime' => Yii::$app->getRequest()->get('eTime')]) ?>',
            "order": [[5, "desc"]],
            "columns": [{
                "data": "name"
            },{
                "data": "type"
            },{
                "data": "member_id"
            },{
                "data": "login"
            },{
                "data": "lever"
            },{
                "data": "in_time"
            },{
                "data": "memo"
            }],
            columnDefs: [{
                targets: 1,
                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-danger">不通过</span>';
                    }else if(data==2){
                        return '<span class="label label-primary">已修改</span>';
                    }
                },
                "orderable": true
            },{
                targets: 5,
                render: function(data, type, row, meta) {
                    if(data!=0){
                        return timeStamp2String(parseInt(data));
                    }else{
                        return "";
                    }
                },
                "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');
                }
            });



        $('#view').click(function() {
            $("#modal").removeData();
            var data=table.row('.selected').data();
            if(data!=undefined){
                var url="/admin/member/view?id="+data.member_id+"&t="+new Date().getTime();
                window.open(url);
            }
        });

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


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

    });


    function w(type){
        var data=table.row('.selected').data();
        if(data!=undefined){
            var msg="";
            if(type==1){
                msg="请确定是否不通过该申请？";
            }else if(type==2){
                msg="请确定是否通过该申请？"
            }

            swal({
                title: "您确定吗?",
                text: msg,
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            }, function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        type: "POST",
                        url: "/admin/modify-lever/type",
                        data: {
                            id:data.id,
                            type:type
                        },
                        dataType: "json",
                        beforeSend: function() {},
                        success: function(data) {
                            if(data.code == 1){
                                table.ajax.reload();
                            }else{
                                toastr.error(data.message, "提示");
                            }
                        },
                        complete: function(XMLHttpRequest, textStatus) {},
                        error: function() {}
                    });
                }
            });
        }
    }

    $('.data').datepicker({
        startView: 1,
        todayBtn: "linked",
        keyboardNavigation: true,
        forceParse: false,
        autoclose: true,
        format: "yyyy-mm-dd"
    });

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

