<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#user/lineauth">
                                        <input type="hidden" value="1" name="lineauth_post"/>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>备注:</label>
                                            <span class="gap"></span>
                                            <select  name="remark" id="remark" class="selectpicker show-tick form-control">
                                                <option value="0">--请选择--</option>
                                                <?php foreach ($remarkStatus as $k => $v) {?>
                                                    <option value="<?php echo $k;?>" <?php if($k == $remark) echo 'selected';?>><?php echo $v;?></option>
                                                <?php }?>
                                            </select>
                                        </div>
                                        <span class="gap"></span>

                                        <button type="submit" class="btn btn-primary" id="searchBtn">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>用户line认证</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>用户ID</th>
                                                <th>用户名称</th>
                                                <th>用户头像</th>
                                                <th>LINE账号</th>
                                                <th>状态</th>
                                                <th>填写时间</th>
                                                <th>备注</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php 
                                                if(is_array($list)){
                                                    foreach ($list as $key => $val) {
                                            ?>
                                            <tr>
                                                <td><?php echo $val['la_id'];?></td>
                                                <td><?php echo empty($val['la_uid']) ? '无uid' : '<a target = "_blank" href="#user/index/'.$val['la_uid'].'">'.$val['la_uid'].'</a>';?></td>
                                                <td><?php echo empty($val['nick']) ? '无' : $val['nick'] ;?></td>
                                                <td><?php if( empty($val['s_picture']) || $val['s_picture'] == 1){echo '无头像';}else{ ?><img width="70" src="<?php echo $val['s_picture'];?>" /><?php }?></td>
                                                <td><?php echo $val['la_account'];?></td>
                                                <td>
                                                    <?php
                                                        $status = 0;
                                                        switch($val['la_status']){
                                                        case 1:
                                                            $status = '<span class="label label-primary">已认证</span>';
                                                            break;
                                                        case 2:
                                                            $status = '<span class="label label-default">已驳回</span>';
                                                            break;
                                                        default:
                                                            $status = '<span class="label label-success">未认证</span>';
                                                            break;
                                                        }
                                                        echo $status;
                                                    ?>
                                                        
                                                </td>

                                                <td><?php echo date('Y-m-d H:i:s', $val['la_time']);?></td>
                                                <td><?php echo $remarkStatus[$val['remark']] ?? '未认证'?></td>
                                                <td>
                                                    <?php if( $val['la_status'] == 0 ) {?>
                                                    <button type="button" class="btn btn-primary actionlineauth" uid="<?php echo $val['la_uid'];?>" >认证</button>
                                                    <button type="button" class="btn btn-warning actiondismiss" uid="<?php echo $val['la_uid'];?>" >驳回</button>
                                                    <?php } else{ ?>
<!--                                                    <button type="button" class="btn btn-primary actionlineauth" uid="--><?php //echo $val['la_uid'];?><!--" disabled >认证</button>-->
                                                    <?php } ?>
                                                    <button type="button" class="btn btn-default actionremark" remark="<?php echo $val['remark'];?>" uid="<?php echo $val['la_uid'];?>"  account="<?php echo $val['la_account'];?>" >备注</button>
                                                </td>
                                            </tr>
                                            <?php } } else{?>
                                            <tr>
                                                <td colspan="10">暂无数据</td>
                                            </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <nav>
                                        <ul class="pagination">
                                            <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo $total;?></span>条</a></li>
                                            <?php echo $pageurl;?>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">备注</h4>
            </div>
            <div id="msg-tip"></div>

            <form class="form-horizontal" role="form" method="post" action="#" id="remarkForm">

                <input type="hidden" value="" id="uid" name="uid"/>
                <input type="hidden" value=""  name="la_status"/>
                <div class="modal-body" style="overflow:auto;">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">LINE账号:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control"  name="la_account" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注:</label>
                            <div class="col-sm-9">
                                <select  name="remark_m" id="remark_m" class="selectpicker show-tick form-control">
                                    <?php foreach ($remarkStatus as $k => $v) {?>
                                        <option value="<?php echo $k;?>" <?php if($k == $remark) echo 'selected';?>><?php echo $v;?></option>
                                    <?php }?>
                                </select>
                            </div>
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="remarkSubmitBtn">提交</button>
                </div>
            </form>

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


<script src="<?php echo base_url();?>public/js/common.js"></script>
<script>
    //认证玩家
    $('.actionlineauth').click(function(){
        if( confirm('确定认证该玩家吗?') ){
            var uid = $(this).attr("uid");
            $.ajax({
                type: 'POST',
                dataType: 'json',
                data:'actionuid='+uid,
                url:'user/actionline',
                success: function(e){
                    console.log(e);
                    console.log(e.state);
                    if(e.state = 'success'){
                        alert('认证成功');
                        window.location.reload()
                    }else{
                        alert('认证失败');
                    }
                }
            });
        }
    });


    //驳回玩家
    $('.actiondismiss').click(function(){
        if( confirm('确定驳回该玩家吗?') ){
            var uid = $(this).attr("uid");
            $.ajax({
                type: 'POST',
                dataType: 'json',
                data:'actionuid='+uid,
                url:'user/actiondismiss',
                success: function(e){
                    console.log(e);
                    console.log(e.state);
                    if(e.state = 'success'){
                        alert('成功');
                        //window.location.reload()
                    }else{
                        alert('失败');
                    }
                }
            });
        }
    });

    //进行备注
    $('.actionremark').click(function () {
        var _this = $(this),
            uid = _this.attr('uid'),
            account = _this.attr('account'),
            remark = _this.attr('remark');
        $('#myModal #uid').val(uid);
        $('#myModal input[name="la_account"]').val(account);
        $('#myModal select[name="remark_m"]').val(remark);
        $('#myModal').modal();
    });
    
    //备注更改
    $('#remarkSubmitBtn').click(function () {
        var uid = $('#myModal #uid').val(),
            remark = $('#myModal select[name="remark_m"]').val(),
            msgTip = $('#msg-tip');
        $.ajax({
            url: 'user/actionremark',
            type:'post',
            dataType: 'json',
            data:{
                uid: uid,
                remark: remark
            },
            success: function (data) {
                if(data.ret == 0) {
                    window.location.reload()
                }else {
                    msgTip.messager().error(data.msg);
                }
            },
            error: function (msg) {
                msgTip.messager().error('网络错误，请刷新后重试');
            }
        });
    });
    
</script>