let form, layer, table, laydate, checkedType = '1', classId = ""; let pageNum = 1, limitSize = 20; // 默认第一页,分页数量为10 layui.use(['form', 'layer', 'table'], function () { form = layui.form; layer = layui.layer; table = layui.table; setBtns('1') pages(1, 20, 1); form.on('select(type)', function (data) { setBtns(data.value); pages(1, 20); }) }) // 设置按钮 function setBtns(value) { checkedType = value; let html = ''; if (value === '1') { html += '' + '' + ''; } else if (value === '2') { html += '' + '' + ''; } $('.btns').empty().append(html) } function pages(pageNum, pageSize, typeNum) { let params = getReqParams(pageNum, pageSize, typeNum); let url = dataUrl + "proteam/pot/ballStatusStatistic/getBallKjList?token=" + token; if (checkedType === '2') { url = dataUrl + "proteam/pot/ballStatusStatistic/getBallHgList?token=" + token; } $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: url, data: params, type: 'POST', async: false, success: function (result) { if (result.code === 200) { if (result.data) { console.log(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) { layui.use(['laypage'], function () { let laypage = layui.laypage; laypage.render({ elem: 'voi-page', count: total, curr: page, limit: limit, limits: [20], 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: "#ballStatusStatisticTable", height: "full-120", data: dataList, limit: limit, cols: [setTableColByType(checkedType, page, limit)], done: function (res, curr, count) { if (checkedType === '2') { let classIdArr = []; if (res.data && res.data.length > 0) { res.data.forEach(function (item, index) { if (item.classIdList.length > 0) { item.classIdList.forEach(function (item2, index2) { classIdArr.push(item2) }) } }) } classId = classIdArr.toString(); } layer.close(loadingMsg); table.resize("ballStatusStatisticTable"); 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 setTableColByType(value, page, limit) { let cols = []; if (value === '1') { cols = [{ title: "序号", width: 80, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "orgName", title: "建管单位", unresize: true, align: "center", sort: true }, { field: "classNum", title: "今日站班会数量", unresize: true, align: "center", sort: true }, { field: "ballNum", title: "球机总数", unresize: true, align: "center", sort: true }, { field: "ballOnNum", title: "今日开机数", unresize: true, align: "center", sort: true }, { field: "ballOffNum", title: "今日未开机", unresize: true, align: "center", sort: true, templet: function (d) { if (d.ballOffNum !== 0) { return '
' + d.ballOffNum + '
'; } else { return d.ballOffNum; } } }, { field: "rate", title: "开机率", unresize: true, align: "center", sort: true }] } else if (value === '2') { cols = [{ title: "序号", width: 80, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "orgName", title: "建管单位", unresize: true, align: "center", sort: true }, { field: "ballTimeHgNum", title: "今日球机在线时长合格数", unresize: true, align: "center", sort: true }, { field: "ballTimeBhgNum", title: "今日球机在线时长不合格数", unresize: true, align: "center", sort: true, templet: function (d) { if (d.ballTimeBhgNum !== 0) { return '
' + d.ballTimeBhgNum + '
'; } else { return d.ballTimeBhgNum; } } }, { field: "rate", title: "合格率", unresize: true, align: "center", sort: true }] } return cols; } // 获取参数 function getReqParams(page, limit, type) { let obj = {}; if (!type) { obj = { page: page + "", limit: limit + "", type: $('#type').val() }; } else { obj = { page: '1', limit: '20', type: '1' }; } return obj; } function refreshData() { pages(1, limitSize) } /*导出*/ function exportData() { let fileName = '当日球机未开机详情'; if (checkedType === '2') { fileName = '当日球机在线时长不合格详情'; } let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,}); let url = dataUrl + "proteam/pot/ballStatusStatistic/exportData?type=" + checkedType + "&orgId=" + "" + "&id=" + classId + "&token=" + token; let xhr = new XMLHttpRequest(); xhr.open("get", url, true); xhr.responseType = "blob"; // 转换流 xhr.setRequestHeader("encrypt", sm3(JSON.stringify({ type: checkedType, orgId: "", id: classId }))); 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 = fileName + getNowDate() + ".xlsx"; // 文件名 } else { layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000}); } a.click(); window.URL.revokeObjectURL(url); }; xhr.send(); } function exportData2() { let fileName = '当日球机开机情况统计'; if (checkedType === '2') { fileName = '当日球机在线时长情况统计'; } let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,}); let url = dataUrl + "proteam/pot/ballStatusStatistic/exportData2?type=" + checkedType + "&token=" + token; let xhr = new XMLHttpRequest(); xhr.open("get", url, true); xhr.responseType = "blob"; // 转换流 xhr.setRequestHeader("encrypt", sm3(JSON.stringify({ type: checkedType, orgId: "" }))); 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 = fileName + getNowDate() + ".xlsx"; // 文件名 } else { layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000}); } a.click(); window.URL.revokeObjectURL(url); }; xhr.send(); } // 球机运行状态-详情 function openBallDetail(orgId, type, classId) { let layerIndex = layer.open({ id: "ballStatusDetail", title: false, type: 2, maxmin: false, content: 'ballStatusChild/ballStatusDetail.html', area: ['100%', '100%'], closeBtn: 0, success: function (layero, index) { let iframeWin = window["layui-layer-iframe" + layerIndex]; iframeWin.setParams(orgId, type, classId); } }); }