<?php   
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/3/003
 * Time: 15:14
 */
?>
<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">

    <form>
        <input type="hidden" name="status" value="<?= $status ?>">
        <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" for="batch_no">打款批次号</label>
                        <input type="number" id="batch_no" name="batch_no" value="<?= Yii::$app->getRequest()->get('batch_no') ?>" placeholder="打款批次号" class="form-control">
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label" for="sTime">开始时间</label>
                        <input readonly="readonly" type="text" id="sTime" name="sTime" value="<?= Yii::$app->getRequest()->get('sTime') ?>" placeholder="开始时间" class="datetime form-control">
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label" for="eTime">结束时间</label>
                        <input readonly="readonly" type="text" id="eTime" name="eTime" value="<?= Yii::$app->getRequest()->get('eTime') ?>" placeholder="结束时间" class="datetime 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 (isset($status) && trim($status) !== ''): ?>
                            <?php if ($status == 'all'): ?>
                                <button id="import" class="btn btn-default">导入批次</button>
                            <?php elseif ($status == 'first_trial') : ?>
                                <!--<button onclick="w(1)" class="btn btn-default">初审通过</button>-->
                                <button id="remitFirst" class="btn btn-default" value="1">初审通过</button>
                                <!--<button onclick="w(3)" class="btn btn-default">初审不通过</button>-->
                                <button id="remitNo" class="btn btn-default" value="3">初审不通过</button>
                            <?php elseif ($status == 're_trial'): ?>
                                <!--<button onclick="wf(2)" class="btn btn-default">复审通过</button>-->
                                <button id="remitRe" class="btn btn-default" value="2">复审通过</button>
                                <!--<button onclick="wf(4)" class="btn btn-default">复审不通过</button>-->
                                <button id="remitReNo" class="btn btn-default" value="4">复审不通过</button>
                            <?php endif; ?>
                        <?php endif; ?>
                        <button id="viewlog" 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>打款总额(CNY)</th>
                                <th>创建时间</th>
                                <th>审核状态</th>
                                <th>初审时间</th>
                                <th>初审不通过原因</th>
                                <th>初审人员</th>
                                <th>复审时间</th>
                                <th>复审不通过原因</th>
                                <th>复审人员</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal inmodal" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">

        </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(['ajax', 'status' => $status, 'batch_no'=>Yii::$app->getRequest()->get('batch_no'), 'start_time' => Yii::$app->getRequest()->get('sTime'), 'end_time' => Yii::$app->getRequest()->get('eTime')]) ?>',
            "order": [[3, "desc"]],
            "columns": [{
                "data": "batch_no"
            },{
                "data": "batch_count"
            },{
                "data": "cny_amount"
            },{
                "data": "create_time"
            },{
                "data": "audit_status"
            },{
                "data": "audit_time"
            },{
                "data": "audit_reason"
            },{
                "data": "audit_name"
            },{
                "data": "reaudit_time"
            },{
                "data": "reaudit_reason"
            },{
                "data": "reaudit_name"
            }],
            columnDefs: [{
                targets: 0,//指定哪几列
                "orderable": true
            },{
                targets: 3,
                render: function(data, type, row, meta) {
                    if(data!=0){
                        return timeStamp2String(data*1000);
                    }else{
                        return "";
                    }
                },
                "orderable": true
            },{
                targets: 4,
                render: function(data, type, row, meta) {
                    if(data==0){
                        return '<span class="label label-warning">未审核</span>';
                    }else if(data==1){
                        return '<span class="label label-primary">初审通过</span>';
                    }else if(data==2){
                        return '<span class="label label-primary">复审通过</span>';
                    }else if(data==3){
                        return '<span class="label label-danger">初审未通过</span>';
                    }else if(data==4){
                        return '<span class="label label-danger">复审未通过</span>';
                    }else {
                        return '';
                    }
                },
                "orderable": true
            },{
                targets: 5,
                render: function(data, type, row, meta) {
                    if(data!=0){
                        return timeStamp2String(data*1000);
                    }else{
                        return "";
                    }
                },
                "orderable": true
            },{
                targets: 8,
                render: function(data, type, row, meta) {
                    if(data!=0){
                        return timeStamp2String(data*1000);
                    }else{
                        return "";
                    }
                },
                "orderable": true
            }],

            "sPaginationType": "full_numbers",
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [{
                extend: 'copy'
            },
                {
                    extend: 'csv',
                    exportOptions: {
                        format: {
                            body: function (data, column, row, node) {
                                if (column == 0 || column == 2) {
                                    return "\u200C"+data;
                                } else if (column == 4) {
                                    if (data == '<span class="label label-warning">未审核</span>') {
                                        return '未审核';
                                    } else if (data == '<span class="label label-primary">初审通过</span>') {
                                        return '初审通过';
                                    } else if (data == '<span class="label label-primary">复审通过</span>') {
                                        return '复审通过';
                                    } else if (data == '<span class="label label-danger">初审未通过</span>') {
                                        return '初审未通过';
                                    } else if (data == '<span class="label label-danger">复审未通过</span>') {
                                        return '复审未通过';
                                    } else {
                                        return '';
                                    }
                                } else {
                                    return data;
                                }
                            }
                        }
                    }
                },
                {
                    extend: 'excel',
                    exportOptions: {
                        format: {
                            body: function (data, column, row, node) {
                                if (column == 0 || column == 2) {
                                    return " "+data;
                                } else if (column == 4) {
                                    if (data == '<span class="label label-warning">未审核</span>') {
                                        return '未审核';
                                    } else if (data == '<span class="label label-primary">初审通过</span>') {
                                        return '初审通过';
                                    } else if (data == '<span class="label label-primary">复审通过</span>') {
                                        return '复审通过';
                                    } else if (data == '<span class="label label-danger">初审未通过</span>') {
                                        return '初审未通过';
                                    } else if (data == '<span class="label label-danger">复审未通过</span>') {
                                        return '复审未通过';
                                    } else {
                                        return '';
                                    }
                                } else {
                                    return data;
                                }
                            }
                        }
                    }
                },
                {
                    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/finance-remit/detail?batch_no="+data.batch_no;
                window.open(url, "_self");
            }
        });

        $('#import').click(function() {
            $("#modal").removeData();
            var url="/admin/finance-remit/import-remit-order?t="+new Date().getTime();
            $("#modal").modal({
                remote:url,
                show:true
            });
        });

        $('#remitFirst').click(function() {
            $("#modal").removeData();
            var data=table.row('.selected').data();
            var type= $('#remitFirst').val();
            var url="/admin/finance-remit/remit-confirm-dialogue?type="+type+"&batch_no="+data.batch_no;
            $("#modal").modal({
                remote:url,
                show:true
            });
        });

        $('#remitNo').click(function() {
            $("#modal").removeData();
            var data=table.row('.selected').data();
            var type= $('#remitNo').val();
            var url="/admin/finance-remit/remit-confirm-dialogue?type="+type+"&batch_no="+data.batch_no;
            $("#modal").modal({
                remote:url,
                show:true
            });
        });

        $('#remitRe').click(function() {
            $("#modal").removeData();
            var data=table.row('.selected').data();
            var type= $('#remitRe').val();
            var url="/admin/finance-remit/remit-confirm-dialogue?type="+type+"&batch_no="+data.batch_no;
            $("#modal").modal({
                remote:url,
                show:true
            });
        });

        $('#remitReNo').click(function() {
            $("#modal").removeData();
            var data=table.row('.selected').data();
            var type= $('#remitReNo').val();
            var url="/admin/finance-remit/remit-confirm-dialogue?type="+type+"&batch_no="+data.batch_no;
            $("#modal").modal({
                remote:url,
                show:true
            });
        });

        $('#viewlog').click(function() {
            $("#modal").removeData();
            var data=table.row('.selected').data();
            var url="/admin/finance-remit/view-log?batch_no="+data.batch_no;
            $("#modal").modal({
                remote:url,
                show:true
            });
        });

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

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

