diff --git a/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java b/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java index 72b164a..bfc1761 100644 --- a/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java @@ -272,6 +272,7 @@ public class CountServiceImpl extends BaseService implements ICountService { // 返回结果 Map result = getHashMap(4); result.put("year", year); + result.put("areaList", areaDTOs); result.put("checkItemList", checkItemList); return new SuccessResultData<>(result); } diff --git a/src/main/resources/static/route/count/list-countenterprisechecktable.html b/src/main/resources/static/route/count/list-countenterprisechecktable.html index 591b8d1..77d006d 100644 --- a/src/main/resources/static/route/count/list-countenterprisechecktable.html +++ b/src/main/resources/static/route/count/list-countenterprisechecktable.html @@ -32,7 +32,7 @@ 打印 -
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
@@ -43,20 +58,148 @@ var $ = layui.$; var $win = $(window); var laydate = layui.laydate; + var laytpl = layui.laytpl; var common = layui.common; - var resizeTimeout = null; - // 事件 - 页面变化 - $win.on('resize', function() { - clearTimeout(resizeTimeout); - resizeTimeout = setTimeout(function() { - reloadTable(); - }, 500); - }); + var today = common.formatDate('yyyy', new Date()) + + // 初始化日期 + function initDate() { + // 日期选择 + laydate.render({ + elem: '#year', + type: 'year', + format: 'yyyy', + trigger: 'click', + value: today + }); + } + initDate(); + + // 动态表格 + function DynamicTable(data) { + var maxColspan = 1; + function initMaxColspan(data, level) { + if(level > maxColspan) { + maxColspan = level; + } + for(var i = 0, item; item = data[i++];) { + // 处理成标准结构开始 + if(item.subCheckItem && item.subCheckItem.length > 0) { + item.sub = item.subCheckItem; + } else if(item.checkItemOptions && item.checkItemOptions.length > 0) { + item.sub = item.checkItemOptions; + } + // 处理成标准结构结束 + if(item.sub) { + initMaxColspan(item.sub, level + 1); + } + } + } + + initMaxColspan(data, 1); + + function getRowspan(data) { + var rowSpan = 0; + if(data.sub) { + for(var i = 0, item; item = data.sub[i++];) { + rowSpan += getRowspan(item); + } + } + return rowSpan == 0 ? 1 : rowSpan; + } + + // 构建表格 + function buildTable(data, level, callback) { + var trData = ''; + for(var i = 0, item; item = data[i++];) { + // 设置行开始 + if(i > 1) { + trData += ''; + } + var colspan = 1; + // 设置合并列 + if(!item.sub) { + colspan = level < maxColspan ? (maxColspan - level + 1) : 1; + } + // 设置合并行 + var rowspan = getRowspan(item); + trData += ''+ item.name +''; + if(item.sub) { + trData += buildTable(item.sub, level + 1, callback); + } else { + if(callback) { + trData += callback(item); + } + } + // 设置行结束 + if(i > 1) { + trData += '' + } + } + return trData; + } + + function initTHead(id, area) { + var th = '指标'; + for(var i = 0, item; item = area[i++];) { + th += ''+ item.dictionaryName +''; + } + document.getElementById(id).innerHTML = th; + } + function initTBody(id, callback) { + var tableString = buildTable(data, 1, callback); + document.getElementById(id).innerHTML = tableString; + } + this.initTHead = initTHead; + this.initTBody = initTBody; + } function initTable() { - + var loadLayerIndex; + top.restAjax.get(top.restAjax.path('api/count/counthiddendangerreportdetail/{year}', [$('#year').val() ? $('#startTime').val() : today]), {}, null, function(code, data) { + laytpl(document.getElementById('tableBoxTemplate').innerHTML).render(data, function(html) { + document.getElementById('tableBox').innerHTML = html; + var dynamicTable = new DynamicTable(data.data.checkItemList); + dynamicTable.initTHead('tHead', data.data.areaList); + dynamicTable.initTBody('tBody', function(tdData) { + var td = ''; + for(var i = 0, item; item = tdData.areaList[i++];) { + td += ''+ item.checkCount +''; + } + return td; + }); + }); + }, function(code, data) { + top.dialog.msg(data.msg); + }, function() { + loadLayerIndex = top.dialog.msg('正在加载...', {icon: 16, time: 0, shade: 0.3}); + }, function() { + top.dialog.close(loadLayerIndex); + }); } + initTable(); + + // 事件 - 搜索 + $(document).on('click', '#search', function() { + initTable(); + }); + + $(document).on('click', '#print', function() { + var bodyHtml = $('html'); + var html = bodyHtml.clone(); + html.find('.button-group-box').remove(); + html.find('.layui-anim').css({'padding': '0px'}); + var win = window.open("打印窗口", "_blank"); + win.document.write(html.html()); + $(win.document).ready(function() { + setTimeout(function() { + win.print(); + win.close(); + }, 100); + }); + }); + });