@extends('admin.master')
@section('style')
<style>
  /* 重置外部样式 */
  .sun .content-box {
    border-radius: 0;
    background: transparent;
    -webkit-box-shadow: none;
    box-shadow: none;
    padding: 0;
  }
</style>
@endsection

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

@section('ordersearch')
<div class="order-search mb-10">
	<div class="clearfix">
		<div class="pull-left">
			{!! Form::model($where, ['method'=>'get', 'class'=>'form-inline', 'id' => 'form-select']) !!}
      <div class="form-group pr-10">
        {!! Form::select('model_type', ['' => '评论来源', 'product' => '产品', 'case' => '案例', 'news' => '新闻', 'album' => '相册', 'download' => '下载', 'job' => '招聘', 'video' => '视频'], null, ['id'=>'flag', 'class'=>'form-control autosize selectpicker show-tick']) !!}
      </div>
			<div class="form-group pr-10">
				{!! Form::select('status', ['' => '显示状态', 0 => '隐藏', 1 => '显示'], null, ['id'=>'attribute', 'class'=>'form-control autosize selectpicker show-tick']) !!}
			</div>
			<button type="submit" class="btn btn-primary">
				<i class="iconfont icon-sousuo2"></i>
			</button>
			{!! Form::close() !!}
		</div>
	</div>
</div>
@endsection
 
@section('content')
@if(!$comments->isEmpty())
<ul class="comment-list">
  @foreach ($comments as $value)
  <li class="comment-item">
    <div class="comment-item-left">
      <div class="comment-item-avatar"><img src="{{ asset('/data/assets/images/avatar.png') }}" alt=""></div>
      <div class="comment-item-info">
        <h3>{{$value['name'] ?? '匿名'}}</h3>
        <p><i class="iconfont icon-a-217shijian"></i><span>{{substr($value['created_at'], 0, 10) }}</span></p>
        <p><i class="iconfont icon-IPdizhixiaoyanbuhefa-01"></i><span>{{$value['ip']}}</span></p>
      </div>
    </div>
    <div class="comment-item-middle">
      <div class="comment-item-content">{{$value['content']}}</div>
      <p>联系方式：<span>{{ $value['contact'] }}</span></p>
    </div>

    <div class="comment-item-right">
      @if ($value['is_display'])
      <a href="javascript:;" class="changeStatus" data-status='0' data-id="{{$value['id']}}"><i class="iconfont icon-yanjing_yincang"></i><span>隐藏</span></a>
      @else
      <a href="javascript:;" class="changeStatus disabled" data-status='1' data-id="{{$value['id']}}"><i class="iconfont icon-a-lujing11"></i><span>显示</span></a>
      @endif
      <a href="/admin/comment/{{$value['id']}}" class="show-view"><i class="iconfont icon-doc-content"></i><span>详情</span></a>
      <a href="javascript:;" class="delete-item" data-id="{{$value['id']}}"><i class="iconfont icon-pinhetuxing1"></i><span>删除</span></a>
    </div>
  </li>
  @endforeach
</ul>

@if(!empty($comments->render()))
  <div class="comment-pagination">
    <div class="pagination-info">共有{{ $comments->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 {{ $comments->perPage() == 20 ? 'selected': ''}} value="20">20条/页</option>
          <option {{ $comments->perPage() == 30 ? 'selected': ''}} value="30">30条/页</option>
          <option {{ $comments->perPage() == 50 ? 'selected': ''}} value="50">50条/页</option>
          <option {{ $comments->perPage() == 100 ? 'selected': ''}} value="100">100条/页</option>
        </select>
      </div>
      {!! $comments->appends($where)->render() !!}
  </div>
@endif

@else
	<div class="nodata-wrap">
		<div class="notice-null"><span class="inline-block">暂无数据</span></div>
	</div>
@endif
@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-yellow'></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 -->
@endsection

@section('foot')
<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;		
});
$('body').on('click', '.btn-modal-ok', function() {
	$(this).parents('#dialog').modal('hide');
	$.ajax({
		type: "DELETE",
		url: url,
		success: function(data) {
			swal({
        title: "", 
        text: "评论删除成功！",
        type: "success",
        showConfirmButton: false,
        timer: 1200,
      });
      setTimeout(function () {
        window.location.reload();
      }, 500);
		}
	});
});
$(".changeStatus").click(function (){
  var status = $(this).data('status');
  var id = $(this).data('id');
  $.ajax({
    type: 'POST',
    url: '/admin/comment/' + id,
    success: function (res) {
      setTimeout(function () {
        window.location.reload();
      }, 500);
    }
  })
})
</script>
@endsection