let form, laypage, layer, table, formSelects,laydate, orgList;
let pageNum = 1, limitSize = 50; // 默认第一页,分页数量为50
let riskLevelList = getRiskLevelSelect('risk_level');
let dataObj = {};
function setParams(params) {
dataObj = JSON.parse(params);
layui.config({
base: "../../../js/layui/", //此处路径请自行处理, 可以使用绝对路径
}).extend({
formSelects: 'formSelects-v4'
}).use(['form', 'layer', 'table', 'formSelects', 'laypage','laydate'], function () {
form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
table = layui.table;
layer = layui.layer;
formSelects = layui.formSelects;
laypage = layui.laypage; //分页
laydate = layui.laydate;
//日期范围
laydate.render({
elem: '#startTime',
type: 'date',
range: '~',
format: 'yyyy-MM-dd',
value: getNowTime() + ' ~ ' + getNowTime(),
max: Date.parse(new Date()),
btns:['confirm']
});
orgList = getBuildCodeSelect();
setOrg();
setRiskLevel();
$('#status').val(dataObj.status);
layui.form.render();
pages(1, 50, 1);
})
}
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify(params))
},
url: dataUrl + "proteam/duty/child/getNewDayList?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,
limits: [50, 100, 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, });
table.render({
elem: "#proTable",
id: "proTable",
height: "full-220",
data: dataList,
limit: limit,
cols: [
[
{
title: "序号", width: 80, unresize: true, align: "center", templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
{ field: "jhbh", title: "作业计划编号", width: 250, unresize: true, align: "center"},
{ field: "gcxmmc", title: "工程项目名称", width: 200, unresize: true, align: "center"},
{ field: "bzmc", title: "班组名称", width: 180, unresize: true, align: "center"},
{ field: "fzr_mc", title: "工作负责人姓名", width: 180, unresize: true, align: "center"},
{ field: "fzr_dh", title: "工作负责人电话", width: 180, unresize: true, align: "center"},
{ field: "fzr_sfzh", title: "工作负责人身份证号", width: 230, unresize: true, align: "center"},
{ field: "jh_cyrs", title: "计划参与人数", width: 160, unresize: true, align: "center"},
{ field: "status", title: "状态", width: 120, unresize: true, align: "center",
templet: function (d) {
return ''+d.status+'';
}
},
{ field: "dwfx", title: "风险等级", width: 120, unresize: true, align: "center",
templet: function (d) {
return setRiskLevelColor(d.dwfx);
}
},
{ field: "bzdwmc", title: "编制单位名称", width: 180, unresize: true, align: "center"},
{ field: "bzbmmc", title: "编制部门名称", width: 180, unresize: true, align: "center"},
{ field: "bzrmc", title: "编制人名称", width: 130, unresize: true, align: "center"},
{ field: "bzrq", title: "编制日期", width: 220, unresize: true, align: "center"},
{ field: "dydj", title: "电压等级", width: 150, unresize: true, align: "center"},
{ field: "sszy", title: "所属专业", width: 150, unresize: true, align: "center"},
{ field: "zylb", title: "专业类别", width: 150, unresize: true, align: "center"},
{ field: "gzxz", title: "工作性质", width: 150, unresize: true, align: "center"},
{ field: "gzdd", title: "工作地点", width: 250, unresize: true, align: "center"},
{ field: "gznr", title: "工作内容", width: 300, unresize: true, align: "center",
templet: function (d) {
if (d.gznr) {
if (d.gznr.length > 60) {
return '' + d.gznr.substring(0, 60) + '...'
} else {
return '' + d.gznr + ''
}
} else {
return '';
}
}
},
{ field: "jhkgsj", title: "计划开工时间", width: 220, unresize: true, align: "center"},
{ field: "jhwgsj", title: "计划完工时间", width: 220, unresize: true, align: "center"},
{ field: "sfbcf", title: "显示计划是否被拆分", width: 200, unresize: true, align: "center"},
{ field: "yjhbh", title: "显示主计划编号", width: 220, unresize: true, align: "center"},
{ field: "sfzdqqy", title: "是否在电气区域", width: 180, unresize: true, align: "center"},
{ field: "sftd", title: "是否停电", width: 120, unresize: true, align: "center"},
{ field: "sfxyxckc", title: "是否需要现场勘查", width: 180, unresize: true, align: "center"},
{ field: "sfyxscya", title: "是否需要三措一案", width: 180, unresize: true, align: "center"},
{ field: "bzxz", title: "班组性质", width: 120, unresize: true, align: "center"},
{ field: "sjly", title: "数据来源", width: 120, unresize: true, align: "center"},
],
],
done: function (res, curr, count) {
console.log(res);
layer.close(loadingMsg);
$(".layui-laypage-skip").css("display", "none");
table.resize("proTable");
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");
let that = this.elem.next();
if (res.data) {
res.data.forEach(function (item, index) {
if (index % 2 === 0) {
let tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#06182E')
} else {
let tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#1F2F43')
}
})
}
},
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
buildCodes: formSelects.value('buildCode','val'),
riskLevels: formSelects.value('riskLevel','val'),
proName: $("#proName").val(),
status: $("#status").val(),
teamName: $("#teamName").val(),
startTime: $("#startTime").val().split(' ~ ')[0],
endTime: $("#startTime").val().split(' ~ ')[1],
};
} else {
obj = {
page: '1',
limit: '50',
buildCodes: formSelects.value('buildCode','val'),
riskLevels: formSelects.value('riskLevel','val'),
proName: $("#proName").val(),
status: $("#status").val(),
teamName: $("#teamName").val(),
startTime: $("#startTime").val().split(' ~ ')[0],
endTime: $("#startTime").val().split(' ~ ')[1],
};
}
return obj;
}
// 查询/重置
function query(type) {
if(type === 1){
const startTime = $("#startTime").val().split(' ~ ')[0],
endTime = $("#startTime").val().split(' ~ ')[1];
let flag = isOver1Days(startTime,endTime);
if(flag){
return layer.msg('查询的时间间隔不能超过1天', { icon: 2, time: 2000 });
}
}else if (type === 2) {
formSelects.value('buildCode', [])
formSelects.value('riskLevel', [])
$('#proName').val('');
$('#teamName').val('');
$('#status').val('');
$('#startTime').val(getNowTime() + ' ~ ' + getNowTime());
}
pages(1, limitSize, false);
}
/*编制单位名称赋值*/
function setOrg() {
let keys = [];
$.each(orgList, function (index, item) {
let temp = {
"name": item.name,
"value": item.code,
};
keys.push(temp);
})
formSelects.data('buildCode', 'local', {
arr: keys
});
layui.form.render();
}
/* 风险等级赋值 */
function setRiskLevel() {
let keys = [];
$.each(riskLevelList, function (index, item) {
let temp = {
"name": item.name,
"value": item.name
};
keys.push(temp);
})
formSelects.data('riskLevel', 'local', {
arr: keys
});
layui.form.render();
}
function downloadExcelDataByDayPlan(){
const startTime = $("#startTime").val().split(' ~ ')[0],
endTime = $("#startTime").val().split(' ~ ')[1];
let flag = isOver1Days(startTime,endTime);
if(flag){
return layer.msg('导出的时间间隔不能超过1天', { icon: 2, time: 2000 });
}
let params = "buildCode="+formSelects.value('buildCode','val') +
"&riskLevels="+formSelects.value('riskLevel','val') +
"&proName=" + $("#proName").val() +
"&status=" + $("#status").val() +
"&teamName=" + $("#teamName").val() +
"&startTime=" + startTime +
"&endTime=" + endTime +
"&token=" + token;
$('.export').addClass("layui-btn-disabled").attr("disabled", true);
let loadingMsg = layer.msg("数据导出中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
let url = dataUrl + "proteam/duty/child/downloadExcelDataByDayPlan?"+params;
let xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "blob";
xhr.setRequestHeader("encrypt","");
xhr.setRequestHeader("encryption","encryption");
xhr.onload = function () {
layer.close(loadingMsg);
$('.export').removeClass("layui-btn-disabled").attr("disabled", false);
if (this.status === 200) {
let blob = this.response;
var a = document.createElement("a");
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = startTime + '~' + endTime+"日计划"+ ".xlsx"; // 文件名
} else {
layer.msg("数据发生异常,请稍后重试", { icon: 16, scrollbar: false, time: 2000 });
}
a.click();
window.URL.revokeObjectURL(url);
};
xhr.send();
}
// 关闭页面
function closePage(type) {
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
}
function isOver1Days(dateStr1, dateStr2) {
// 将字符串日期转换为Date对象
const date1 = new Date(dateStr1);
const date2 = new Date(dateStr2);
// 计算两个日期的时间差(毫秒)
const timeDiff = Math.abs(date2.getTime() - date1.getTime());
// 将毫秒转换为天数(1天 = 24 * 60 * 60 * 1000毫秒)
const dayDiff = timeDiff / (1000 * 60 * 60 * 24);
// 判断是否超过1天
return dayDiff >= 1;
}