IntelligentRecognition/ah-jjsp-web/.svn/pristine/d2/d2433c33510bb8600030c5eef10...

379 lines
10 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let table;
let deviceTable;
let form;
let per;
let laypage;
let strIds;
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为10
layui.use(['layer', 'form', 'element','laypage'], function(){
var layer = layui.layer; //弹层
laypage = layui.laypage; //分页
table = layui.table; //表格
form=layui.form;
//注册权限
// per=getPer();
$('#myModal_edit').on('show.bs.modal', centerModals);
//初始化下拉选
pages(1, 10, 1);
$(".layui-add").click(function(){
layer.open({
title: '新增',
type: 2,
area: ['40%','70%'],
content: '../../html/projectInformation/child/preservationAdd.html',
cancel: function(){
// layer.msg('捕获就是从页面已经存在的元素上包裹layer的结构', {time: 5000, icon:6});
},
btn: ['确定', '取消'] //只是为了演示
,yes: function(index,leyuo){
var body = layer.getChildFrame('body', index);
body.find('#add-preservation').click();
}
,btn2: function(){
layer.closeAll();
}
});
})
$(".layui-export").click(function(){
exportData();
})
$(".layui-delete").click(function(){
setDelete();
})
$(".layui-deleteAll").click(function(){
setAllDelete();
})
$("#downloadExcel").click(function(){
window.open(dataUrl + 'proteam/pot/preservation/downloadExcel' + '?token=' + token);
})
$(".layui-import").click(function(){
$("#import-excel").trigger('click');
})
$("#import-excel").change(function () {
if($(this).val()){
let files = $(this)[0].files[0];
let fileType = files.name.substring(
files.name.lastIndexOf(".") + 1,
files.name.length
);
if (fileType === "xlsx" || fileType === "xls") {
excelUpload(this, dataUrl + "proteam/pot/preservation/importExcel" + '?token=' + token, "");
} else {
layer.msg("仅支持上传文件格式为xlx、xlsx", {icon: 5,});
$("#import-excel").val("");
}
}
});
$("#query").off().click(function(){
// if(/^[a-zA-Z0-9\u4e80-\u9fa5\\s-]+$/.test($("#deviceName").val()) || ""==$("#deviceName").val()){
// }else {
// layer.msg("不能包合特殊字符", {icon: 5,});
// return;
// }
pages(1, limitSize,false);
return ;
})
//重置
$("#reset").off().click(function(){
pages(1, limitSize,true);
})
// 头工具栏事件
table.on('tool(preservation-table)', function(obj){
console.log(obj);
var event=obj.event;
var key=obj.data.id;//唯一值
if(event=='update'){//修改数据
layer.open({
title: '修改',
type: 2,
area: ['40%','70%'],
content: '../../html/projectInformation/child/preservationAdd.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,pageNum,limitSize);//调用子页面的方法,页面锁定
}
,yes: function(index,leyuo){
var body = layer.getChildFrame('body', index);
body.find('#add-preservation').click();
}
,btn2: function(){
layer.closeAll();
}
});
}else if(event=='del'){//删除数据
layer.msg('确定要删除吗?', {
time: 10000, //10s后自动关闭
btn: ['确定', '取消']
,yes: function(index,leyuo){
layer.closeAll();
delData(key)
}
});
}
})
//查询按钮
})
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify(params))
},
url: dataUrl+'proteam/pot/preservation/getProjectPreservation?token='+token,
data: params,
type: 'POST',
async: false,
success: function (result) {
if (result.code === 200) {
if (result.data) {
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})
} else if (result.code === 401) {
logout(1);
}
}, error: function () {
}
});
}
function laypages(total, page, limit) {
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
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 getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
unit:$("#unit").val(),
pro_name:$("#pro_name").val(),
gcgm:$("#gcgm").val(),
gcwz:$("#gcwz").val(),
sgdw:$("#sgdw").val(),
keyWord:$("#keyWord").val(),
};
} else {
obj = {
page: '1',
limit: '10',
unit:"",
pro_name:"",
gcgm:"",
gcwz:"",
sgdw:"",
keyWord:"",
};
}
return obj;
}
//初始化表格
function initTable(dataList, limit, page) {
// 执行一个 table 实例
preservationTable=table.render({
id:'preservationTable',
elem: '#preservation-table',
height: "full-250",
data: dataList,
limit: limit,
title: '设备表',
cols: [[ //表头
{type: 'checkbox', fixed: 'left'},
{title: "序号", width: 80, align: "center", templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
}
,{field: 'unit', title: '单位', width:200,align:'center'}
,{field: 'aq_code', title: '安全编码', width: 200,align:'center'}
,{field: 'pro_name', title: '在施工程名称', width:210,align:'center' }
,{field: 'zsgcfw', title: '在施工程范围', width: 150,align:'center'}
,{field: 'gcgm', title: '工程规模', width:250,align:'center'}
,{field: 'aqzj', title: '安全总监及手机号', width: 200,align:'center'}
,{field: 'org', title: '建设单位', width: 200,align:'center'}
,{field: 'jldw', title: '监理单位', width: 200,align:'center'}
,{field: 'sgdw', title: '施工单位', width: 200,align:'center'}
,{field: 'gcwz', title: '工程位置', width: 200,align:'center'}
,{field: 'jhkgsj', title: '实际开工时间', width: 200,align:'center'}
,{field: 'jhjgsj', title: '计划竣工时间', width: 200,align:'center'}
,{field: 'gcjd', title: '当前工程进度', width: 200,align:'center'}
,{field: 'gczt', title: '工程状态', width: 200,align:'center'}
,{field: 'risklevel', title: '当前风险等级', width: 200,align:'center'}
,{field: 'risk_ly', title: '风险判断理由', width: 200,align:'center'}
,{field: 'update_time', title: '梳理时间', width: 100,align:'center'}
,{field: 'next_time', title: '下次梳理时间', width: 100,align:'center'}
,{field: 'next_import', title: '下次梳理重点', width: 400,align:'center'}
,{field: 'remarks', title: '备注', width: 400,align:'center'}
,{fixed: 'right', title: '操作', width: 200,align:'center', toolbar: '#preservation-bar'}
]],
done:function (res,curr,count){
}
});
}
function setAllDelete() {
Ajax().post({
url: dataUrl + 'proteam/pot/preservation/deleteAllPreservation',
async : true,
success : function(data) {
pages(1, limitSize,false);
if(data.code=='200') {
layer.msg(data.msg, {
icon: 1,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}else{
layer.msg(data.msg, {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
}
});
}
function setDelete(){
var checkStatus = layui.table.checkStatus("preservationTable");
var strIds = '';
data = checkStatus.data;
for(var i = 0;i<data.length;i++){
strIds += checkStatus.data[i].id + ';';
}
strIds = strIds.substring(0,strIds.length-1);
Ajax().post({
url: dataUrl + 'proteam/pot/preservation/batchDeletePreservation',
headers: {
"encrypt": sm3(JSON.stringify({'keyId':strIds[0]}))
},
data: {
keyId:strIds
},
async : true,
success : function(data) {
pages(1, limitSize,false);
if(data.code=='200') {
layer.msg(data.msg, {
icon: 1,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}else{
layer.msg(data.msg, {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
}
});
}
//删除数据
function delData(keyId){
Ajax().post({
url: dataUrl + 'proteam/pot/preservation/deletePreservation',
headers: {
"encrypt": sm3(JSON.stringify({'keyId':keyId}))
},
data: {
keyId:keyId
},
async : true,
success : function(data) {
pages(1, limitSize,false);
if(data.code=='200') {
layer.msg(data.msg, {
icon: 1,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}else{
layer.msg(data.msg, {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
}
});
}
function query(){
pages(1, limitSize,false);
}
function reloadTable(){
query();
}
//导出
function exportData() {
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
let url = dataUrl + "proteam/pot/preservation/exportPreservation?&token="+token;
let xhr = new XMLHttpRequest();
let a = document.createElement("a");
xhr.open("get", url, true);
xhr.responseType = "blob"; // 转换流
xhr.onload = function () {
layer.close(loadingMsg);
if (this.status === 200) {
let url = window.URL.createObjectURL(new Blob([this.response]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', "工程维护.xlsx")
document.body.appendChild(link)
link.click()
// 释放URL对象所占资源
window.URL.revokeObjectURL(url)
// 用完即删
document.body.removeChild(link)
} else {
layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
}
};
xhr.send();
}
// 弹出模态框
function centerModals() {
$('#myModal_edit').each(function (i) {
var $clone = $(this).clone().css('display', 'block').appendTo('body');
var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 3);
top = top > 0 ? top : 0;
$clone.remove();
$(this).find('.modal-content').css("margin-top", top);
});
};