@extends('admin.master')

@section('style')
<link href="{{ asset('data/assets/css/bootstrap-datetimepicker.css') }}" rel="stylesheet">
@endsection

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

@section('ordersearch')
<div class="order-search mb-10">
	<div class="clearfix">
		<div class="top-btn-group pull-left">
			@if(config('managerLang') == config('setting.lang'))
				<a href="{{ url('admin/product/create') }}" class="btn btn-primary">
					<i class="iconfont icon-plus"></i><span>添加</span>
				</a>
			@endif
			<a href="{{ url('admin/product-cate') }}" class="btn btn-outline-primary ml-10">
				<span>分类管理</span>
			</a>
        <a href="{{ url('admin/batch-upload') }}" class="btn btn-outline-primary ml-10">
          <span>批量上传</span>
        </a>
		</div>
		<div class="pull-right">
			{!! Form::model($where, ['method'=>'get', 'class'=>'form-inline', 'id' => 'form-select']) !!}
			<div class="form-group pr-10">
				{!! Form::text('title', null, ['class'=>'form-control len wd-search', 'id'=>'kw', 'placeholder'=>'请输入产品名称']) !!}
			</div>
			<div class="form-group pr-10">
				{!! Form::select('pid', ['' => '选择分类'] + $categories, null, ['id'=>'pidCate', 'class'=>'form-control autosize selectpicker show-tick']) !!}
			</div>
      <div class="form-group pr-10">
        {!! Form::select('flag', ['' => '选择状态'] + $flag, null, ['id'=>'flag', 'class'=>'form-control autosize selectpicker show-tick']) !!}
      </div>
			<div class="form-group pr-10">
				{!! Form::select('attribute', ['' => '选择属性'] + $attributes, null, ['id'=>'attribute', 'class'=>'form-control autosize selectpicker show-tick']) !!}
			</div>
      <div class="form-group pr-10">
        {!! Form::select('is_collect', ['' => '是否采集内容'] + $is_collect, null, ['id'=>'is_collect', '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')
{!! Form::open(['route' => 'admin.product.index', 'method' => 'post', '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 width="86" class="text-center">排序</th>
			<th>名称</th>
			<th>预览图</th>
			<th>分类</th>
			<th>属性</th>
			<th>状态</th>
			<th>创建时间</th>
			<th class="text-center">操作</th>
		</tr>
	</thead>
	<tbody>
	@if(!$products->isEmpty())
		@foreach ($products as $value)
			<tr>
				<td align="center">
					<div class="pretty p-default p-smooth">
						<input name="id[]" class="id" type="checkbox" value="{{ $value['id'] }}" onclick="checkItem(this, 'chkAll')">
						<div class="state p-success"><label></label></div>
					</div>
				</td>
				<td align="center">
				    <input name="orders[{{ $value->id }}]" id="orders" value="{{ $value->orders }}" class="form-control text-center">
				</td>
				<td>
					<a href="{{ $value->present()->url }}" title="{{ $value->description->title }}" target="_blank">
						{{ str_limit($value->description->title, $limit = 50, $end = '...') }}
					</a>
				</td>
				<td>
					@if(!empty($value->description->imgs))
            @if(isVideo($value->description->present()->image))
              <a href="javascript:void(0);" class="img product-video">
                <img class="video-icon" src="{{ asset('data/assets/images/controls.png') }}">
                <img src="{{ $value->description->present()->image }}?x-oss-process=video/snapshot,t_1000,f_jpg,w_400,m_fast,ar_auto" class="user-img-list" width="40" height="40">
              </a>
            @else
              <a href="{{ $value->description->present()->image }}" class="img" target="_blank">
                <img src="{{ $value->description->present()->image('40*40') }}" class="user-img-list">
              </a>
            @endif
					@else
						<span class="changegray">暂无图片</span>
					@endif
				</td>
				<td>{{ $value->cates->description->cname or '' }}</td>
				<td>
					<div class="pretty-box">
						<div class="pretty p-default">
							<input id="recom{{ $value['id'] }}" name="recom" data-operating="{{ $value['recom'] == 1 ? 'close' : 'open'}}" type="checkbox" @if($value->recom) checked @endif value="{{ $value['recom'] }}" onclick="fetch_ajax('recom', '{{ $value['id'] }}', 'product');">
							<div class="state p-success"><label>推荐</label></div>
						</div>
						<div class="pretty p-default">
							<input id="top{{ $value['id'] }}" name="top" data-operating="{{ $value['top'] == 1 ? 'close' : 'open'}}" type="checkbox" @if($value->top) checked @endif value="{{ $value['top'] }}" onclick="fetch_ajax('top', '{{ $value['id'] }}', 'product');">
							<div class="state p-success"><label>置顶</label></div>
						</div>
						<div class="pretty p-default">
							<input id="headline{{ $value['id'] }}" name="headline" data-operating="{{ $value['headline'] == 1 ? 'close' : 'open'}}" type="checkbox" @if($value->headline) checked @endif value="{{ $value['headline'] }}" onclick="fetch_ajax('headline', '{{ $value['id'] }}', 'product');">
							<div class="state p-success"><label>头条</label></div>
						</div>
					</div>
				</td>
				<td>
					<span id="flag{{ $value['id'] }}" class="{{ $value['flag'] == 1 ? 'changegreen' : 'changegray'}}" data-operating="{{ $value['flag'] == 1 ? 'close' : 'open'}}" onclick="fetch_ajax('flag', '{{ $value['id'] }}', 'product');" data-open-text="发布" data-close-text="不发布" style="cursor:pointer;">{{ $value['flag'] == 1 ? '发布' : '不发布'}}</span>
				</td>
				<td><span>{{ $value->created_at->format('Y-m-d') }}</span></td>
				<td>
					<div class="toolbar">
						<a href="{{ route('admin.product.edit', $value->id) }}" class="btn-link">修改</a>
						<span class="text-explode ">|</span>
						<a href="javascript:void(0);" data-id="{{ $value->id }}" class="btn-link delete-item">删除</a>
					</div>
				</td>
			</tr>
		@endforeach
		<tr class="footer">
			<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="9">
				<div class="foot-wrap">
					<div class="pull-left">
						@if(config('managerLang') == config('setting.lang'))
							@include('admin.common.translate_models', ['translateModel' => 'product', 'translateModelName' => '产品'])
						@endif
						<input name="btn_del" type="button" value="删 除" class="btn btn-default delet-select">
						<input name="btn_order" type="button" value="更新排序" onclick="javascript:update_orders('product');" class="btn btn-default button-order all-order">
						{!! Form::select('pid', ['请选择'] + $categories, null, ['id'=>'pid', 'class'=>'form-control autosize']) !!}
						<input name="btn_order" type="button" value="移 动" data-text="移动" data-model="product" data-action="move" class="btn btn-default button-order all-submit">
						<input name="btn_order" type="button" value="复 制" data-text="复制" data-model="product" data-action="copy" class="btn btn-default button-order all-submit">
					</div>
					@if(!empty($products->render()))
					<div class="pull-right">
						<div class="pagination-info">共有{{ $products->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 {{ $products->perPage() == 20 ? 'selected': ''}} value="20">20条/页</option>
                <option {{ $products->perPage() == 30 ? 'selected': ''}} value="30">30条/页</option>
                <option {{ $products->perPage() == 50 ? 'selected': ''}} value="50">50条/页</option>
                <option {{ $products->perPage() == 100 ? 'selected': ''}} value="100">100条/页</option>
              </select>
            </div>
						{!! $products->appends($where)->render() !!}
					</div>
					@endif
				</div>
			</td>
		</tr>	
	@endif
	</tbody>
</table>
@if($products->isEmpty())
	<div class="nodata-wrap">
		<div class="notice-null"><span class="inline-block">暂无数据</span></div>
	</div>
@endif

{!! Form::close() !!}
@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')
<script type="text/javascript">
    //批量删除
    $('.delet-select').on('click', function(){	
        var ids = [];
        $('.id:checked').each(function(){
            ids.push(this.value);
        });
        ids = ids.join('-');

        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');
    });

    // 删除
    $('.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) {
                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
