374 lines
18 KiB
HTML
374 lines
18 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>layui</title>
|
||
<meta name="renderer" content="webkit">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||
<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
|
||
<link rel="stylesheet" href="../../../css/public.css" media="all">
|
||
</head>
|
||
|
||
<body>
|
||
<div class="layuimini-container">
|
||
<div class="layuimini-main">
|
||
|
||
<fieldset class="table-search-fieldset">
|
||
<legend>搜索信息</legend>
|
||
<div style="margin: 10px 10px 10px 10px">
|
||
<form class="layui-form layui-form-pane" action="">
|
||
<div class="layui-form-item">
|
||
<div class="layui-inline">
|
||
<label class="layui-form-label">产品编码</label>
|
||
<div class="layui-input-inline">
|
||
<input type="text" name="ProductNum" autocomplete="off" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline">
|
||
<label class="layui-form-label">备注</label>
|
||
<div class="layui-input-inline">
|
||
<input type="text" name="Remark" autocomplete="off" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline">
|
||
<button type="submit" class="layui-btn layui-btn-primary" lay-submit
|
||
lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</fieldset>
|
||
|
||
<script type="text/html" id="toolbar">
|
||
<div class="layui-btn-container">
|
||
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
|
||
<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
|
||
<button type="button" id="LAY-excel-upload" class="layui-btn layui-btn-sm"><i class="layui-icon"></i>导入</button>
|
||
</div>
|
||
</script>
|
||
|
||
<script type="text/html" id="toolbar_3">
|
||
<div class="layui-btn-container">
|
||
</div>
|
||
</script>
|
||
|
||
<table class="layui-hide" id="ProductNumberList" lay-filter="currentTableFilter"></table>
|
||
|
||
<script type="text/html" id="currentTableBar">
|
||
<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
|
||
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
|
||
</script>
|
||
|
||
<script type="text/html" id="currentTableBar_3">
|
||
</script>
|
||
|
||
</div>
|
||
</div>
|
||
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||
<script src="../../../js/lay-config.js" charset="utf-8"></script>
|
||
<script src="../../../js/PublicParameters/PublicParameters.js" charset="utf-8"></script>
|
||
<script>
|
||
layui.use(['form', 'table', 'excel', 'upload'], function () {
|
||
var $ = layui.jquery,
|
||
form = layui.form,
|
||
table = layui.table,
|
||
excel = layui.excel,
|
||
upload = layui.upload;
|
||
|
||
var apiUrl = GetWebApiUrl();
|
||
var CurrUserData = layui.sessionData('CurrUserInfo');
|
||
var powerlevel = CurrUserData.data.powerLevel;
|
||
var ToolBarID = "#toolbar";
|
||
var TableBarID = "#currentTableBar";
|
||
if (powerlevel == 3) {
|
||
ToolBarID = "#toolbar_3";
|
||
TableBarID = "#currentTableBar_3";
|
||
}
|
||
|
||
table.render({
|
||
elem: '#ProductNumberList',
|
||
height: 600,
|
||
url: apiUrl + '/api/services/app/ProductNumber/GetAllProductNumber',
|
||
parseData: function (res) { //res 即为原始返回的数据
|
||
return {
|
||
"code": res.result.code, //解析接口状态
|
||
"msg": res.result.msg, //解析提示文本
|
||
"count": res.result.count, //解析数据长度
|
||
"data": res.result.data //解析数据列表
|
||
};
|
||
},
|
||
toolbar: ToolBarID,
|
||
defaultToolbar: ['filter', 'exports'],
|
||
cols: [[
|
||
{ type: "checkbox", width: 50 },
|
||
{ type: "numbers", title: '序号', width: 50 },
|
||
{ field: 'id', hide: true, width: 300, title: 'ID' },
|
||
{ field: 'productNum', width: 200, title: '产品编码', sort: true, align: "center" },
|
||
{ field: 'remark', width: 350, title: '备注', sort: true, align: "left" },
|
||
{ title: '操作', width: 200, toolbar: TableBarID, align: "center" }
|
||
]],
|
||
initSort: {
|
||
field: 'productNum', //排序字段,对应 cols 设定的各字段名
|
||
type: 'asc' //排序方式 asc: 升序、desc: 降序、null: 默认排序
|
||
},
|
||
page: false,
|
||
limit: 15,
|
||
limits: [10, 15, 20, 25, 50, 100],
|
||
skin: 'line'
|
||
});
|
||
|
||
upload.render({
|
||
elem: '#LAY-excel-upload', //绑定元素
|
||
url: '/upload/', //上传接口(PS:这里不用传递整个 excel)
|
||
auto: false, //选择文件后不自动上传
|
||
accept: 'file',
|
||
choose: function (obj) {// 选择文件回调
|
||
var files = obj.pushFile()
|
||
var fileArr = Object.values(files)// 注意这里的数据需要是数组,所以需要转换一下
|
||
|
||
// 用完就清理掉,避免多次选中相同文件时出现问题
|
||
for (var index in files) {
|
||
if (files.hasOwnProperty(index)) {
|
||
delete files[index]
|
||
}
|
||
}
|
||
$('#LAY-excel-upload').next().val('');
|
||
uploadExcel(fileArr) // 如果只需要最新选择的文件,可以这样写: uploadExcel([files.pop()])
|
||
}
|
||
});
|
||
|
||
// 监听搜索操作
|
||
form.on('submit(data-search-btn)', function (data) {
|
||
var result = JSON.stringify(data.field);
|
||
//执行搜索重载
|
||
table.reload('ProductNumberList', {
|
||
page: {
|
||
curr: 1
|
||
}
|
||
, where: {
|
||
ProductNum: data.field.ProductNum,
|
||
Remark: data.field.Remark,
|
||
}
|
||
}, 'data');
|
||
|
||
return false;
|
||
});
|
||
|
||
/**
|
||
* toolbar监听事件
|
||
*/
|
||
table.on('toolbar(currentTableFilter)', function (obj) {
|
||
if (obj.event === 'add') { // 监听添加操作
|
||
var index = layer.open({
|
||
title: '添加产品编码',
|
||
type: 2,
|
||
shade: 0.2,
|
||
maxmin: true,
|
||
shadeClose: true,
|
||
area: ['50%', '30%'],
|
||
content: 'addProductNumber.html',
|
||
});
|
||
$(window).on("resize", function () {
|
||
layer.full(index);
|
||
});
|
||
} else if (obj.event === 'delete') { // 监听删除操作
|
||
var checkStatus = table.checkStatus('ProductNumberList'),
|
||
data = checkStatus.data;
|
||
if (data.length == 0) {
|
||
layer.alert('请选择至少一个产品编码!');
|
||
return false;
|
||
}
|
||
delProductNumber(data);
|
||
return false;
|
||
}
|
||
});
|
||
|
||
//监听表格复选框选择
|
||
table.on('checkbox(currentTableFilter)', function (obj) {
|
||
console.log(obj)
|
||
});
|
||
|
||
table.on('tool(currentTableFilter)', function (obj) {
|
||
var data = obj.data;
|
||
if (obj.event === 'edit') {
|
||
layui.sessionData('editProductNumber', {
|
||
key: 'SelProductNumberID',
|
||
value: data.id,
|
||
});
|
||
var index = layer.open({
|
||
title: '编辑产品编码',
|
||
type: 2,
|
||
shade: 0.2,
|
||
maxmin: true,
|
||
shadeClose: true,
|
||
area: ['50%', '30%'],
|
||
content: 'editProductNumber.html',
|
||
});
|
||
$(window).on("resize", function () {
|
||
layer.full(index);
|
||
});
|
||
return false;
|
||
} else if (obj.event === 'delete') {
|
||
delSingleProductNumber(data);
|
||
return false;
|
||
}
|
||
});
|
||
|
||
|
||
//批量删除用户
|
||
function delProductNumber(data) {
|
||
//弹出确认弹窗
|
||
layer.confirm('确认删除吗?', function () {
|
||
var apiUrl = GetWebApiUrl();
|
||
var CurrUserInfo = layui.sessionData('CurrUserInfo');
|
||
//删除所选的产品编码信息,更新isdelete字段为1
|
||
for (let index = 0; index < data.length; index++) {
|
||
$.ajax({
|
||
url: apiUrl + "/api/services/app/ProductNumber/UpdateProductNumber", //请求的url地址
|
||
dataType: "json", //返回格式为json
|
||
//async: false,//请求是否异步,默认为异步,这也是ajax重要特性
|
||
contentType: 'application/json',
|
||
data: JSON.stringify({
|
||
id: data[index].id,
|
||
updateUserID: CurrUserInfo.data.userid,
|
||
updateUserName: CurrUserInfo.data.userName,
|
||
isDelete: 1,
|
||
}), //参数值
|
||
type: "PUT", //请求方式
|
||
success: function (req) {
|
||
if (req.result.code == 1) {
|
||
//请求成功时处理
|
||
layer.msg('删除成功', { time: 1000 }, function () {
|
||
window.location.reload();
|
||
});
|
||
}
|
||
else {
|
||
/*错误信息处理*/
|
||
layer.alert("产品编码:" + data[index].productNum + " 删除失败,请重试!");
|
||
return false;
|
||
}
|
||
},
|
||
error: function () {
|
||
/*错误信息处理*/
|
||
layer.alert("产品编码:" + data[index].productNum + " 删除失败,请重试!");
|
||
return false;
|
||
},
|
||
});
|
||
}
|
||
return false;
|
||
});
|
||
}
|
||
|
||
//删除单个用户
|
||
function delSingleProductNumber(data) {
|
||
//弹出确认弹窗
|
||
layer.confirm('确认删除吗?', function () {
|
||
//删除所选的产品编码信息,更新isdelete字段为1
|
||
var apiUrl = GetWebApiUrl();
|
||
var CurrUserInfo = layui.sessionData('CurrUserInfo');
|
||
$.ajax({
|
||
url: apiUrl + "/api/services/app/ProductNumber/UpdateProductNumber", //请求的url地址
|
||
dataType: "json", //返回格式为json
|
||
//async: false,//请求是否异步,默认为异步,这也是ajax重要特性
|
||
contentType: 'application/json',
|
||
data: JSON.stringify({
|
||
id: data.id,
|
||
updateUserID: CurrUserInfo.data.userid,
|
||
updateUserName: CurrUserInfo.data.userName,
|
||
isDelete: 1,
|
||
}), //参数值
|
||
type: "PUT", //请求方式
|
||
success: function (req) {
|
||
if (req.result.code == 1) {
|
||
//请求成功时处理
|
||
layer.msg('删除成功', { time: 1000 }, function () {
|
||
window.location.reload();
|
||
});
|
||
}
|
||
else {
|
||
/*错误信息处理*/
|
||
layer.alert("产品编码:" + data.productNum + " 删除失败,请重试!");
|
||
return false;
|
||
}
|
||
},
|
||
error: function () {
|
||
/*错误信息处理*/
|
||
layer.alert("产品编码:" + data.productNum + " 删除失败,请重试!");
|
||
return false;
|
||
},
|
||
});
|
||
return false;
|
||
});
|
||
}
|
||
|
||
function uploadExcel(files) {
|
||
try {
|
||
excel.importExcel(files, {
|
||
// 读取数据的同时梳理数据
|
||
fields: {
|
||
'productNum': 'A',
|
||
'remark': 'B',
|
||
}
|
||
}, function (data) {
|
||
var dataArr = data[0].Sheet1;
|
||
//获取前端页面整个表格数据
|
||
var tableData = layui.table.cache["ProductNumberList"];
|
||
if (tableData.length > 0) {
|
||
for (let index = 0; index < tableData.length; index++) {
|
||
var tableProductNum = tableData[index].productNum;
|
||
for (let dataindex = 1; dataindex < dataArr.length; dataindex++) {
|
||
var productNum = dataArr[dataindex].productNum;
|
||
if (productNum == tableProductNum) {
|
||
layer.alert("导入的产品编码:" + productNum + " 与已有的产品编码重复,请修改!");
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//校验无误,保存导入的数据
|
||
for (let index = 1; index < dataArr.length; index++) {
|
||
var CurrUserInfo = layui.sessionData('CurrUserInfo');
|
||
var productNum = dataArr[index].productNum.toString();
|
||
if (productNum.length == 1) {
|
||
productNum = '0' + productNum;
|
||
}
|
||
$.ajax({
|
||
url: apiUrl + "/api/services/app/ProductNumber/CreateProductNumber", //请求的url地址
|
||
dataType: "json", //返回格式为json
|
||
//async: false,//请求是否异步,默认为异步,这也是ajax重要特性
|
||
contentType: 'application/json',
|
||
data: JSON.stringify({
|
||
productNum: productNum,
|
||
remark: dataArr[index].remark,
|
||
createTime: getDatetime(),
|
||
createUserID: CurrUserInfo.data.userid,
|
||
createUserName: CurrUserInfo.data.userName,
|
||
isDelete: 0
|
||
}), //参数值
|
||
type: "POST", //请求方式
|
||
success: function (req) {
|
||
//请求成功时处理
|
||
|
||
},
|
||
error: function () {
|
||
/*错误信息处理*/
|
||
layer.msg("保存失败,请重试!");
|
||
return false;
|
||
},
|
||
});
|
||
}
|
||
layer.msg('导入成功', { time: 1000 }, function () {
|
||
table.reload('ProductNumberList');
|
||
});
|
||
})
|
||
} catch (e) {
|
||
layer.alert(e.message)
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
</body>
|
||
|
||
</html> |