@extends('admin.layout') 

@section('content')
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5>经销商管理</h5>
					<div class="ibox-tools">
						<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
						</a>
					</div>
				</div>
				<div class="ibox-content">
				    <div class="row">
				        <form method="GET" action="" accept-charset="UTF-8">

				        <div class="col-sm-4">
				            <div class="input-group">
								<input type="text" value="{{Request::get('keyword')}}"	placeholder="可搜索ID/电话/地址/名称" name="keyword"class="input-sm form-control">
								<span class="input-group-btn">
									<button type="submit" class="btn btn-sm btn-primary">搜索</button>
								</span>
    						</div>
				        </div>
				        </form>
						<div class="col-sm-4 pull-left">
							<a href="{{ U('Album/Agent/index', ['status' => -1])}}" class="btn btn-sm btn-primary pull-left" style="margin-left: 1px;">全部</a>
							<a href="{{ U('Album/Agent/index', ['status' => 1])}}" class="btn btn-sm btn-primary pull-left" style="margin-left: 1px;">未审核</a>
							<a href="{{ U('Album/Agent/index', ['status' => 2])}}" class="btn btn-sm btn-primary pull-left" style="margin-left: 1px;">已审核</a>
							<a href="{{ U('Album/Agent/index', ['status' => 3])}}" class="btn btn-sm btn-primary pull-left" style="margin-left: 1px;">BOSS</a>
						</div>
						@if(role('Album/Agent/batch'))
    					<div class="col-sm-3 pull-right">
    					   <a class="btn btn-sm btn-primary pull-right" onclick="batch()">批量审核</a>
    					</div>
						@endif
					</div>
					
					<table class="table table-striped table-bordered table-hover dataTables-example dataTable">
						<thead>
    						<tr>
								<th><input class="checkAll" type="checkbox"></th>
								<th class="sorting" data-sort="id"> ID </th>
								<th> 微信昵称 </th>
								<th class="sorting" data-sort="name"> 名称 </th>
								<th class="sorting" data-sort="user_id"> 电话 </th>
								<th class="sorting" data-sort="address"> 地址 </th>
								<th class="sorting" data-sort="status"> 审核状态 </th>
								<th>是否为boss</th>
        						<th width="22%">相关操作</th>
        					</tr>
						</thead>
						<tbody>
						@if(isset($list))
							@foreach($list as $key => $item)							<tr>
								<td><input id="{{ $item->user_id }}" class="checkItem" name="checkItem" type="checkbox"></td>
								<td>{{ $item->id }}</td>
								<td>{{ $item->nickname }}</td>
								<td>{{ $item->name }}</td>
								<td>{{ $item->phone }}</td>
								<td>{{ $item->address }}</td>
								<td>{{ $item->status }}</td>
								@if($item->is_boss != 1)
									<td>不是</td>
								@else
									<td>是</td>
								@endif
								<td>
									<div class="pull-left">
										@if(role('Album/User/role-boss'))
											@if($item->is_boss == 0)
												<a href="{{ U('Album/User/role',['id'=>$item->user_id,'role'=>4]) }}" class="btn btn-sm btn-default pull-right">设为Boss
												</a>
											@else
												<a href="{{ U('Album/User/role',['id'=>$item->user_id,'role'=>5]) }}" class="btn btn-sm btn-default pull-right">取消Boss
												</a>
											@endif
										@endif

										@if(role('Album/Agent/update'))
												<a href="{{ U('Album/Agent/update',['id'=>$item->id])}}" class="btn btn-sm btn-warning pull-right">修改</a>
										@endif
										@if(role('Album/Agent/status'))
												@if($item->status == '待审核')
													<a href="{{ U('Album/Agent/status',['id'=>$item->id,'status'=>1])}}" onclick="return confirm('你确定通过审核？');" class="btn btn-sm btn-success pull-right">通过审核</a>
												@endif
										@endif
										@if(role('Album/Agent/destroy'))
												<a href="{{ U('Album/Agent/destroy',['id'=>$item->id])}}" onclick="return confirm('你确定执行删除操作？');" class="btn btn-sm btn-danger pull-right">删除</a>
										@endif
										@if(role('Album/Product/Price/index'))
											@if($item->status == '已审核')
												<a href="{{ U('Album/Product/Price/index',['id'=>$item->id])}}" class="btn btn-sm btn-primary pull-left">查看报价</a>
											@endif
										@endif

									</div>
								</td>
							</tr>
							@endforeach
							@endif

						</tbody>
					</table>
					<div class="row">
						<div class="col-sm-6">
							<div class="dataTables_info" id="DataTables_Table_0_info"
								role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}条，共{{ $list->lastPage() }}页，总{{ $list->total() }}条。</div>
						</div>
						<div class="col-sm-6">
						<div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
						{!! $list->setPath('')->appends(Request::all())->render() !!}
						</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<link href="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/css/plugins/toastr/toastr.min.css" rel="stylesheet">
<script src="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/js/plugins/toastr/toastr.min.js"></script>
<script>
    toastr.options.positionClass = 'toast-bottom-center';
    var checkArr = [];
    $(".checkItem").click(function () {
        checkArr = [];
        $("input:checkbox[name=checkItem]:checked").each(function () {
            checkArr.push($(this).attr("id"))
        })
    })

	$(".checkAll").click(function () {
        $(".checkItem").each(function () {
            if ($(this).prop('checked')) {
                $(this).prop('checked',false)
            } else {
                $(this).prop('checked',true)
            }
		})
        checkArr = [];
        $("input:checkbox[name=checkItem]:checked").each(function () {
            checkArr.push($(this).attr("id"))
        })
    })


	function batch(){
        if (confirm('确定执行批量操作吗？')) {
            if (checkArr.length <= 0) {
                toastr.error('请勾选需要操作的数据!');
                return false;
            }
            $.ajax({
                url: "{{ U('Album/Agent/batch') }}",
                method: 'POST',
                data: {
                    'data': checkArr,
                    '_token':"{{ csrf_token() }}"
                },
                dataType:'json',
                success: function(data) {
					toastr.success('执行成功！')
                    setTimeout(function () {
                        location.reload();
                    }, 3000);
                }
            });
		}
		return;
	}
</script>
@endsection