193 lines
5.8 KiB
HTML
193 lines
5.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>产品列表</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
<link rel="stylesheet" href="../../css/oksub.css">
|
|
<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="ok-body">
|
|
<!--模糊搜索区域-->
|
|
<div class="layui-row">
|
|
<form class="layui-form layui-col-md12 ok-search">
|
|
<input class="layui-input" placeholder="开始日期" autocomplete="off" id="startTime" name="startTime">
|
|
<input class="layui-input" placeholder="截止日期" autocomplete="off" id="endTime" name="endTime">
|
|
<input class="layui-input" placeholder="请输入标题" autocomplete="off" name="title">
|
|
<button class="layui-btn" lay-submit="" lay-filter="search">
|
|
<i class="layui-icon layui-icon-search"></i>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
<!--数据表格-->
|
|
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
|
|
</div>
|
|
<!--js逻辑-->
|
|
<script src="../../lib/layui/layui.js"></script>
|
|
<script>
|
|
layui.use(["table", "form", "laydate", "okLayer", "okUtils", "okMock"], function () {
|
|
let table = layui.table;
|
|
let form = layui.form;
|
|
let util = layui.util;
|
|
let laydate = layui.laydate;
|
|
let okLayer = layui.okLayer;
|
|
let okUtils = layui.okUtils;
|
|
let okMock = layui.okMock;
|
|
okLoading.close();
|
|
util.fixbar({});
|
|
|
|
laydate.render({elem: "#startTime", type: "datetime"});
|
|
laydate.render({elem: "#endTime", type: "datetime"});
|
|
|
|
let articleTable = table.render({
|
|
elem: "#tableId",
|
|
url: okMock.api.listProduct,
|
|
limit: 20,
|
|
page: true,
|
|
even: true,
|
|
toolbar: "#toolbarTpl",
|
|
size: "lg",
|
|
cols: [[
|
|
{type: "checkbox", fixed: "left"},
|
|
{field: "id", title: "ID", width: 200, sort: true},
|
|
{field: "name", title: "产品名称", width: 100},
|
|
{field: "logo", title: "产品LOGO", width: 150, templet: "#logoTpl"},
|
|
{field: "url", title: "产品官网", width: 200, templet: "#urlTpl"},
|
|
{field: "description", title: "产品描述", width: 400},
|
|
{field: "createTime", title: "创建时间", width: 180},
|
|
{field: "updateTime", title: "更新时间", width: 180},
|
|
{title: "操作", width: 100, align: "center", fixed: "right", templet: "#operationTpl"}
|
|
]],
|
|
done: function (res, curr, count) {
|
|
console.log(res, curr, count)
|
|
}
|
|
});
|
|
|
|
form.on("submit(search)", function (data) {
|
|
articleTable.reload({
|
|
where: data.field,
|
|
page: {curr: 1}
|
|
});
|
|
return false;
|
|
});
|
|
|
|
table.on("toolbar(tableFilter)", function (obj) {
|
|
switch (obj.event) {
|
|
case "batchEnabled":
|
|
batchEnabled();
|
|
break;
|
|
case "batchDisabled":
|
|
batchDisabled();
|
|
break;
|
|
case "batchDelete":
|
|
batchDelete();
|
|
break;
|
|
case "add":
|
|
add();
|
|
break;
|
|
}
|
|
});
|
|
|
|
table.on("tool(tableFilter)", function (obj) {
|
|
let data = obj.data;
|
|
switch (obj.event) {
|
|
case "updateById":
|
|
updateById(data.id);
|
|
break;
|
|
case "deleteById":
|
|
deleteById(data.id);
|
|
break;
|
|
}
|
|
});
|
|
|
|
function batchEnabled() {
|
|
okLayer.confirm("确定要批量上架吗?", function (index) {
|
|
layer.close(index);
|
|
let idsStr = okUtils.tableBatchCheck(table);
|
|
if (idsStr) {
|
|
okUtils.ajax("/product/update-product-status", "put", {idsStr: idsStr}, true).done(function (response) {
|
|
okUtils.tableSuccessMsg(response.msg);
|
|
}).fail(function (error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function batchDisabled() {
|
|
okLayer.confirm("确定要批量下架吗?", function (index) {
|
|
layer.close(index);
|
|
let idsStr = okUtils.tableBatchCheck(table);
|
|
if (idsStr) {
|
|
okUtils.ajax("/product/update-product-status", "put", {idsStr: idsStr}, true).done(function (response) {
|
|
okUtils.tableSuccessMsg(response.msg);
|
|
}).fail(function (error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function batchDelete() {
|
|
okLayer.confirm("确定要批量删除吗?", function (index) {
|
|
layer.close(index);
|
|
let idsStr = okUtils.tableBatchCheck(table);
|
|
if (idsStr) {
|
|
okUtils.ajax("/product/deleteProduct", "delete", {idsStr: idsStr}, true).done(function (response) {
|
|
okUtils.tableSuccessMsg(response.msg);
|
|
}).fail(function (error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function add() {
|
|
okLayer.open("添加产品", "product-add.html", "90%", "90%", null, function () {
|
|
articleTable.reload();
|
|
})
|
|
}
|
|
|
|
function updateById(id) {
|
|
okLayer.open("编辑产品", "product-edit.html?id=" + id, "90%", "90%", null, function () {
|
|
articleTable.reload();
|
|
})
|
|
}
|
|
|
|
function deleteById(id) {
|
|
okLayer.confirm("确定要删除吗?", function () {
|
|
okUtils.ajax("/product/deleteProduct", "delete", {idsStr: id}).done(function (response) {
|
|
okUtils.tableSuccessMsg(response.msg);
|
|
}).fail(function (error) {
|
|
console.log(error);
|
|
});
|
|
})
|
|
}
|
|
})
|
|
</script>
|
|
<!-- 头工具栏模板 -->
|
|
<script type="text/html" id="toolbarTpl">
|
|
<div class="layui-btn-container">
|
|
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batchEnabled">批量上架</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="batchDisabled">批量下架</button>
|
|
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDelete">批量删除</button>
|
|
<button class="layui-btn layui-btn-sm" lay-event="add">添加产品</button>
|
|
</div>
|
|
</script>
|
|
<!-- 行工具栏模板 -->
|
|
<script type="text/html" id="operationTpl">
|
|
<a href="javascript:" title="编辑" lay-event="updateById"><i class="layui-icon"></i></a>
|
|
<a href="javascript:" title="删除" lay-event="deleteById"><i class="layui-icon"></i></a>
|
|
</script>
|
|
|
|
<script type="text/html" id="logoTpl">
|
|
<image src="{{d.logo}}"/>
|
|
</script>
|
|
|
|
<script type="text/html" id="urlTpl">
|
|
<a href="{{d.url}}" target="_blank">{{d.url}}</a>
|
|
</script>
|
|
</body>
|
|
</html>
|