305 lines
10 KiB
JavaScript
305 lines
10 KiB
JavaScript
let form, layer, table, laydate, tableIns, user = getUser(), tableHeight;
|
||
let pageNum = 1, limitSize = 10; // 默认第一页,分页数量为10
|
||
layui.use(['form', 'layer', 'table', 'laydate'], function () {
|
||
form = layui.form;
|
||
layer = layui.layer;
|
||
table = layui.table;
|
||
laydate = layui.laydate;
|
||
pages(1, 10, 1);
|
||
|
||
// 头工具栏事件
|
||
table.on('tool(currTable)', function(obj){
|
||
console.log(obj);
|
||
var event=obj.event;
|
||
var key=obj.data.id;//唯一值
|
||
if(event=='detail'){//查看详情
|
||
layer.open({
|
||
title: '详情',
|
||
type: 2,
|
||
area: ['50%','90%'],
|
||
content: '../../html/supplement/child/riskWarningAndEarlyDisposalAdd.html',
|
||
btn: ['取消'] //只是为了演示
|
||
,success: function (layero, index) {
|
||
var body = layer.getChildFrame('body', index);
|
||
var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象,执行iframe页的方法:
|
||
iframeWin.setForm(key);//调用子页面的方法,页面锁定
|
||
}
|
||
,btn2: function(){
|
||
layer.closeAll();
|
||
}
|
||
});
|
||
|
||
}else if(event=='update'){//修改数据
|
||
layer.open({
|
||
title: '整改',
|
||
type: 2,
|
||
area: ['50%','90%'],
|
||
content: '../../html/supplement/child/riskWarningAndEarlyDisposalAdd.html',
|
||
btn: ['确定', '取消']
|
||
,success: function (layero, index) {
|
||
var body = layer.getChildFrame('body', index);
|
||
var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象,执行iframe页的方法:
|
||
iframeWin.setForms(key,pageNum,limitSize);//调用子页面的方法,页面锁定
|
||
}
|
||
,yes: function(index,leyuo){
|
||
var body = layer.getChildFrame('body', index);
|
||
body.find('#updateBtn').click();
|
||
}
|
||
,btn2: function(){
|
||
layer.closeAll();
|
||
}
|
||
});
|
||
|
||
}else if(event=='del'){//删除数据
|
||
layer.msg('确定注销该设备?', {
|
||
time: 10000, //10s后自动关闭
|
||
btn: ['确定', '取消']
|
||
,yes: function(index,leyuo){
|
||
layer.closeAll();
|
||
delData(key)
|
||
}
|
||
});
|
||
}
|
||
})
|
||
|
||
$(".layui-add").click(function(){
|
||
layer.open({
|
||
title: '新增',
|
||
type: 2,
|
||
area: ['50%','90%'],
|
||
content: '../../html/supplement/child/riskWarningAndEarlyDisposalAdd.html',
|
||
cancel: function(){
|
||
// layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', {time: 5000, icon:6});
|
||
}
|
||
});
|
||
})
|
||
|
||
})
|
||
|
||
/* 加载表格 */
|
||
function pages(pageNum, pageSize, typeNum) {
|
||
let params = getReqParams(pageNum, pageSize, typeNum);
|
||
let url = dataUrl + "proteam/pot/riskWarningAndEarlyDisposal/getList";
|
||
ajaxRequest(url, "POST", params, true, function () {
|
||
}, function (result) {
|
||
if (result.code === 200) {
|
||
initTable(result.data, result.limit, result.curr)
|
||
laypages(result.count, result.curr, result.limit)
|
||
} else if (result.code === 500) {
|
||
layer.alert(result.msg, { icon: 2 })
|
||
}
|
||
}, function (xhr, status, error) {
|
||
errorFn(xhr, status, error)
|
||
}, null);
|
||
}
|
||
|
||
function reloadTable(pageNum,limitSize){
|
||
pages(pageNum, limitSize,false);
|
||
}
|
||
|
||
function laypages(total, page, limit) {
|
||
layui.use(['laypage'], function () {
|
||
let laypage = layui.laypage;
|
||
laypage.render({
|
||
elem: 'voi-page',
|
||
count: total,
|
||
curr: page,
|
||
limit: limit,
|
||
limits: [10, 20, 50, 100, 200, 500],
|
||
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
|
||
groups: 5,
|
||
jump: function (obj, first) {
|
||
if (!first) {
|
||
pageNum = obj.curr, limitSize = obj.limit;
|
||
pages(obj.curr, obj.limit, null);
|
||
}
|
||
}
|
||
});
|
||
})
|
||
}
|
||
|
||
/*初始化表格*/
|
||
function initTable(dataList, limit, page) {
|
||
let loadingMsg = layer.msg("数据加载中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
|
||
tableIns = table.render({
|
||
id: 'currTable',
|
||
elem: "#currTable",
|
||
height: 'full-130',
|
||
data: dataList,
|
||
limit: limit,
|
||
cols: [
|
||
[
|
||
{
|
||
title: "序号",
|
||
width: '5%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return (page - 1) * limit + d.LAY_NUM;
|
||
}
|
||
},
|
||
{
|
||
field: "proName",
|
||
title: "工程名称",
|
||
width: '15%',
|
||
unresize: true,
|
||
align: "center",
|
||
style: 'word-break: break-all'
|
||
},
|
||
{
|
||
field: "ticketName",
|
||
title: "作业票名称",
|
||
width: '10%',
|
||
unresize: true,
|
||
align: "center",
|
||
style: 'word-break: break-all'
|
||
},
|
||
{
|
||
field: "riskGrade",
|
||
title: "风险等级",
|
||
width: '5%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return setRiskLevelColor(d.riskGrade);
|
||
}
|
||
},
|
||
{
|
||
field: "number",
|
||
title: "编号",
|
||
width: '10%',
|
||
unresize: true,
|
||
align: "center",
|
||
style: 'word-break: break-all'
|
||
},
|
||
{
|
||
field: "jobLeader",
|
||
title: "负责人",
|
||
width: '5%',
|
||
unresize: true,
|
||
align: "center",
|
||
tstyle: 'word-break: break-all'
|
||
},
|
||
{
|
||
field: "jobSite",
|
||
title: "作业部分",
|
||
width: '15%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
if (d.jobSite) {
|
||
if (d.jobSite.length > 60) {
|
||
return '<span title="' + d.jobSite + '">' + d.jobSite.substring(0, 60) + '...</span>'
|
||
} else {
|
||
return '<span title="' + d.jobSite + '">' + d.jobSite + '</span>'
|
||
}
|
||
} else {
|
||
return '';
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: "jobGx",
|
||
title: "工序",
|
||
width: '15%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
if (d.jobGx) {
|
||
if (d.jobGx.length > 60) {
|
||
return '<span title="' + d.jobGx + '">' + d.jobGx.substring(0, 60) + '...</span>'
|
||
} else {
|
||
return '<span title="' + d.jobGx + '">' + d.jobGx + '</span>'
|
||
}
|
||
} else {
|
||
return '';
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: "yjDate",
|
||
title: "时间",
|
||
width: '10%',
|
||
unresize: true,
|
||
align: "center",
|
||
style: 'word-break: break-all'
|
||
},
|
||
{
|
||
field: "status",
|
||
title: "状态",
|
||
width: '5%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
var status ;
|
||
if (d.status==='1'){
|
||
status='已发布';
|
||
} else {
|
||
status='未发布';
|
||
}
|
||
return '<span title="' + status + '">' + status + '</span>'
|
||
}
|
||
},
|
||
{fixed: 'right', title: '操作', width: '5%',align:'center', toolbar: '#device-bar'}
|
||
],
|
||
],
|
||
done: function (res, curr, count) {
|
||
layer.close(loadingMsg);
|
||
table.resize("currTable");
|
||
count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block");
|
||
count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto");
|
||
},
|
||
});
|
||
}
|
||
|
||
// 获取参数
|
||
function getReqParams(page, limit, type) {
|
||
let obj = {};
|
||
if (!type) {
|
||
obj = {
|
||
page: page + "",
|
||
limit: limit + "",
|
||
proName: $('#proName').val(),
|
||
riskLevel: $('#riskLevel').val(),
|
||
currentUserId: user.userId + '',
|
||
isSup: user.isSup,
|
||
currentUserOrgId: user.orgId
|
||
};
|
||
} else {
|
||
obj = {
|
||
page: '1',
|
||
limit: '10',
|
||
proName: '',
|
||
riskLevel:'',
|
||
currentUserId: user.userId + '',
|
||
isSup: user.isSup,
|
||
currentUserOrgId: user.orgId
|
||
};
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
// 查询/重置
|
||
function queryTable(type) {
|
||
if (type === 2) {
|
||
$('#proName').val('');
|
||
$('#riskLevel').val('');
|
||
layui.form.render();
|
||
}
|
||
let pattern = new RegExp("[%_<>]");
|
||
if (pattern.test($("#proName").val())) {
|
||
$("#proName").val('');
|
||
return layer.msg('工程名称查询包含特殊字符,请重新输入', {
|
||
icon: 2,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
});
|
||
}
|
||
pageNum = 1;
|
||
pages(1, limitSize)
|
||
}
|
||
|
||
// 整改详情
|
||
function rectDetail(obj) {
|
||
openIframeByParamObj("rectDetail", "整改详情", "../supplement/child/risk_rect_detail.html", "62%", "85%", obj);
|
||
}
|