IntelligentRecognition/ah-jjsp-web/bns/js/dutyTask/remotePatrol/towerMain.js

235 lines
7.4 KiB
JavaScript
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 form, layer, table, tableIns, idParam;
let pageNum = 1, limitSize = 50; // 默认第一页分页数量为10
function setParams(id) {
layui.use(['form', 'layer', 'table'], function () {
form = layui.form;
layer = layui.layer;
table = layui.table;
idParam = id;
initTable();
$('#myModal_edit').on('show.bs.modal', centerModals);
})
}
/*初始化表格*/
function initTable() {
let loadingMsg = layer.msg("数据加载中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
tableIns = table.render({
elem: "#todayTaskTable",
id: "todayTaskTable",
height: "full-110",
url: dataUrl + "proteam/pot/bidTowerMain/getTowerListById?token=" + token,
page: {
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
groups: 5, //只显示 5 个连续页码
limits: [30, 50, 100],
limit: 50,
curr: 1
},
method: 'POST',
where: {
towerName: '',
proNo: idParam
},
response: {
statusCode: 200 //重新规定成功的状态码为 200table 组件默认为 0
},
parseData: function (res) { // res 即为原始返回的数据
return {
"code": res.code,
"msg": res.msg,
"count": res.count,
"data": res.data,
"limit": res.limit,
"curr": res.curr
};
},
cols: [[
//表头
{
title: "序号",
width: '10%',
unresize: true,
align: "center",
templet: function (d) {
return d.LAY_NUM;
}
},
{
field: "towerName",
title: "杆塔名称",
width: '20%',
unresize: false,
align: "center",
},
{
field: "lat",
title: "经度",
width: '25%',
unresize: false,
align: "center",
},
{
field: "lon",
title: "纬度",
width: '25%',
unresize: false,
align: "center",
},
{
title: "操作",
width: '20%',
unresize: false,
align: "center",
templet: function (d) {
return "<a onclick=\"addTowerInfo('" + d.id + "')\">修改</a><div>|</div>" +
"<a onclick=\"delData(1,'" + d.id + '\')" style="color:#EB3330;">删除</a>';
}
},
]],
done: function (res, curr, count) {
layer.close(loadingMsg);
table.resize("todayTaskTable");
pageNum = res.curr, limitSize = res.limit;
},
});
}
// 查询/重置
function query(type) {
if (type === 2) {
$('#towerName').val('')
}
let pattern = new RegExp("[%_<>]");
if (pattern.test($("#towerName").val())) {
$("#towerName").val('');
return layer.msg('杆塔名称查询包含特殊字符,请重新输入', { icon: 2, time: 2000 });
}
layui.form.render();
reloadData();
}
// 刷新表格
function reloadData(type) {
table.reload('todayTaskTable', {
where: {
towerName: $('#towerName').val(),
proNo: idParam
},
page: {
curr: type ? pageNum : 1,
limit: limitSize,
groups: 5, //只显示 5 个连续页码
},
});
}
/*新增/修改杆塔信息*/
function addTowerInfo(id) {
let title = '新增杆塔';
if (id) {
title = '修改杆塔';
}
let layerIndex = layer.open({
id: "addTowerInfo",
title: ['<div style="border-left: 3px solid #2F82FB;display: flex;align-items: center;height: 20px;padding: 0 10px;">' + title + '</div>', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'],
type: 2,
maxmin: false,
content: 'bidTowerForm.html',
area: ['664px', '444px'],
move: false,
success: function (layero, index) {
let iframeWin = window["layui-layer-iframe" + layerIndex];
iframeWin.setParams(idParam,id);
}
});
}
// 删除杆塔数据(单个/批量)
function delData(type, id) {
layer.confirm('确定删除吗?', { 'move': false, 'title': '操作提示' }, function () {
let url = dataUrl + 'proteam/pot/bidTowerMain/delTowerData';
let params = {
'type': type,
'id': type === 1 ? id : idParam,
};
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
if (result.code === 200) {
layer.msg(result.msg, { icon: 1 })
reloadData();
} else if (result.code === 500) {
layer.msg(result.msg, { icon: 1 })
} else if (result.code === 401) {
logout(1);
}
}, function (xhr) {
});
})
}
// 标段杆塔维护模版下载
function modelDownload() {
let loadingMsg = layer.msg('模板下载中,请稍候...', { icon: 16, scrollbar: false, time: 0 });
let url = dataUrl + 'proteam/pot/bidTowerMain/downLoadExcelModel2?token=' + token;
let xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader("encrypt",
sm3(JSON.stringify({})));
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 = "单项工程杆塔维护-导入模板.xlsx"; // 文件名
} else {
layer.msg('服务异常,请稍后重试', { icon: 16, scrollbar: false, time: 2000 });
}
a.click()
window.URL.revokeObjectURL(url)
};
xhr.send();
}
/*导入*/
function chooseFile(){
$("#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") {
excelUpload8(this,idParam,dataUrl + "proteam/pot/bidTowerMain/importExcel2?token=" + token)
} else {
layer.msg("仅支持上传文件格式为xlx、xlsx", {icon: 7,});
$("#import-excel").val("");
}
}
});
// 弹出模态框
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 closePage() {
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
parent.reloadData();
}