272 lines
8.1 KiB
Plaintext
272 lines
8.1 KiB
Plaintext
let table, form, layer, rate, util, laydate,laypage;
|
||
let pageNum = 1, limitSize = 10; // 默认第一页,分页数量为10
|
||
$(function () {
|
||
layui.use(['rate', 'layer', 'form', 'table', 'util', 'laydate','laypage'], function () {
|
||
layer = layui.layer;
|
||
form = layui.form;
|
||
rate = layui.rate;
|
||
table = layui.table;
|
||
util = layui.util;
|
||
laydate = layui.laydate;
|
||
laypage=layui.laypage;
|
||
//日期范围
|
||
laydate.render({
|
||
elem: '#startTime'
|
||
, type: 'date'
|
||
, range: '~'
|
||
, format: 'yyyy-MM-dd',
|
||
max: Date.parse(new Date()),
|
||
});
|
||
util.event('lay-active', {
|
||
query: function () {
|
||
pages(1, 10, false);
|
||
},
|
||
export: function () {
|
||
exportData();
|
||
}
|
||
});
|
||
form.on("select(deviceType1)", function (data) {
|
||
getDeviceNum(data.value);
|
||
});
|
||
form.render();
|
||
initDeviceTypeSelect();
|
||
pages(1, 10, 1);
|
||
|
||
// initTable();
|
||
getDeviceNum("");
|
||
|
||
});
|
||
});
|
||
function pages(pageNum, pageSize, typeNum) {
|
||
let params = getReqParams(pageNum, pageSize, typeNum);
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify(params))
|
||
},
|
||
url: dataUrl + "proteam/pot/ledger/getDeviceLedgerList" + '?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 getReqParams(page, limit, type) {
|
||
let startTime = isEmpty($('#startTime').val().split('~')[0])?"":$('#startTime').val().split('~')[0];
|
||
let endTime = isEmpty($('#startTime').val().split('~')[1])?"":$('#startTime').val().split('~')[1];
|
||
if (!type) {
|
||
return {
|
||
page: page + "",
|
||
limit: limit + "",
|
||
bName: $('#project').val(),
|
||
manage: $('#manage').val(),
|
||
puId: $('#puId').val(),
|
||
bidNo: $('#bidNo').val(),
|
||
startTime: startTime.trim(),
|
||
endTime: endTime.trim()
|
||
};
|
||
}else{
|
||
return {
|
||
page: '1',
|
||
limit: '10',
|
||
bName: "",
|
||
manage: "",
|
||
puId: "",
|
||
bidNo: "",
|
||
startTime: "",
|
||
endTime: ""
|
||
};
|
||
}
|
||
|
||
}
|
||
|
||
function laypages(total, page, limit) {
|
||
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) {
|
||
table.render({
|
||
elem: "#deviceTable",
|
||
id: "deviceTable",
|
||
data: dataList,
|
||
limit: limit,
|
||
loading: true,
|
||
height: "full-420",
|
||
cols: [
|
||
[//表头
|
||
{
|
||
field: "number",
|
||
type: "numbers",
|
||
title: "序号",
|
||
// width: 100,
|
||
unresize: true,
|
||
align: "center",
|
||
},
|
||
{
|
||
field: 'bName',
|
||
title: "工程名称",
|
||
unresize: true,
|
||
// minWidth: 200,
|
||
align: "center",
|
||
|
||
},
|
||
{
|
||
field: "manage",
|
||
title: "班组长",
|
||
// minWidth: 200,
|
||
unresize: true,
|
||
align: "center",
|
||
},
|
||
{
|
||
field: "bidNo",
|
||
title: "标段编码",
|
||
unresize: true,
|
||
// minWidth: 200,
|
||
align: "center",
|
||
},
|
||
{
|
||
field: "createDay",
|
||
title: "入库时间",
|
||
unresize: true,
|
||
// minWidth: 200,
|
||
align: "center"
|
||
},
|
||
{
|
||
field: "puId",
|
||
title: "PUID",
|
||
unresize: true,
|
||
// minWidth: 200,
|
||
align: "center",
|
||
},
|
||
{
|
||
field: "operTime",
|
||
title: "绑定时间",
|
||
unresize: true,
|
||
// minWidth: 200,
|
||
align: "center",
|
||
}
|
||
],
|
||
],
|
||
done: function (res, curr, count) {
|
||
},
|
||
parseData: function (res) {
|
||
console.log(res);
|
||
return {
|
||
"code": res.code === 200 ? 0 : res.code,
|
||
"msg": res.msg,
|
||
"count": res.total,
|
||
"data": res.rows
|
||
};
|
||
}
|
||
});
|
||
}
|
||
|
||
//设备类型下拉选
|
||
function initDeviceTypeSelect() {
|
||
Ajax().post({
|
||
url: dataUrl + 'system/sys/selected/getDeviceTypeSelected',
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify({'params':"device_type"}))
|
||
},
|
||
data: {
|
||
params: "device_type"
|
||
},
|
||
async: true,
|
||
success: function (data) {
|
||
let html = "";
|
||
html += "<option value=''>全部</option>"
|
||
if (data != null && data.length > 0) {
|
||
for (let i = 0; i < data.length; i++) { //循环LIST
|
||
html += "<option value=" + data[i].code + ">" + data[i].name + "</option>";
|
||
}
|
||
}
|
||
$("#deviceType1").empty().append(html);
|
||
$("#deviceType2").empty().append(html);
|
||
form.render();
|
||
}
|
||
|
||
});
|
||
}
|
||
|
||
//导出
|
||
function exportData() {
|
||
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
let url = dataUrl + "proteam/pot/ledger/exportDeviceLedger?" + setData(getReqParams(1, 10, false)) + '&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(1, 10, false))));
|
||
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 getDeviceNum(deviceType) {
|
||
Ajax().post({
|
||
url: dataUrl + 'proteam/pot/ledger/getDeviceNum',
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify({'deviceType':deviceType}))
|
||
},
|
||
data: {
|
||
deviceType: deviceType
|
||
},
|
||
success: function (data) {
|
||
console.log(data);
|
||
$.each(data.data, function (index, item) {
|
||
$('#deviceNum').text(item.deviceNum);
|
||
$('#onlineNum').text(item.onlineNum);
|
||
$('#offlineNum').text(item.offlineNum);
|
||
$('#longOfflineNum').text(item.longOfflineNum);
|
||
});
|
||
}
|
||
|
||
});
|
||
}
|
||
|
||
|
||
|