已废弃
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

340 lines
14 KiB

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<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="/static/lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
<div class="layuimini-main">
<input style="display: none" id="gid" th:value="${gid}">
<script id="toolbarDemo" type="text/html">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加</button>
</div>
</script>
<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" placeholder="请选择物料类型" class="layui-input" id="openSonByMateralType"
readonly/>
<input type="text" id="materialTypeId" placeholder="请选择物料类型" name="materialTypeId"
class="layui-input" style="display: none"/>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">物料名称</label>
<div class="layui-input-inline">
<input type="text" name="mname" 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="code" 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>
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
</div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
layui.use(['form', 'layer', 'dropdown', 'tree', 'laydate'], function () {
var $ = layui.jquery,
form = layui.form,
table = layui.table;
// 用于暂存选择的数据
let checkList = [];
let gid = $("#gid").val();
$('#openSonByMateralType').on('click', function () {
layer.open({
type: 2,
title: '弹窗内容',
skin: 'layui-layer-rim',
maxmin: true,
shadeClose: true, //点击遮罩关闭层
area: ['70%', '70%'],
move: '.layui-layer-title',
fixed: false,
content: '/selectType',
success: function (layero, index) {
var children = layero.children();
var content = $(children[1]);
var iframeChildren = $(content.children());
content.css('height', '100%');
iframeChildren.css('height', '100%');
}
});
});
table.render({
elem: "#currentTableId",
url: '/material/material',
parseData: function (res) { //res 即为原始返回的数据
return {
"status": res.status, //解析接口状态
"message": res.statusInfo.message, //解析提示文本
"count": res.count, //解析数据长度
"data": res.data //解析数据列表
};
},
request: {
pageName: 'page', //页码的参数名称,默认:page
limitName: 'size' //每页数据量的参数名,默认:limit
},
response: {
statusName: 'status' //规定数据状态的字段名称,默认:code
, statusCode: 200 //规定成功的状态码,默认:0
, msgName: 'message' //规定状态信息的字段名称,默认:msg
, countName: 'count' //规定数据总数的字段名称,默认:count
, dataName: 'data' //规定数据列表的字段名称,默认:data
},
toolbar: '#toolbarDemo',
cols: [
[
{type: "checkbox", width: 50},
{field: 'quantity', width: 200, title: '数量', edit: 'quantity'},
{field: 'mname', width: 200, title: '物料名称'},
{field: 'version', width: 250, title: '规格型号'},
{field: 'code', width: 200, title: '存货编码'},
{field: 'typeName', width: 200, title: '物料类型'},
{field: 'unit', width: 200, title: '计量单位'},
{field: 'texture', width: 200, title: '材质',},
]
],
limits: [10, 15, 20, 25, 50, 100],
limit: 10,
page: true,
skin: 'line',
done: function (res, curr, count) {
if (checkList.length > 0) {
let count = 0;
$.each(res['data'], function (i, j) {
let id = j["id"];
for (let k = 0; k < checkList.length; k++) {
if(checkList[k].id === id){
let index = j["LAY_TABLE_INDEX"];
$('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked','true');
form.render('checkbox'); //刷新checkbox选择框渲染
count++;
}
}
});
if(count === res.data.length){
// 如果是全选
$('tr input[type="checkbox"]').prop('checked','true');
form.render('checkbox');
}
}
}
});
table.on('toolbar(currentTableFilter)', function (obj) {
if (obj.event === 'add') { // 监听添加操作申请操作
var checkStatus = table.checkStatus('currentTableId')
, data = checkStatus.data;
var req = {};
req.mids = [];
req.quantitys = [];
let len = data.length;
for (let i = 0; i < len; i++) {
req.mids[i] = data[i].id;
req.quantitys[i] = data[i].quantity;
}
req.len = len;
if (req.mids.length > 0) {
// 如果有,则进行下一步
if(gid === "-1") {
$.ajax({
url: '/group/addGroup',
type: 'post',
dataType: "json",
data: JSON.stringify(req),
contentType: "application/json;charset=utf-8",
success: function (res) {
if (res.status >= 300) {
layer.msg(res.statusInfo.message);//失败的表情
return;
} else {
layer.msg("添加成功!", {
icon: 6,//成功的表情
time: 1000
}, //1秒关闭(如果不配置,默认是3秒)
function () {
//do something
table.reload('currentTableId', {
url: '/material/material',
page: {
curr: 1
}
}, 'data')
});
}
}
})
}else{
req.gid = gid;
$.ajax({
url: '/group/addMaterialForGroup',
type: 'post',
dataType: "json",
data: JSON.stringify(req),
contentType: "application/json;charset=utf-8",
success: function (res) {
if (res.status >= 300) {
layer.msg(res.statusInfo.message);//失败的表情
return;
} else {
layer.msg("添加成功!", {
icon: 6,//成功的表情
time: 1000
}, //1秒关闭(如果不配置,默认是3秒)
function () {
//do something
table.reload('currentTableId', {
url: '/material/material',
page: {
curr: 1
}
}, 'data')
});
}
}
})
}
}else{
layer.msg("请选择物料",{
icon:0,
time:500
})
}
}
});
// 监听搜索操作
form.on('submit(data-search-btn)', function (data) {
var req = {};
data = data.field;
req.type = 1;
if (data.mname !== '') {
req.mname = data.mname;
}
if (data.materialTypeId !== '') {
req.materialTypeId = data.materialTypeId;
}
if (data.code !== '') {
req.code = data.code
}
//执行搜索重载
table.reload('currentTableId', {
url: '/material/material',
page: {
curr: 1
},
where: req
}, 'data');
return false;
});
//监听表格复选框选择
table.on('checkbox(currentTableFilter)', function (obj) {
if(obj.type === "one") {
// 如果选择的是一个
if (obj.checked) {
let flag = true;
for (let i = 0; i < checkList.length; i++) {
let data = checkList[i];
if (data.id === obj.data.id) {
flag = false;
break
}
}
if (flag) {
checkList.push(obj.data);
}
} else {
for (let i = 0; i < checkList.length; i++) {
let data = checkList[i];
if (data.id === obj.data.id) {
checkList.splice(i, i + 1);
break
}
}
}
}
else{
// 如果是全选
// 获取选中的数据
let dataList = table.checkStatus('currentTableId').data;
if (obj.checked) {
for (let i = 0; i < dataList.length; i++) {
let dataItem = dataList[i];
let flag = true;
for (let j = 0; j < checkList.length; j++) {
let data = checkList[j];
if (data.id === dataItem.id) {
flag = false;
break
}
}
if (flag) {
checkList.push(dataItem);
}
}
}else{
dataList = table.getData('currentTableId');
for (let i = 0; i < dataList.length; i++) {
let dataItem = dataList[i];
for (let j = 0; j < checkList.length; j++) {
let data = checkList[j];
if (data.id === dataItem.id) {
checkList.splice(j, j + 1);
break
}
}
}
}
}
});
})
</script>
</body>
</html>