186 lines
5.9 KiB
Plaintext
186 lines
5.9 KiB
Plaintext
let user = getUser();
|
||
let form, layer, laydate, orgList;
|
||
orgList = getOrgSelect();
|
||
layui.use(['form', 'layer'], function () {
|
||
layer = layui.layer;
|
||
form = layui.form;
|
||
form.render();
|
||
form.on('select(checkedType)', function (data) {
|
||
if (data.value === '1') {
|
||
$('#org-div').css('display', 'none')
|
||
$('#pro-div').css('display', 'none')
|
||
$('#org-table').empty();
|
||
$('#pro-table').empty();
|
||
} else if (data.value === '2') {
|
||
$('#org-div').removeAttr('style')
|
||
$('#pro-div').css('display', 'none')
|
||
$('#pro-table').empty();
|
||
initClassTable(orgList, 'org-table', '序号', '地市');
|
||
} else if (data.value === '3') {
|
||
$('#org-div').css('display', 'none')
|
||
$('#pro-div').removeAttr('style')
|
||
$('#org-table').empty();
|
||
getProNumByOrgAjax();
|
||
}
|
||
})
|
||
});
|
||
|
||
function initClassTable(data, name, idx, titleName) {
|
||
let html = '<thead><tr><td><input onclick="selectAll(this.checked)" type="checkbox"></td><td>' + idx + '</td><td>' + titleName + '</td></tr></thead>';
|
||
html += '<tbody>'
|
||
if (data && data.length > 0) {
|
||
$.each(data, function (index, item) {
|
||
if (item) {
|
||
html += '<tr ondblclick="dbSel(this)">' +
|
||
'<td><input onclick="sel(this.checked,this)" name="check" type="checkbox"></td>' +
|
||
'<td code="' + item.code + '">' + (index + 1) + '</td>' +
|
||
'<td>' + item.name + '</td>' +
|
||
'</tr>';
|
||
}
|
||
})
|
||
} else {
|
||
html += '<tr><td colspan="3">暂无数据</td></tr>';
|
||
}
|
||
html += '</tbody>'
|
||
$('#' + name).empty().append(html);
|
||
}
|
||
|
||
// 复选框全选
|
||
function selectAll(selectStatus) {//传入参数(全选框的选中状态)
|
||
//根据name属性获取到单选框的input,使用each方法循环设置所有单选框的选中状态
|
||
if (selectStatus) {
|
||
$("input[name='check']").each(function (i, n) {
|
||
n.checked = true;
|
||
});
|
||
} else {
|
||
$("input[name='check']").each(function (i, n) {
|
||
n.checked = false;
|
||
});
|
||
}
|
||
}
|
||
|
||
//双击选中
|
||
function dbSel(that) {
|
||
let flag = $(that).find('input').prop("checked");
|
||
if (flag) {
|
||
$(that).find('input').prop("checked", false);
|
||
} else {
|
||
$(that).find('input').prop("checked", true);
|
||
}
|
||
}
|
||
|
||
// 单个选中
|
||
function sel(selectStatus, that) {
|
||
if (selectStatus) {
|
||
$(that).prop('checked', true);
|
||
} else {
|
||
$(that).prop('checked', false);
|
||
}
|
||
}
|
||
|
||
// 获取复选框选中的值
|
||
function selData() {
|
||
let list = [];
|
||
$("input[name='check']").each(function (i, n) {
|
||
if (n.checked === true) {
|
||
let id = $(n).parent().parent().find('td').eq(1).attr('code');
|
||
list.push(id);
|
||
}
|
||
});
|
||
return list;
|
||
}
|
||
|
||
// 保存
|
||
function save() {
|
||
let checkType = $('#checkedType').val();
|
||
let idStr = '';
|
||
if (checkType === '2') {
|
||
let list = selData();
|
||
if (list.length === 0) {
|
||
return layer.msg('请选择地市', {icon: 7, time: 2000});
|
||
}
|
||
idStr = list.toString();
|
||
} else if (checkType === '3') {
|
||
let list = selData();
|
||
if (list.length === 0) {
|
||
return layer.msg('请选择输变电工程', {icon: 7, time: 2000});
|
||
}
|
||
idStr = list.toString();
|
||
}
|
||
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
let params = {
|
||
type: checkType,
|
||
id: encrypt(idStr)
|
||
}
|
||
let url = dataUrl + "proteam/pot/proInfo/exportProData?token=" + token;
|
||
let xhr = new XMLHttpRequest();
|
||
xhr.open("POST", url, true);
|
||
xhr.responseType = "blob"; // 转换流
|
||
xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8')
|
||
xhr.setRequestHeader("encrypt",
|
||
sm3(JSON.stringify(params)));
|
||
xhr.onload = function () {
|
||
layer.close(loadingMsg);
|
||
if (this.status === 200) {
|
||
let blob = this.response;
|
||
var a = document.createElement("a");
|
||
var url = window.URL.createObjectURL(blob);
|
||
a.href = url;
|
||
a.download = "工程信息" + getNowDate() + ".xlsx"; // 文件名
|
||
} else {
|
||
layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000});
|
||
}
|
||
a.click();
|
||
window.URL.revokeObjectURL(url);
|
||
};
|
||
xhr.send(JSON.stringify(params));
|
||
}
|
||
|
||
function query() {
|
||
let pattern = new RegExp("[%_<>]");
|
||
if (pattern.test($("#proName").val())) {
|
||
$("#proName").val('');
|
||
return layer.msg('工程名称查询包含特殊字符,请重新输入', {
|
||
icon: 2,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
});
|
||
}
|
||
getProNumByOrgAjax();
|
||
}
|
||
|
||
// 获取输变电工程
|
||
function getProNumByOrgAjax() {
|
||
let param = {
|
||
proName: $('#proName').val()
|
||
}
|
||
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify(param))
|
||
},
|
||
url: dataUrl + 'proteam/pot/proInfo/getPowerProData?token=' + token,
|
||
data: param,
|
||
type: 'POST',
|
||
async: true,
|
||
success: function (result) {
|
||
layer.close(loadingMsg);
|
||
if (result.code === 200) {
|
||
if (result.data) {
|
||
initClassTable(result.data, 'pro-table', '序号', '工程名称');
|
||
}
|
||
} else if (result.code === 500) {
|
||
layer.alert(result.msg, {icon: 2})
|
||
} else if (result.code === 401) {
|
||
logout(1)
|
||
}
|
||
}, error: function () {
|
||
layer.close(loadingMsg);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 关闭页面
|
||
function closePage(type) {
|
||
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
||
parent.layer.close(index); //再执行关闭
|
||
} |