IntelligentRecognition/ah-jjsp-web/.svn/pristine/43/43ab026ea0cbf317a322a0fffc9...

486 lines
17 KiB
Plaintext
Raw Normal View History

2024-05-24 16:09:40 +08:00
let table, form, laypage,laydate, tableIns, rightPopup, util, formSelects, user = getUser();
let pageNum = 1, limitSize = 10;
$(function () {
layui.config({
base: "../../js/layui/", //此处路径请自行处理, 可以使用绝对路径
}).extend({
rightPopup: "rightPopup",
rightPopup2: "rightPopup2",
formSelects: 'formSelects-v4'
}).use(["form", "laypage", "formSelects", "table", "rightPopup", "rightPopup2", 'util','laydate'], function () {
form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
table = layui.table;
laypage = layui.laypage;
rightPopup = layui.rightPopup2;
util = layui.util;
laydate = layui.laydate;
formSelects = layui.formSelects;
laydate.render({
elem: '#sgTime', //指定元素 元素选择器
type: 'date', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
trigger: 'click',
range: true,
format: 'yyyy-MM-dd', //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
btns: ['now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定
});
$('#sgTime').val(getNowTime() + " - " + getNowTime())
util.event('lay-active', {
query: function () {
pages(1, limitSize,false);
},
reset: function () {
$("#proStatus").val('00');
$('#proType').val('00');
form.render();
pages(1, limitSize,true);
},
export: function () {
exportData();
},
openMore: function () {
openMoreOption();
}
});
getOrgSelect();
pages(1, 10, true);
getProject();
layui.form.render();
$('#myModal_edit').on('show.bs.modal', centerModals);
table.on("rowDouble(proTable)", function (res) {
viewData(res.data.bidCode);
});
}
);
});
/**
* 获得当前时间 yyyy-MM-dd
* @returns {string}
*/
function getNowTime() {
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
var day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
return year + "-" + month + "-" + day;
}
function pages(pageNum, pageSize,tType) {
let params = getReqParams(pageNum, pageSize,tType);
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify(params))
},
url: dataUrl + 'proteam/pot/weekRisk/getWeekRiskList?token=' + token,
data: params,
type: 'POST',
async: false,
success: function (result) {
if (result.code === 200) {
console.log(result);
if (result.data) {
initTable(result.data, result.limit, result.curr)
laypages(result.count, result.curr, result.limit)
resetContent();
}
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
} else if (result.code === 401) {
logout();
}
}, error: function () {
}
});
}
function laypages(total, page, limit) {
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limits: [10, 20, 50, 100, 200, 500],
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 initTable(dataList, limit, page) {
tableIns = table.render({
elem: "#weekRsikTable",
id: "weekRsikTable",
height: "full-175",
data: dataList,
limit: limit,
cols: [
[
//表头
{
title: "序号",
width: 80,
unresize: true,
align: "center",
templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
{field: "buildUnit", title: "建管单位", width: 150, unresize: true, align: "center", sort: true},
{field: "projectName", title: "工程名称", width: 200, unresize: true, align: "center", sort: true,},
{field: "riskLevel", title: "风险等级", width: 120, unresize: true, align: "center", sort: true,templet: function (d) {
return setRiskLevelColor(d.riskLevel);
}},
{field: "workContent", title: "工作内容", width: 400, unresize: true, align: "center", sort: true,
templet: function (d) {
if (d.workContent) {
if (d.workContent.length > 80) {
return '<span title="' + d.workContent + '">' + d.workContent.substring(0, 60) + '...</span>'
} else {
return '<span title="' + d.workContent + '">' + d.workContent + '</span>'
}
} else {
return '';
}
}
},
{field: "startDate", title: "开始时间", width: 120, unresize: true, align: "center", sort: true},
{field: "endDate", title: "结束时间", width: 120, unresize: true, align: "center", sort: true},
{field: "workName", title: "工作名称", width: 250, unresize: true, align: "center", sort: true,},
{field: "workGx", title: "作业工序", width: 200, unresize: true, align: "center", sort: true,},
{field: "workType", title: "作业类型", width: 200, unresize: true, align: "center", sort: true,},
{field: "teamName", title: "班组名称", width: 200, unresize: true, align: "center", sort: true,},
],
],
done: function (res, curr, count) {
$(".layui-laypage-skip").css("display", "none");
$(".layui-table-main tr").each(function (index, val) {
$($(".layui-table-fixed-r tr")[index + 1]).css("height", $(val).height());
});
}
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
buildUnit: formSelects.value('buildUnit', 'val').toString(),
bidCode: formSelects.value('bidName', 'val').toString(),
sgTime:$("#sgTime").val(),
keyWord:$("#keyWord").val(),
};
} else {
obj = {
page: '1',
limit: '10',
buildUnit: formSelects.value('buildUnit', []),
bidCode: formSelects.value('bidName', []),
sgTime:$("#sgTime").val(),
keyWord:"",
};
}
return obj;
}
//导出
function exportData() {
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
let url = dataUrl + "proteam/pot/weekRisk/exportProData?" + setData(getReqParams(pageNum, limitSize)) + '&token=' + token;
let xhr = new XMLHttpRequest();
let a = document.createElement("a");
xhr.open("get", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader("encrypt",
sm3(JSON.stringify(
getReqParams(pageNum, limitSize)
)));
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 getOrgSelect() {
let keys = [];
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify({}))
},
url: dataUrl + 'proteam/pot/team/getOrgSelected' + '?token=' + token,
type: 'post',
success: function (data) {
console.log(data);
$.each(data.data, function (index, item) {
let temp = {
"name": item.name,
"value": item.code
};
keys.push(temp);
})
formSelects.data('buildUnit', 'local', {
arr: keys
});
form.render();
}
});
}
// 关闭页面
function closePage(type) {
if (type === 1) {
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
} else if (type === 2) {
layer.closeAll();
}
}
// 展开/收起
function isShow(type) {
if (type === 1) {
$("#basic-info").slideLeftHide();
setTimeout(() => {
$("#show").removeAttr("style");
}, 510);
$(".basic-info-box").animate({backgroundColor: "#fff"}, "500");
} else if (type === 2) {
$("#show").css("display", "none");
$(".basic-info-box").animate({backgroundColor: "#EEF5FF"}, "500");
$("#basic-info").slideLeftShow();
}
}
// 弹出模态框
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);
});
}
/*更多选项*/
function openMoreOption() {
let width = getMoreWidth().toFixed(0) + "px";
let height = getMoreHeight().toFixed(0) + "px";
let layerIndex = layer.open({
id: "moreOption",
title: ['<div style="border-left: 3px solid #2F82FB;display: flex;align-items: center;height: 20px;padding: 0 10px;">选择查询条件</div>', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'],
type: 1,
maxmin: false,
content: setOptionHtml(),
area: [width, height],
move: false,
shade: 0.1,
success: function (layero, index) {
layui.form.render();
$(window).resize(function () {
if (autoMoreResizeWidth) autoMoreResizeWidth(index);
if (autoMoreResizeHeight) autoMoreResizeHeight(index);
});
},
});
}
/*更多选项赋值*/
function setOptionHtml() {
let html = '<form class="layui-form option-form" onsubmit="return false;">';
let cent = '';
$.each(searchList, function (index, item) {
if (item.isChecked) {
cent += '<div class="layui-input-inline"><input lay-skin="primary" type="checkbox" name="' + item.titleCode + '" title="' + item.titleName + '" checked></div>'
} else {
cent += '<div class="layui-input-inline"><input lay-skin="primary" type="checkbox" name="' + item.titleCode + '" title="' + item.titleName + '"></div>'
}
})
html += '<div class="layui-form-item" style="margin: 5% 0 0 20px;">' + cent + '</div>'
html += '<div class="layui-form-item" style="margin-top: 8%;display: flex;align-items: center;justify-content: center;">' +
'<button class="layui-btn layui-btn-normal layui-btn-sm" onclick="sureOption()">确定</button>' +
'<button class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">取消</button>' +
'</div></form>'
return html;
}
/*确定更多选项*/
function sureOption() {
let formList = [];
$('input[type=checkbox]').each(function (index) {
let html = '';
searchList[index].isChecked = $(this).prop("checked")
if ($(this).prop("checked")) {
formList.push(setOptionForm(searchList[index]))
}
})
setFormHtml(formList);
layer.closeAll()
}
/*给表单内容*/
function setFormHtml(data) {
$('.more-search-box').removeAttr('style')
let html = '', cent = '', cent2 = '', item = $('.option-form .layui-form-item');
clearBasicForm();
$.each(data, function (index, item) {
if (index <= 3) {
html += item;
} else if (index > 3 && index < 9) {
cent += item;
} else {
cent2 += item;
}
})
$(html).prependTo('.basic')
item.eq(0).empty().append(cent);
item.eq(1).empty().append(cent2);
form.render();
if (data.length <= 4) {
$('.table-box').css('height', 'calc(100% - 200px)')
tableIns.getthat().fullHeightGap = '130'
$('.more-search-box').css('margin-bottom', '0')
} else if (data.length > 4 && data.length <= 8) {
$('.more-search-box').css('margin-bottom', '0px')
tableIns.getthat().fullHeightGap = '230'
$('.table-box').css('height', 'calc(100% - 257px)')
} else if (data.length === 9) {
tableIns.getthat().fullHeightGap = '230'
$('.table-box').css('height', 'calc(100% - 290px)')
}
tableIns.resize();
getOrgSelect();
getProStatus();
getProType();
getVoltage();
getIsStop();
getProject();
}
function getProject() {
let keys = [];
$("#bidName").empty();
Ajax().post({
headers: {
"encrypt": sm3(JSON.stringify({
params: encrypt(JSON.stringify({
currentUserId: user.userId,
isSup: user.isSup,
currentUserOrgId: user.orgId
}))
}))
},
url: dataUrl + 'proteam/pot/weekRisk/getProject',
data: {
params: encrypt(JSON.stringify({
currentUserId: user.userId,
isSup: user.isSup,
currentUserOrgId: user.orgId
}))
},
success: function (data) {
console.log(data);
let obj = data.data;
$.each(obj, function (index, item) {
keys.push({
"name": item.projectName,
"value": item.projectName
});
});
formSelects.data('bidName', 'local', {
arr: keys
});
form.render();
}
});
}
/*设置更多选项表单*/
function setOptionForm(item) {
let html = '';
if (item.type === 'select') {
html = '<div class="layui-inline ' + item.titleCode + '">' +
'<label class="layui-form-label">' + item.titleName + ':</label>' +
'<div class="layui-input-inline">' +
'<select class="layui-select" xm-select="' + item.titleCode + '" xm-select-max="5" xm-select-search="" xm-select-search-type="dl" xm-select-show-count=\'1\' id="' + item.titleCode + '">' +
'</select>' +
'</div>' +
'</div>'
} else {
html = '<div class="layui-inline ' + item.titleCode + '">' +
'<label class="layui-form-label">' + item.titleName + ':</label>' +
'<div class="layui-input-inline">' +
'<input type="text" id="' + item.titleCode + '" class="layui-input" autocomplete="off" placeholder="请输入' + item.titleName + '">' +
'</div>' +
'</div>'
}
return html;
}
/*清空表单的内容*/
function clearBasicForm() {
let obj = $('.basic-form .layui-form-item .layui-inline');
obj.each(function () {
if ($(this).hasClass('keyWord') || $(this).hasClass('btns')) {
} else {
let classAttr = $(this).attr('class');
obj.remove('.' + classAttr.substring(classAttr.indexOf(' ') + 1, classAttr.length));
}
})
}
// 重置页面样式
function resetContent() {
if ($('.layui-inline').length <= 5) {
$('.table-box').css('height', 'calc(100% - 300px)')
tableIns.getthat().fullHeightGap = '180'
} else if ($('.layui-inline').length > 5 && $('.layui-inline').length <= 10) {
$('.table-box').css('height', 'calc(100% - 300px)')
tableIns.getthat().fullHeightGap = '220'
} else if ($('.layui-inline').length === 11) {
$('.table-box').css('height', 'calc(100% - 300px)')
tableIns.getthat().fullHeightGap = '220'
}
tableIns.resize();
}