@extends('admin.master')

@section('top')
	<div class="top-breadcrumb">
		<h5>标签管理</h5>
	</div>
@endsection

@section('ordersearch')
<div class="order-search mb-10">
	<div class="clearfix">
    @if(config('managerLang') == config('setting.lang'))
		<div class="top-btn-group pull-left">
			<a href="{{ url('admin/tag/create') }}" class="btn btn-primary">
				<i class="iconfont icon-plus"></i><span>添加</span>
			</a>
		</div>
    @endif
		<div class="pull-right" style="display: flex; align-items: center;">
			{!! Form::model($where, ['method'=>'get', 'class'=>'form-inline', 'id' => 'form-select']) !!}
			<div class="form-group pr-10">
				{!! Form::text('name', null, ['class'=>'form-control len wd-search', 'id'=>'kw', 'placeholder'=>'请输入标签名称']) !!}
			</div>
      <div class="form-group pr-10">
        {!! Form::select('flag', ['' => '选择状态', 1 => '已使用', 2 => '未使用'], null, ['id'=>'flag', 'class'=>'form-control autosize selectpicker show-tick']) !!}
      </div>
      <div class="form-group pr-10">
        {!! Form::select('order', ['' => '选择排序', 1 => '倒序', 2 => '正序'], null, ['id'=>'order', 'class'=>'form-control autosize selectpicker show-tick']) !!}
      </div>
			<button type="submit" class="btn btn-primary">
				<i class="iconfont icon-sousuo2"></i>
			</button>
			{!! Form::close() !!}
			<a class="search-keyword" href="{{url('admin/tag/keyword')}}">
				<i class="iconfont icon-suoyoufenlei"></i> 查询关键词
			</a>
		</div>
	</div>
</div>
@endsection

@section('content')
<div class="form-ajax">
<table class="table table-hover">
	<thead>
		<tr>
			<th width="60" class="text-center">
				<div class="pretty p-default p-smooth">
					<input name="chkAll" type="checkbox" id="chkAll" onclick="checkAll(this, 'id[]')" value="checkbox">
					<div class="state p-success"><label></label></div>
				</div>
			</th>
			<th>标签名称</th>
      <th>使用次数</th>
			<th>创建时间</th>
			<th width="110" class="text-center">操作</th>
		</tr>
	</thead>
	<tbody>
	@if(!$tags->isEmpty())
		@foreach ($tags as $value)
			<tr>
				<td align="center">
					<div class="pretty p-default p-smooth">
						<input name="id[]" class="id" type="checkbox" value="{{ $value['tag_id'] }}" onclick="checkItem(this, 'chkAll')">
						<div class="state p-success"><label></label></div>
					</div>
				</td>
				<td>
					<div title="{{ $value->name }}">{{ str_limit($value->name, $limit = 50, $end = '...') }}</div>
				</td>
        <td>
          {{ $value->taggables->count() }}
        </td>
				<td><span class="text-success">{{ $value->created_at }}</span></td>
				<td class="text-right">
					<div class="toolbar">
						<a href="{{ route('admin.tag.edit', $value->tag_id) }}" class="btn-link">修改</a>
						<span class="text-explode ">|</span>
						<a href="javascript:void(0);" data-id="{{ $value->tag_id }}" class="btn-link delete-item">删除</a>
					</div>
				</td>
			</tr>
		@endforeach
		<tr>
			<td align="center">
				<div class="pretty p-default p-smooth">
					<input name="chkAll" type="checkbox" id="chkAll" onclick="checkAll(this, 'id[]')" value="checkbox">
					<div class="state p-success"><label></label></div>
				</div>
			</td>
			<td class="text-left" colspan="6">
				<div class="foot-wrap">
					<div class="pull-left">
						@if(config('managerLang') == config('setting.lang'))
							@include('admin.common.translate_models', ['translateModel' => 'tag', 'translateModelName' => '标签'])
						@endif
						<input name="btn_del" type="button" value="删 除" class="button delet-select btn-primary" >&nbsp;&nbsp;共[ <b class="text-warning">{{ $tags->count() }}</b> ]条记录&nbsp;&nbsp;
					</div>
					@if(!empty($tags->render()))
					<div class="pull-right">
						<div class="pagination-info">共有{{ $tags->total() }}条</div>
            <div class="pagination-info" style="padding-left: 0">
              <select id="perPage" class="form-control autosize selectpicker show-tick" name="perPage" form="form-select">
                <option {{ $tags->perPage() == 20 ? 'selected': ''}} value="20">20条/页</option>
                <option {{ $tags->perPage() == 30 ? 'selected': ''}} value="30">30条/页</option>
                <option {{ $tags->perPage() == 50 ? 'selected': ''}} value="50">50条/页</option>
                <option {{ $tags->perPage() == 100 ? 'selected': ''}} value="100">100条/页</option>
              </select>
            </div>
						{!! $tags->appends($where)->render() !!}
					</div>
					@endif
				</div>
			</td>
		</tr>	
	@endif
	</tbody>
</table>
@if($tags->isEmpty())
	<div class="nodata-wrap">
		<div class="notice-null"><span class="inline-block">暂无数据</span></div>
	</div>
@endif
</div>
@endsection

@section('notice')
<!-- Modal -->
<div class="modal fade" id="dialog" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
            <div class='col-sm-1 text-center'><i class='iconfont icon-zhuyi'></i></div>
            <div class='col-sm-11 breakall'><p>删除后您将无法恢复，请谨慎操作</p><p class='text-muted'>您确认要删除吗？</p></div>
        </div>
        <div class="modal-footer">
        	<button type="button" class="btn btn-primary btn-modal-ok">确定</button>
        	<button class="btn btn-default btn-modal-cancel btn-modal-close" data-dismiss="modal">取消</button>
        </div>
    </div>
  </div>
</div>
<!-- Modal End -->
<!-- Modal -->
<div class="modal fade" id="dialog-tip" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
			<div class='col-sm-1 text-center'><i class='fa fa-times-circle text-size-32 text-warning'></i></div>
			<div class='col-sm-11 breakall'><p class="delete-error">删除失败！</p></div>
		</div>	
        <div class="modal-footer">
			<button class="btn btn-primary btn-modal-close" data-dismiss="modal">确定</button>
        </div>
    </div>
  </div>
</div>
<!-- Modal End -->
<!-- Modal -->
<div class="modal fade" id="dialog-common" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
            <div class='col-sm-1 text-center'><i class='iconfont icon-zhuyi'></i></div>
            <div class='col-sm-11 breakall'><p class="common">请选择要删除的内容!</p></div>
        </div>
        <div class="modal-footer">
        	<button type="button" class="btn btn-primary btn-modal-common">确定</button>
        </div>
    </div>
  </div>
</div>
<!-- Modal End -->
@endsection

@section('foot')
  @if (inject('setting')->config('translate_remind') && Session::has('success'))
    @include('admin.common.translate_remind')
    <script>
        $('#dialog-remind').modal('show');
    </script>
  @endif
<script type="text/javascript">
// 删除
$('.delete-item').on('click', function(e) {
	var deleteAction = location.pathname;
	var id = $(this).data('id');
	url = deleteAction + '/' + id;

	$('#dialog').modal('show');
	return false;		
});

//批量删除
$('.delet-select').on('click', function(){	
	var ids = [];
	$('.id:checked').each(function(){
		ids.push(this.value);
	});
	ids = ids.join('-');
	console.log(ids);
	if (!ids) {
		$('.common').text('请选择要删除的内容!');
		$('#dialog-common').modal('show');
		return false;
	}
	url = location.pathname + '/' + ids;

	$('#dialog').modal('show');
	return false;	
});

$('body').on('click', '.btn-modal-common', function(){
	$(this).parents('#dialog-common').modal('hide');
});

$('body').on('click', '.btn-modal-ok', function() {
	$(this).parents('#dialog').modal('hide');
	$.ajax({
		type: "DELETE",
		url: url,
		success: function(data) {
			if (data.status == 'sucess') {
				swal({
					title: "", 
					text: "信息删除成功！",
					type: "success",
					showConfirmButton: false,
					timer: 1200,
				});
				setTimeout("location.reload()", 1200);
			} else {
				$('.delete-error').html('删除失败！');
				$('#dialog-tip').modal('show');
			}
		}
	});
});

$('#perPage').change(function(){
    $('#form-select').submit();
})
</script>
@endsection