@import helper._
@(title: String)(implicit request: RequestHeader)
@layout(title) {
<body class="layui-container" style="width: 95%;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>商品信息</legend>
</fieldset>
<!--页面主体开始-->
<div>
<form class="layui-form layui-form-pane">
<div class="layui-form-item" style="display: inline-block">
<label class="layui-form-label">商品查询</label>
<div class="layui-input-block">
<div class="layui-input-inline" style="width: 350px;" >
<input class="layui-input" id="searchValue" name="searchValue" type="text" placeholder="商品名、商品类型ID、条形码、供应商ID" value="" />
</div>
<a id="searchButton" class="layui-btn" >查询</a>
<a id="add" class="layui-btn" onclick="add()">商品录入</a>
<a href="/merch_manage" class="layui-btn">刷新</a>
</div>
</div>
</form>
</div>
<div>
<p id="memberCount" style="font-size: 18px;"></p>
<table class="layui-table">
<colgroup>
<col width="80">
<col width="80">
<col width="150">
<col width="200">
<col width="100">
<col width="100">
<col width="100">
<col width="100">
<col width="100">
<col width="100">
<col width="100">
<col width="90">
<col width="150">
</colgroup>
<thead>
<tr>
<th>商品编号</th>
<th>类型编号</th>
<th>商品名称</th>
<th>条形码</th>
<th>库存数量</th>
<th>预设进货数</th>
<th>库存报警数量</th>
<th>货架数量</th>
<th>货架预设数量</th>
<th>进价</th>
<th>售价</th>
<th>供应商编号</th>
<th>操作</th>
</tr>
</thead>
<tbody id="table">
<!--插入动态数据-->
</tbody>
</table>
</div>
<div id="paged" class="" style="text-align: center"></div>
<script>
//分页参数设置
var startIndex = 0;//记录开始的索引
var limitValue = 10;//每页显示的记录条数
var currentPage = 1; //当前页数
var dataLength = 0; //数据总条数
var token = '@CSRF.getToken.value';
$(document).ready(function () {
$("#add_form").hide();
$("#update_form").hide();
//ajax请求数据
getdata();
//点击搜索时 搜索数据
$("#searchButton").click(function () {
getdata();
currentPage = 1; //当点击搜索的时候,应该回到第一页
toPage();//然后进行分页的初始化
});
//分页渲染
toPage();
});
function getdata() {
$.ajax({
type: "post",
async: false,
url: "/merch_page_list?csrfToken=" + token,
data: {
start: startIndex,
limit: limitValue,
searchValue:$("#searchValue").prop("value")
},
success: function (data, status) {
dataLength = data.total;
parse_table(data.data);
}
});
}
function parse_table(data) {
var rows = "";
$.each(data, function (v, o) {
var color = "white";
if(!o.alowSale){
color = "#ff572280";
}
rows += '<tr bgcolor="'+ color +'"><td>' + o.merchId + '</td>';
rows += '<td>' + o.merchTypeId + '</td>';
rows += '<td>' + o.merchName + '</td>';
rows += '<td>' + o.barcode + '</td>';
rows += '<td>' + o.stockNum + '</td>';
rows += '<td>' + o.planNum + '</td>';
rows += '<td>' + o.cautionNum + '</td>';
rows += '<td>' + o.selfNum + '</td>';
rows += '<td>' + o.selfPreNum + '</td>';
rows += '<td>' + (o.merchPrice).toFixed(2) + '</td>';
rows += '<td>' + (o.salePrice).toFixed(2) + '</td>';
rows += '<td>' + o.provideId + '</td>';
rows += '<td><a href="javascript:void(0)" class="layui-btn layui-btn-xs update" onclick="update(' + o.merchId + ')" style="margin-top: 10px">修改</a><span> </span>';
if(o.alowSale){
rows += '<a href="/merch_forbid/'+ o.merchId+ '" class="layui-btn layui-btn-xs layui-btn-warm" style="margin-top: 10px">禁售</a><span> </span>'
}else {
rows += '<a href="/merch_sale/'+ o.merchId+ '" class="layui-btn layui-btn-xs layui-btn-warm" style="margin-top: 10px">恢复</a><span> </span>'
}
rows += '<a href="/merch_delete/' + o.merchId + '" class="layui-btn layui-btn-xs layui-btn-danger" style="margin-top: 10px">删除</a></td></tr>';
})
if (data.length > 0) {
$("#paged").show();
$("#table").html(rows);
} else {
$("#paged").hide();
$("#table").html("<br><tr><td colspan='13'><h1 style='width:100%;height: 30px;display: block;text-align: center'><span>数据库未录入!</span></h1></td></tr>");
}
}
function toPage() {
layui.use(['laypage'], function () {
var laypage = layui.laypage;
var limit = limitValue;
laypage.render({
elem: 'paged',
count: dataLength,
limit: limit,
curr: currentPage,
skip: true,
jump: function (obj, first) {
currentPage = obj.curr;
startIndex = (obj.curr - 1) * obj.limit;
if (!first) {
getdata();
}
}
});
});
}
function add() {
layui.use('layer', function () {
var layer = layui.layer;
layer.open({
closeBtn: 2,
skin: 'layui-layer-lan',
type: 1 //Page层类型