yn_img_tool/src/main/resources/static/js/pro/pro.js

172 lines
5.5 KiB
JavaScript
Raw 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, dtree, table, tableIns;
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为10
let orgData,selectOrgId="";
layui.config({
base: "../../js/layui-v2.6.8/dtree/", //此处路径请自行处理, 可以使用绝对路径
}).extend({
dtree: 'dtree'
}).use(['form', 'layer', 'table','dtree', 'laydate'], function () {
form = layui.form;
layer = layui.layer;
table = layui.table;
dtree = layui.dtree;
layui.form.render();
pages(1, 10, 1);
})
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
let url = dataUrl + "/basic/pro/getProList"
ajaxRequest(url, "GET", params, true, function () {
}, function (result) {
console.log(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})
}
}, function (xhr) {
error(xhr)
});
}
function laypages(total, page, limit) {
layui.use(['laypage'], function () {
let laypage = layui.laypage;
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
limits: [10, 20, 50, 100, 200, 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,});
tableIns = table.render({
elem: "#table_data",
height: "full-130",
data: dataList,
limit: limit,
cols: [
[
//表头
{title: "序号", width: 80, unresize: true, align: "center",
templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
{field: "companyName", title: "分公司/组织", unresize: true, align: "center"},
{field: "proName", title: "项目名称", unresize: true, align: "center"},
{field: "proType", title: "工程类型", align: "center",templet: 'center'},
{field: "voltageLevel", title: "电压等级", align: "center",templet: 'center'},
{field: "origin", title: "工程地址", align: "center",templet: 'center'},
{field: "status", title: "工程状态", align: "center",templet: 'center'},
],
],
done: function (res, curr, count) {
layer.close(loadingMsg);
table.resize("table_data");
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");
},
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (type === 2) {
$('#companyName').val('')
$('#proName').val('')
$('#status').val('')
layui.form.render();
}
obj = {
page: page + "",
limit: limit + "",
companyName: $('#companyName').val(),
proName: $('#proName').val(),
status: $('#status').val(),
};
obj={
encryptedData:encryptCBC(JSON.stringify(obj))
}
return obj;
}
// 查询/重置
function query(type) {
pageNum = 1;
pages(1, limitSize,type);
}
// 查询/重置
function updatePro() {
let url = dataUrl + "/basic/pro/updateProList"
ajaxRequest(url, "GET", "", true, function () {
}, function (result) {
layer.msg(result.data, {
time: 1000 // 显示时间单位为毫秒默认为3秒这里设置为2秒
}, function(){
query(1); // 在消息关闭后执行查询操作
});
}, function (xhr) {
error(xhr)
});
}
function exportExcel() {
let obj = {
companyName: $('#companyName').val(),
proName: $('#proName').val(),
status: $('#status').val(),
};
let params = {
encryptedData: encryptCBC(JSON.stringify(obj))
}
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
let url = dataUrl + "/basic/pro/downloadProExcel?token=" + tokens + "&encryptedData=" + encodeURIComponent(encryptCBC(JSON.stringify(obj)));
let xhr = new XMLHttpRequest();
xhr.open("post", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8')
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();
}