<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>商品报表</title>
		<link rel="stylesheet" href="/zzhnc/res/plugins/layui/css/layui.css">
		<link rel="stylesheet" href="/zzhnc/res/css/basic.css">
	</head>
	<style>
		.floatR {
			float: right;
			line-height: 36px;
			padding-right: 40px;
		}
		
		.floatR span {
			color: red;
			font-size: 1.4em;
		}
	</style>

	<body class="wrap">
		<div class="layui-form">
			<div class="layui-form-item">
				<div class="layui-input-inline">
					<input type="text" class="layui-input" name="key" placeholder="关键字" />
				</div>
				<button class="layui-btn" lay-submit lay-filter="querybtn">查询</button>
				<button class="layui-btn layui-btn-primary resetBtn" type="reset">重置</button>
			</div>
		</div>
		<table class="layui-table">
			<thead>
				<tr>
					<th>No</th>
					<th>商品主图</th>
					<th>商品标题</th>
					<th>转发数</th>
					<th>浏览数</th>
				</tr>
			</thead>
			<tbody id="tablelist">

			</tbody>
		</table>
		<div class="nodata">暂无数据</div>
		<div id="page"></div>
	</body>

	<script src='/zzhnc/res/js/jquery.min.js'></script>
	<script src="/zzhnc/res/plugins/layui/layui.js"></script>
	<script src="/zzhnc/res/js/me.js"></script>
	<script>
		layui.use(['form', 'element', 'laypage'], function() {
			var form = layui.form,
				element = layui.element,
				laypage = layui.laypage;

			//查询条件
			var queryObj = {
				page: 1,
				size: 10,
				sellerId: 0,
				key: null
			};

			//初始化方法
			function initData(queryObj) {
				$.get("/zzhnc/goods/search", queryObj, function(data) {
					data = data.data;
					console.log(data)
					$("#tablelist").html("");
					var str = "";
					if(data.rows.length < 1) {
						$(".nodata").show();
					} else {
						$(".nodata").hide();
						var str = "";
						for(var i = 0; i < data.rows.length; i++) {
							str += '<tr data-id=' + data.rows[i].id + '>' +
								'<td>' + ((data.page - 1) * data.pageSize + i + 1) + '</td>' +
								'<td><img class="imgUrl" src="' + data.rows[i].bannerUrl + '"  /></td>' +
								'<td>' + data.rows[i].name + '</td>' +
								'<td>' + data.rows[i].shareCount + '</td>' +
								'<td>' + data.rows[i].pageViews + '</td>' +
								'</tr>';
						}
						$("#tablelist").html(str);
						form.render();
						toNull_G();
					}
					laypage.render({
						elem: 'page',
						count: data.total,
						limit: queryObj.size,
						curr: queryObj.page,
						layout: ['count', 'prev', 'page', 'next', 'skip'],
						jump: function(obj, first) {
							if(!first) {
								queryObj.page = obj.curr
								initData(queryObj);
							}
						}
					})
				})
			}

			//初始化数据
			initData(queryObj);

			//查询
			form.on('submit(querybtn)', function(data) {
				queryObj.page = 1;
				queryObj.key = $("[name=key]").val();
				initData(queryObj);
			});

			//重置
			$(".resetBtn").on("click", function() {
				$("[name=key]").val("");
				queryObj.page = 1;
				queryObj.key = null;
				initData(queryObj);
			})

		})
	</script>

</html>