#@layout()
#define script()
<script>

	function trash(id) {
		ajaxGet("#(CPATH)/admin/product/doTrash/" + id);
	}


	function draft(id) {
		ajaxGet("#(CPATH)/admin/product/doDraft/" + id);
	}

	function normal(id) {
		ajaxGet("#(CPATH)/admin/product/doNormal/" + id);
	}

	function del(id) {
		if (confirm('确定要删除该产品吗？删除后不可恢复')) {
			ajaxGet("#(CPATH)/admin/product/doDel/" + id);
		}
	}

	$("#batchDel").click(function () {
		var ids = getSelectedIds();
		if (ids == "") {
			alert('您未选择任何内容');
			return
		}
		if (confirm('确定要删除该产品吗？删除后不可恢复')) {
			ajaxGet("#(CPATH)/admin/product/doDelByIds?ids=" + ids);
		}
	})
</script>

#end

#define content()
<div class="content-wrapper">

	<section class="content-header">
		<h1>
			产品管理
			<small>Product Management</small>
		</h1>
	</section>

	<section class="content-header text-tap">
		<a href="#(CPATH)/admin/product">全部 (#(totalCount ?? 0))</a> |
		<a href="?status=1">已上架 (#(normalCount ?? 0))</a> |
		<a href="?status=2">草稿 (#(draftCount ?? 0))</a> |
		<a href="?status=3" style="color: #a00">垃圾箱 (#(trashCount ?? 0))</a>
	</section>

	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="box box-primary">
					<div class="box-header with-border">
						<form class="form-horizontal actionPanel" action="#(CPATH)/admin/product" method="get">
							<input type="hidden" name="status" value="#para('status')">
							<div class="row">
								<div class="form-group col-lg-4">
									<label class="col-sm-3 control-label">标题</label>
									<div class="col-sm-9">
										<input type="text" class="form-control" name="title" value="#para('title')">
									</div>
								</div>
								<div class="form-group col-lg-4">
									<label class="col-sm-3 control-label">分类</label>
									<div class="col-sm-9">
										<select class="form-control" name="categoryId">
											<option value="">全部分类</option>
											#for(category : categories)
											<option value="#(category.id ??)" #selectedIf(category.isCheck)>
												#(category.layerString)#(category.title ??)
											</option>
											#end
										</select>
									</div>
								</div>
								<div class="form-group col-lg-4">
									<div class="col-sm-12">
										<button type="submit" class="btn btn-primary ">查询</button>
										<button type="reset" class="btn btn-default">重置</button>
										<a class="btn"> 更多<i class="fa fa-fw fa-angle-down"></i> </a>
									</div>
								</div>
							</div>
							<!-- /.box-body -->
						</form>

						<div class="row actionPanel">
							<div class="col-xs-12">
								<a href="#(CPATH)/admin/product/edit" class="btn btn-primary "> <i
										class="fa fa-fw fa-plus"></i> 新建</a>
								<button type="button" id="batchDel" class="btn btn-default checkAction"> 批量删除</button>
							</div>
						</div>

					</div>
					<!-- /.box-header -->
					<div class="box-body ">

						<table class="table table-striped">
							<tbody>
							<tr>
								<th style="width: 10px">
									<input name="dataItem" onchange="checkAll(this)" type="checkbox" value="0"/>
								</th>
								<th style="width: 350px">标题</th>
								<th style="width: 50px">价格</th>
								<th style="width: 50px">销量</th>
								<th>分类</th>
								<th>标签</th>
								<th style="width: 50px"><i class="fa fa-commenting"></i></th>
								<th style="width: 90px">发布时间</th>
							</tr>

							#for(product : page.list)
							<tr class="jp-actiontr">
								<td><input class="dataItem" type="checkbox" value="#(product.id)"/>
								</td>
								<td>
									<!--<div style="width: 20px;height: 20px">-->
										<!--<img src="#(CPATH)#(product.thumbnail ??)" style="width: 100%;height: 100%">-->
									<!--</div>-->
									<!--<div style="float: right">-->
										<strong>
											<a href="#(CPATH)/admin/product/edit/#(product.id)">#(product.title ??)</a>
											#if(product.isDraft())
											（草稿）
											#end
										</strong>
										<div class="jp-actionblock">
											#if(product.isNormal())
											<div class="jp-actionitem">
												<a href="#(CPATH)/admin/product/edit/#(product.id)">编辑</a> |
												<a href="javascript:;" onclick="draft('#(product.id??)')">草稿</a>
												|
												<a href="javascript:;" onclick="trash('#(product.id??)')"
												   class="red-action">垃圾箱</a>|
												<a href="#(product.url ??)" target="_blank" class="red-action">查看</a>
											</div>
											#elseif(product.isDraft())
											<div class="jp-actionitem">
												<a href="#(CPATH)/admin/product/write/#(product.id)">编辑</a> |
												<a href="javascript:;" onclick="trash('#(product.id??)')"
												   class="red-action">垃圾箱</a>
											</div>
											#else
											<div class="jp-actionitem">
												<a href="javascript:;" onclick="draft('#(product.id??)')">还原</a>
												|
												<a href="javascript:;" onclick="del('#(product.id??)')" class="red-action">永久删除</a>
											</div>
											#end
										</div>
									<!--</div>-->

								</td>
								<td>
										#(product.price ??)
								</td>
								<td>
										#(product.real_sales_count ?? '0' )（#(product.sales_count ?? '0')）
								</td>
								
								<td>
									#productCategories(product.id,"category")
									#for(category : categories)
									<a href="#(category.url ??)" target="_blank">#(category.title ??)</a>
									#if(!for.last) , #end
									#end
									#end
								</td>
								<td>
									#productCategories(product.id,"tag")
									#for(category : categories)
									<a href="#(category.url ??)" target="_blank">#(category.title ??)</a>
									#if(!for.last) , #end
									#end
									#end
								</td>
								<td>
									<a href="#(CPATH)/admin/product/comment?productId=#(product.id)">
										#(product.comment_count ??)
									</a>
								</td>
								<td>#date(product.created)</td>
							</tr>
							#end

							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
					<div class="box-footer">
						<div class="row">
							<div class="col-sm-12">
								#@_paginate()
							</div>
						</div>
					</div>
				</div>
				<!-- /.box -->
			</div>
		</div>

	</section>


</div>
#end
