@include('common.header')
<div class="page-body">
    @include('common.meun');
    <div class="content">
    @include('common.tab')
    <!--  useful  -->
        <div class="row animated col-lg-12" style="padding-left: 10px">
            <div class="panel col-lg-12">
                <div class="panel-content">
                    <div class="table-responsive">
                        <form action="{{ URL::action('UserController@getUserList',[]) }}" method="GET">
                            <div style="height: 50px;">
                                <div class="col-lg-9"></div>
                                <div class="col-lg-3 mt-md mb-md">
                                    <div class="col-lg-1 pull-right"></div>
                                    <div class="col-lg-10">
                                        <input  placeholder="员工名称" value="{{ @$NAME }}" class="form-control" name="name" id="name"/>
                                    </div>
                                    <div class="col-lg-2 pull-right">
                                        <button type="submit" class="fa fa-search" style="height: 32px;width: 32px;border-radius:5px;border: none" id="submit"/>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <table id="basic-table2" class="data-table table table-striped nowrap table-hover" cellspacing="0" width="100%">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>员工名称</th>
                                <th>OpenID</th>
                                <th>UnionID</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($LISTS as $list)
                                <tr>
                                    <td>{{ $list->id }}</td>
                                    <td>{{ $list->name }}</td>
                                    <td>{{ $list->OpenID }}</td>
                                    <td>{{ $list->UnionID }}</td>
                                    <td>
                                        @if($list->status == 1)
                                            在用
                                        @else
                                            禁用
                                        @endif
                                    </td>
                                    <td>{{ date('Y-m-d',strtotime($list->created_at)) }}</td>
                                    <td>
                                        @if($list->status == 1)
                                            <button type="button" class="btn btn-default" style="color: red;" onclick="return changeStatus('{{ $list->id }}',0,'{{ $list->name }}')">停用</button>
                                        @else
                                            <button type="button" class="btn btn-default" style="color: green;" onclick="return changeStatus('{{ $list->id }}',1,'{{ $list->name }}')">启用</button>
                                        @endif


                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>

                        <div class="modal fade" id="check-box" tabindex="-1" role="dialog" aria-labelledby="modal-error-label">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header state modal-danger">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                        <h4 class="modal-title" id="modal-error-label"><i class="fa fa-warning"></i>确认框</h4>
                                    </div>
                                    <div class="modal-body" id="modal-info">
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-danger" onclick="statusConfirm()">确认</button>
                                        <button type="button" class="btn btn-default" onclick="checkClose('check-box')">关闭</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal fade" id="change-status" tabindex="-1" role="dialog" aria-labelledby="modal-error-label">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header state modal-danger">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                        <h4 class="modal-title" id="modal-error-label"><i class="fa fa-warning"></i>确认框</h4>
                                    </div>
                                    <div class="modal-body" id="change_info"></div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-danger" onclick="return save_status();" id="change_status">确认</button>
                                        <button type="button" class="btn btn-default" onclick="return checkClose('change-status');" id="cancel_change_status">取消</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        @include('common.message')
                        <div class="dataTables_info" id="basic-table2_info" role="status" aria-live="polite"> 共 {{ @$LISTS->total()}} 条记录</div>
                        <div class="libaoTurnPage" style="float:right;">
                            {{  $LISTS->links() }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<input type="hidden" id="id" value=""/>
<input type="hidden" id="status" value="0"/>
<input type="hidden" id="_token" value="{{csrf_token()}}"/>

<script src="/html/vendor/jquery/jquery-1.12.3.min.js"></script>
<script src="/html/javascripts/Jquery.form.js"></script>
<script src="/html/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/html/vendor/nano-scroller/nano-scroller.js"></script>
<script src="/html/javascripts/template-script.min.js"></script>
<script src="/html/javascripts/template-init.min.js"></script>
<script src="/html/javascripts/examples/charts/left-sidevar.js"></script>
</body>
</html>
<script type="text/javascript">

    function changeStatus(id,status,name){
        $('#id').val(id);
        $('#status').val(status);
        var option = '确认将用户【'+name+'】停用吗?';
        if(status == 1) option = '确认将用户【'+name+'】启用吗?';
        $('#change_info').html(option);
        $('#change-status').modal('show')
    }

    function save_status(){
        var id = $('#id').val();
        var status = $('#status').val();
        var token = $('#_token').val();

        $('#change_status').attr("disabled",true);
        $('#cancel_change_status').attr("disabled",true);

        $.ajax({
            type: 'POST',
            url: '{{ URL::action('UserController@getUserSetStatus',[]) }}',
            data: {_token:token,id:id,status:status},
            success:function(data){
                $('#show_error_info').html(data.msg);
                $('#show_success_info').html(data.msg);

                $('#change_status').attr("disabled",false);
                $('#cancel_change_status').attr("disabled",false);

                $('#change-status').modal('hide')
                if(data.code == 200){
                    $('#message-success-modal').modal('show')
                }else{
                    $("#message-error-modal").modal('show');
                }
            }
        });
    }
    $('#message-success-modal').on('hidden.bs.modal',function(){
        window.location.reload();
    });
    /**
     * 关闭弹框
     */
    function checkClose(id){
        $('#'+id).modal('hide');
    }

    function cir_cancel(id){
        $('#'+id).modal('hide')
    }
    /**
     * 验证字段
     */
    function verfyField(id,error_txt){
        $('#'+id).html(error_txt);
        $('#'+id).show();
        return false;
    }

</script>
