@include('admin.common.header')
<link rel="stylesheet" href="/html/vendor/data-table/media/css/dataTables.bootstrap.min.css">
<div class="page-body">
    @include('admin.common.meun')
    <div class="content">
        @include('admin.common.tab')
        <div class="row animated col-lg-12" style="padding-left: 10px">
            <div class="panel col-lg-12">
                <div class="panel-content">
                    <div class="text-md mt-md bg-scale-0 mb-sm" style="height: 30px;"><a href="">图片审核</a>
                    </div>
                    <div class="table-responsive">
                        <form action="" method="GET" onsubmit="return check();">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-8 mt-md mb-md">
                                <div class="col-lg-3">
                                    <input type="text" name="startTime" value="{{ @$SEARCH['startTime'] }}" class="form-control" placeholder="开始时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd H:mm:ss'})">
                                </div>
                                <div class="col-lg-3">
                                    <input type="text" name="endTime" value="{{ @$SEARCH['endTime'] }}" class="form-control" placeholder="结束时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd H:mm:ss'})">
                                </div>
                                <div class="col-lg-2">
                                    <select class="form-control" name="status" >
                                        <option value="0" @if(@$SEARCH['status'] == 0) selected="selected" @endif>全部</option>
                                        <option value="1" @if(@$SEARCH['status'] == 1) selected="selected" @endif>待审核</option>
                                        <option value="2" @if(@$SEARCH['status'] == 2) selected="selected" @endif>审核通过</option>
                                        <option value="3" @if(@$SEARCH['status'] == 3) selected="selected" @endif>审核拒绝</option>
                                    </select>
                                </div>
                                <div class="col-lg-2">
                                    <input  placeholder="账号" value="{{  @$SEARCH['user'] }}" class="form-control" name="user" />
                                </div>
                                <input type="hidden" id="_token" name="_token" value="{{ csrf_token() }}">
                                <div class="col-lg-2">
                                    <button type="submit" class="fa fa-search pull-left" style="height: 32px;width: 32px;border-radius:5px;border: none" id="submit"/>
                                </div>
                            </div>
                        </form>

                        <table id="basic-table2" class="data-table table table-striped nowrap table-hover" cellspacing="0" width="100%">
                            <thead>
                            <tr>
                                <th>操作 <input type="checkbox" value="all" onclick="return imgCheck(this);"/><label class="ml-sm">全选</label><button type="button" class="btn btn-success" onclick="return setAllStatus();">审核</button></th>
                                <th>编号</th>
                                <th>用户名</th>
                                <th>审核</th>
                                <th>状态</th>
                                <th>图片</th>
                                <th>更新时间</th>
                                <th>查看</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($LIST as $li)
                                <tr>
                                    <td>  <input type="checkbox" name="ids[]" value="{{ $li->id }}" class="imgIDCheckbox" /></td>
                                    <td>{{ @$li->id }}</td>
                                    <td>{{ $USER_INFO[$li->uid] ?? '' }}</td>
                                    <td>
                                        @if($li->status == 0)
                                            <button type="button" class="btn btn-success" onclick="return setStatus({{ $li->id }});">审核</button>
                                        @else
                                            <button type="button" class="btn btn-success" onclick="return setStatus({{ $li->id }});">重新审核</button>
                                        @endif
                                    <td>
                                        @if($li->status == 0) 待审核 @endif
                                        @if($li->status == 1) 审核通过 @endif
                                        @if($li->status == 2) 审核拒绝 @endif
                                    </td>
                                    <td><img src="{{ $li->img_url }}" width="50px" height="30px"></td>
                                    <td>{{ @$li->updated_at }}</td>
                                    <td>  <button type="button" class="btn btn-default" onclick="return showImg('{{ $li->img_url }}');">查看</button></td>
                                </tr>
                            @endforeach

                            @include('admin.mode')
                            @include('admin.common.message')
                            </tbody>
                        </table>
                    </div>
                    <div class="dataTables_info" id="basic-table2_info" role="status" aria-live="polite"> 共{{ @$LIST->total() }}条记录</div>
                    <div class="libaoTurnPage">
                        {{  @$LIST->links() }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<input type="hidden" id="img_id" value="0"/>
<script src="/html/vendor/data-table/media/js/dataTables.bootstrap.min.js"></script>
<script src="/html/javascripts/My97DatePicker/WdatePicker.js"></script>
@include('admin.common.foot')
<script>

    function setAllStatus(){
        $('#ALL_VERITY').modal('show')
    }

    function saveStatusAll(){
        var ids = '';
        var box =document.getElementsByClassName('imgIDCheckbox');
        for (i=0; i< box.length; i++){
            if(box[i].checked){
                if(ids == ''){
                    ids =  box[i].value;
                }else{
                    ids = ids + '#'+box[i].value;
                }
            }
        }
        if(ids == ''){
            alert('请选择渠道');
            return false;
        }

        var token = $("input[name='_token']").val();
        var status = $("input:radio[name='imgStatusAll']:checked").val();

        $('#change_status_all').attr("disabled",true);
        $('#cancel_change_status_all').attr("disabled",true);
        if(status == 2){
            $('#ALL_VERITY').modal('hide');
            $('#CONFIRM_ALL').modal('show');
        }else{
            $.ajax({
                type: 'POST',
                url: '/admin/save/status/all',
                data: {_token:token,ids:ids,status:status},
                success:function(data){
                    $('#show_error_info').html(data.info);
                    $('#show_success_info').html(data.info);

                    $('#change_status_all').attr("disabled",false);
                    $('#cancel_change_status_all').attr("disabled",false);

                    $('#ALL_VERITY').modal('hide')
                    if(data.code == 200){
                        $('#message-success-modal').modal('show')
                    }else{
                        $("#message-error-modal").modal('show');
                    }
                }
            });
        }
    }

    function saveStatusAllCir(){
        var ids = '';
        var box =document.getElementsByClassName('imgIDCheckbox');
        for (i=0; i< box.length; i++){
            if(box[i].checked){
                if(ids == ''){
                    ids =  box[i].value;
                }else{
                    ids = ids + '#'+box[i].value;
                }
            }
        }
        var token = $("input[name='_token']").val();
        var status = $("input:radio[name='imgStatusAll']:checked").val();

        $('#change_status_all_cir').attr("disabled",true);
        $('#caacel_change_status_all_cir').attr("disabled",true);
        $.ajax({
            type: 'POST',
            url: '/admin/save/status/all',
            data: {_token:token,ids:ids,status:status},
            success:function(data){
                $('#show_error_info').html(data.info);
                $('#show_success_info').html(data.info);

                $('#change_status_all_cir').attr("disabled",false);
                $('#caacel_change_status_all_cir').attr("disabled",false);

                $('#CONFIRM_ALL').modal('hide')
                if(data.code == 200){
                    $('#message-success-modal').modal('show')
                }else{
                    $("#message-error-modal").modal('show');
                }
            }
        });
    }

    function imgCheck(obj){
        var box =document.getElementsByClassName('imgIDCheckbox');
        for (i=0; i< box.length; i++){
            if(obj.checked){
                box[i].checked = true;
            }else{
                box[i].checked = false;
            }
        }
    }

    function setStatus(id){
        $('#img_id').val(id);
        $('#VERITY').modal('show')
    }

    function saveStatusCir()
    {
        var id = $('#img_id').val();
        var token = $("input[name='_token']").val();
        var status = 2;

        $('#change_status').attr("disabled",true);
        $('#cancel_change_status').attr("disabled",true);
        $.ajax({
            type: 'POST',
            url: '/admin/save/status',
            data: {_token:token,id:id,status:status},
            success:function(data){
                $('#show_error_info').html(data.info);
                $('#show_success_info').html(data.info);

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

                $('#CONFIRM').modal('hide')
                if(data.code == 200){
                    $('#message-success-modal').modal('show')
                }else{
                    $("#message-error-modal").modal('show');
                }
            }
        });
    }

    function saveStatus(){
        var id = $('#img_id').val();
        var token = $("input[name='_token']").val();
        var status = $("input:radio[name='imgStatus']:checked").val();

        $('#change_status').attr("disabled",true);
        $('#cancel_change_status').attr("disabled",true);
        if(status == 2){
            $('#VERITY').modal('hide');
            $('#CONFIRM').modal('show');
        }else{
            $.ajax({
                type: 'POST',
                url: '/admin/save/status',
                data: {_token:token,id:id,status:status},
                success:function(data){
                    $('#show_error_info').html(data.info);
                    $('#show_success_info').html(data.info);

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

                    $('#VERITY').modal('hide')
                    if(data.code == 200){
                        $('#message-success-modal').modal('show')
                    }else{
                        $("#message-error-modal").modal('show');
                    }
                }
            });
        }
    }

    function showImg(img)
    {
        $('#showImg').attr('src',img);
        $('#GM').modal('show');
    }

    $('#message-success-modal').on('hidden.bs.modal', function () {
        location.reload();
    });

    function verity_field(error_info,id){
        $('#'+id).html(error_info);
        $('#'+id).show();
        return false;
    }

    function cir_cancel(id){
        $('#'+id).modal('hide')
    }


    function check(){
        if($('#username').val() == '' && $('#phone').val() == ''){
            alert('搜索内容不可以为空!');
            return false;
        }
    }
</script>
