pressure-report.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. var checkedIds = [];
  2. var checkedNoteName = [];
  3. $(function () {
  4. InitialPage();
  5. GetTree();
  6. $("#tabs").tabs({
  7. select: function (event, ui) { alert(ui.index); }
  8. });
  9. });
  10. //初始化页面
  11. function InitialPage() {
  12. //layout布局
  13. $('#layout').layout({
  14. applyDemoStyles: true,
  15. onresize: function () {
  16. $(window).resize();
  17. }
  18. });
  19. //resize重设(表格、树形)宽高
  20. $(window).resize(function (e) {
  21. window.setTimeout(function () {
  22. $('#gridTable').setGridWidth(($('.gridPanel').width()));
  23. $("#gridTable").setGridHeight($(window).height() - 141);
  24. $("#itemTree").setTreeHeight($(window).height() - 52);
  25. }, 200);
  26. e.stopPropagation();
  27. });
  28. }
  29. //加载树
  30. function GetTree() {
  31. var item = {
  32. height: $(window).height() - 52,
  33. url: "/PipeNetworkManage/Meter/GetMeterTreeJson?showCheck=true",
  34. onnodeclick: function (item) {
  35. PointTreeCode = item.id;
  36. //展开下级
  37. $(".bbit-tree-selected").children('.bbit-tree-ec-icon').trigger("click");
  38. },
  39. oncheckboxclick: function (item, status) {
  40. GetAllCheckNodes(item.id, status,item.text);//维护 选中元素id的数组
  41. var tabIndex = getSelectedTabIndex();
  42. if (tabIndex == 0) {
  43. DynamicLoadDayGrid();//动态加载 表格数据
  44. }
  45. if (tabIndex == 1) {
  46. DynamicLoadMonthGrid();//动态加载 表格数据
  47. }
  48. if (tabIndex == 2) {
  49. DynamicLoadYearGrid();//动态加载 表格数据
  50. }
  51. }
  52. };
  53. //初始化
  54. $("#itemTree").treeview(item);
  55. }
  56. //被选中元素的ID,TEXT 数组维护
  57. function GetAllCheckNodes(id, status, text) {
  58. //数据加入数组
  59. if (status == 1) {
  60. if (!checkedIds.contain(id)) {
  61. checkedIds.push(id);
  62. }
  63. if (!checkedNoteName.contain(text)) {
  64. checkedNoteName.push(text);
  65. }
  66. }
  67. if (status == 0) {
  68. if (checkedIds.contain(id)) {
  69. checkedIds.splice(checkedIds.indexOf(id), 1);
  70. }
  71. if (checkedNoteName.contain(text)) {
  72. checkedNoteName.splice(checkedNoteName.indexOf(text), 1);
  73. }
  74. }
  75. }
  76. function DynamicLoadDayGrid() {
  77. $.ajax({
  78. type: "POST",
  79. async: false,
  80. url: "/PipeNetworkManage/Pressure/GetPressureReportDayHead",
  81. dataType: "json",
  82. data: { ids: checkedIds.toString() },
  83. success: function (data) {
  84. GetGrid(data, "dayGrid", $("#dayDate").val(),checkedIds.toString(),0);
  85. },
  86. error: function (xhr, status, error) {
  87. }
  88. });
  89. }
  90. function DynamicLoadMonthGrid() {
  91. $.ajax({
  92. type: "POST",
  93. async: false,
  94. url: "/PipeNetworkManage/Pressure/GetPressureMonthReportHead",
  95. dataType: "json",
  96. data: { ids: checkedIds.toString() },
  97. success: function (data) {
  98. GetGrid(data, "monthGrid", $("#monthDate").val(), checkedIds.toString(), 1);
  99. },
  100. error: function (xhr, status, error) {
  101. }
  102. });
  103. }
  104. function DynamicLoadYearGrid() {
  105. $.ajax({
  106. type: "POST",
  107. async: false,
  108. url: "/PipeNetworkManage/Pressure/GetPressureMonthReportHead",
  109. dataType: "json",
  110. data: { ids: checkedIds.toString() },
  111. success: function (data) {
  112. GetGrid(data, "yearGrid", $("#yearDate").val(), checkedIds.toString(), 2);
  113. },
  114. error: function (xhr, status, error) {
  115. }
  116. });
  117. }
  118. function GetGrid(data,gridId,dateTime,ids,typeFlat) {
  119. $("#" + gridId).jqGrid('GridUnload');
  120. $("#" + gridId).jqGrid({
  121. url: "/PipeNetworkManage/Pressure/GetPressureReport",
  122. datatype: "json",
  123. postData: { ids: ids, typeFlag: typeFlat, time: dateTime },
  124. height: $(window).height() - 170,
  125. colModel: data,
  126. rownumbers: true,
  127. viewrecords: true,
  128. rowNum: 50,
  129. gridview: true,
  130. footerrow: true,
  131. gridComplete: function () {
  132. GridHeadSetting(gridId);
  133. },
  134. loadError: function (xhr, status, error) {
  135. }
  136. });
  137. }
  138. //表头格式化
  139. function GridHeadSetting(gridId) {
  140. var index = getSelectedTabIndex();
  141. var groupHeaders = "[";
  142. if (index == 1)
  143. {
  144. for (var i = 0; i < checkedIds.length; i++) {
  145. groupHeaders = groupHeaders + "{\"startColumnName\":\"avg_" + checkedIds[i] + "\",\"numberOfColumns\": \"3\", \"titleText\": \"" + checkedNoteName[i] + "\"}";
  146. if (i < checkedIds.length - 1) groupHeaders = groupHeaders + ",";
  147. }
  148. }
  149. groupHeaders = groupHeaders + "]";
  150. $("#" + gridId).setGroupHeaders({
  151. useColSpanStyle: true, //表头是否合并行
  152. groupHeaders: JSON.parse(groupHeaders)
  153. });
  154. }
  155. function getSelectedTabIndex() {
  156. return $("#tabs").tabs('option', 'active');
  157. }