online_energy.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /**
  2. * _oo8oo_
  3. * o8888888o
  4. * 88" . "88
  5. * (| -_- |)
  6. * 0\ = /0
  7. * ___/'==='\___
  8. * .' \\| |// '.
  9. * / \\||| : |||// \
  10. * / _||||| -:- |||||_ \
  11. * | | \\\ - /// | |
  12. * | \_| ''\---/'' |_/ |
  13. * \ .-\__ '-' __/-. /
  14. * ___'. .' /--.--\ '. .'___
  15. * ."" '< '.___\_<|>_/___.' >' "".
  16. * | | : `- \`.:`\ _ /`:.`/ -` : | |
  17. * \ \ `-. \_ __\ /__ _/ .-` / /
  18. *=====`-.____`.___ \_____/ ___.`____.-`=====
  19. * `=---=`
  20. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. * 佛祖保佑 永无bug
  22. *
  23. * 电量实时运行图表页面JS
  24. * @author grxie
  25. */
  26. var companyId = $.getUrlParam("cid") //机构代码
  27. var monitorId = undefined
  28. $("input[type=radio][name=picType][value=1]").attr("checked", true) //默认选中电量变化
  29. //$("input[type=radio][name=picType]:checked").val();//获取选择值
  30. var type = "monitor" //监测点数据类型
  31. $("#easyui-datagrid-tab").datagrid({
  32. border: false,
  33. fit: true,
  34. fitcolumns: true,
  35. animate: true,
  36. selectOnCheck: false,
  37. checkOnSelect: false,
  38. singleSelect: true,
  39. frozenColumns: [
  40. [
  41. { field: "monitorName", title: "监控点名称", width: 120, align: "left" },
  42. /*{field:'today',title:'时间',width:120,align:'center',
  43. formatter:function(value,row,index){
  44. if(value != null)
  45. return new Date(value.toString().substr(0,4),parseInt(value.toString().substr(4,2))-1,value.toString().substr(6,2)).format('yyyy-MM-dd');
  46. }
  47. },*/
  48. { field: "total", title: "总电量(kW.h)", width: 100, align: "right" },
  49. ],
  50. ],
  51. columns: [
  52. [{ title: "小时", colspan: 24 }],
  53. [
  54. { field: "1", title: "1", width: 80, align: "center" },
  55. { field: "2", title: "2", width: 80, align: "center" },
  56. { field: "3", title: "3", width: 80, align: "center" },
  57. { field: "4", title: "4", width: 80, align: "center" },
  58. { field: "5", title: "5", width: 80, align: "center" },
  59. { field: "6", title: "6", width: 80, align: "center" },
  60. { field: "7", title: "7", width: 80, align: "center" },
  61. { field: "8", title: "8", width: 80, align: "center" },
  62. { field: "9", title: "9", width: 80, align: "center" },
  63. { field: "10", title: "10", width: 80, align: "center" },
  64. { field: "11", title: "11", width: 80, align: "center" },
  65. { field: "12", title: "12", width: 80, align: "center" },
  66. { field: "13", title: "13", width: 80, align: "center" },
  67. { field: "14", title: "14", width: 80, align: "center" },
  68. { field: "15", title: "15", width: 80, align: "center" },
  69. { field: "16", title: "16", width: 80, align: "center" },
  70. { field: "17", title: "17", width: 80, align: "center" },
  71. { field: "18", title: "18", width: 80, align: "center" },
  72. { field: "19", title: "19", width: 80, align: "center" },
  73. { field: "20", title: "20", width: 80, align: "center" },
  74. { field: "21", title: "21", width: 80, align: "center" },
  75. { field: "22", title: "22", width: 80, align: "center" },
  76. { field: "23", title: "23", width: 80, align: "center" },
  77. { field: "24", title: "24", width: 80, align: "center" },
  78. ],
  79. ],
  80. })
  81. var tab1State = false,
  82. tab2State = false
  83. $("#tabs").tabs({
  84. fit: true,
  85. border: false,
  86. tabPosition: "bottom",
  87. onSelect: function (title, index) {
  88. tabIndex = index
  89. if (index == 0) {
  90. model = "monitor"
  91. } else if (index == 1) {
  92. if (!tab1State) {
  93. monitorId = undefined
  94. loadTreeData("powerunitTree", powerunitTreeUrl)
  95. tab1State = true
  96. type = "powerunit"
  97. }
  98. } else if (index == 2) {
  99. if (!tab2State) {
  100. monitorId = undefined
  101. loadTreeData("buildingsTree", buildingTreeUrl)
  102. tab2State = true
  103. type = "building"
  104. }
  105. }
  106. },
  107. })
  108. //加在树数据
  109. function loadTreeData(renderObj, url) {
  110. ajax({
  111. url: url,
  112. type: "POST",
  113. dataType: "json",
  114. cache: false,
  115. success: function (data) {
  116. if (data.status == 1) {
  117. showTree(renderObj, data.data)
  118. } else {
  119. toast(data.msg)
  120. }
  121. },
  122. })
  123. }
  124. var monitorTreeUrl = "/web/getMonitorTree/tree.json?cid=" + companyId
  125. var buildingTreeUrl = "/web/buildingmornitor/getBuildingMonitorTree.json?cid=" + companyId
  126. var powerunitTreeUrl = "/web/monitor/powerunit/getPowerUnitMonitorTree.json?cid=" + companyId
  127. //加载监测点数据
  128. function showTree(renderObj, _data) {
  129. $("#" + renderObj).tree({
  130. method: "POST",
  131. lines: true,
  132. animate: true,
  133. data: _data,
  134. onClick: function (node) {
  135. monitorId = node.id
  136. if (node.attribute.type != undefined) {
  137. type = node.attribute.type
  138. }
  139. loadOnlineEnergyDate()
  140. onclickPowerRadio()
  141. },
  142. onLoadSuccess: function (node, data) {
  143. if (monitorId == undefined) {
  144. //首次加载时,选中默认节点
  145. var firstNode = $("#" + renderObj).tree("getChildren", $("#" + renderObj).tree("getRoot").target)[0]
  146. if (firstNode) {
  147. $("#" + renderObj).tree("select", firstNode.target)
  148. monitorId = firstNode.id
  149. }
  150. loadOnlineEnergyDate()
  151. onclickPowerRadio()
  152. }
  153. },
  154. })
  155. }
  156. function loadOnlineEnergyDate() {
  157. $("#datagrid-tab").mask("数据加载中...")
  158. //var tabIndex = $('#tabs').tabs('getTabIndex',$('#tabs').tabs('getSelected'));
  159. ajax({
  160. url: "/web/anal/energy/getTodayEnergyDate.json",
  161. data: { monitorId: monitorId, type: type },
  162. type: "POST",
  163. dataType: "json",
  164. cache: false,
  165. success: function (data) {
  166. if (data.status == 1) {
  167. var energyData = data.data[0]
  168. var gridData = {}
  169. gridData.monitorName = energyData.monitorName
  170. gridData.today = energyData.date
  171. var total = 0
  172. for (var i = 1; i <= 24; i++) {
  173. for (var j = 0; j < energyData.energyList.length; j++) {
  174. if (!energyData.energyList[j]) {
  175. continue
  176. }
  177. if (i == energyData.energyList[j].hour) {
  178. if (!isNaN(total + energyData.energyList[j].tpe)) total += energyData.energyList[j].tpe
  179. gridData["" + i] = energyData.energyList[j].tpe
  180. }
  181. }
  182. }
  183. gridData.total = total.toFixed(2)
  184. $("#easyui-datagrid-tab").datagrid({ data: [gridData] })
  185. } else {
  186. toast(data.msg)
  187. }
  188. },
  189. })
  190. $("#datagrid-tab").unmask()
  191. }
  192. function onclickPowerRadio() {
  193. var picType = $("input[type=radio][name=picType]:checked").val()
  194. ajax({
  195. url: "/web/online/energy/getChartsData.json",
  196. data: { monitorId: monitorId, picType: picType, type: type },
  197. type: "POST",
  198. dataType: "json",
  199. cache: false,
  200. success: function (data) {
  201. if (data.status == 1) {
  202. showAreaCharts(data.data)
  203. } else {
  204. toast(data.msg)
  205. }
  206. },
  207. })
  208. }
  209. Highcharts.setOptions({
  210. lang: {
  211. resetZoom: "返回",
  212. resetZoomTitle: "回到初始状态",
  213. printChart: "打印图表",
  214. downloadPNG: "导出PNG格式图片",
  215. downloadJPEG: "导出 JPEG格式图片",
  216. downloadPDF: "导出 PDF文档",
  217. downloadSVG: "导出 SVG矢量图片",
  218. contextButtonTitle: "打印和导出",
  219. },
  220. global: { useUTC: false },
  221. })
  222. function showAreaCharts(data) {
  223. //var chart = new Highcharts.Chart({
  224. $("#showchart").highcharts({
  225. chart: {
  226. renderTo: "showchart",
  227. zoomType: "x",
  228. spacingRight: 20,
  229. },
  230. title: {
  231. text: data.title,
  232. },
  233. xAxis: {
  234. showEmpty: true,
  235. type: "datetime",
  236. maxZoom: 24 * 3600, // one days
  237. title: {
  238. text: null,
  239. },
  240. labels: {
  241. formatter: function () {
  242. return Highcharts.dateFormat("%H:%M", this.value)
  243. },
  244. },
  245. },
  246. yAxis: {
  247. min: 0,
  248. title: {
  249. text: "电量(kW.h)",
  250. },
  251. },
  252. tooltip: {
  253. shared: true,
  254. formatter: function () {
  255. //%Y-%m-%d
  256. return Highcharts.dateFormat("%H点%M分", this.x) + "(" + this.y + ")"
  257. },
  258. },
  259. legend: {
  260. enabled: false,
  261. },
  262. plotOptions: {
  263. area: {
  264. fillColor: {
  265. linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
  266. stops: [
  267. [0, Highcharts.getOptions().colors[0]],
  268. [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get("rgba")],
  269. ],
  270. },
  271. lineWidth: 1,
  272. marker: {
  273. enabled: false,
  274. },
  275. shadow: false,
  276. states: {
  277. hover: {
  278. lineWidth: 1,
  279. },
  280. },
  281. threshold: null,
  282. },
  283. series: {
  284. connectNulls: true,
  285. },
  286. },
  287. series: [
  288. {
  289. type: "area",
  290. // name: 'USD to EUR',
  291. pointInterval: 300 * 1000,
  292. pointStart: data.pointStart,
  293. data: data.series[0].data,
  294. },
  295. ],
  296. })
  297. }
  298. $(document).ready(function () {
  299. loadTreeData("monitorTree", monitorTreeUrl)
  300. })
  301. //窗口大小变化时延时刷新图片大小
  302. $(window).resize(function () {
  303. if ($("#showchart").highcharts()) {
  304. $("#showchart")
  305. .highcharts()
  306. .setSize($(window).width() - 230, $("#imageShow").height(), true)
  307. }
  308. /*window.resizeTimer = setTimeout(function() {
  309. window.clearTimeout(window.resizeTimer);
  310. },100);*/
  311. })