614c5f8a1d4c25fab206c33a7a1d907650444a0e.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var cdid=null;
  2. var cdycm=null;
  3. var child=[];
  4. var pageParam={};
  5. var chart=null;
  6. var utils=new Util();
  7. var startTime=null;
  8. var endTime=null;
  9. var searchUtil = new SearchUtil();
  10. $(function(){
  11. pageParam.style=utils.resolveUrl()["style"]||"style1";
  12. pageParam.title=utils.resolveUrl()["title"]||"广东电网";
  13. pageParam.number=utils.resolveUrl()["number"]||warnningnumber;
  14. pageParam.parentId=utils.resolveUrl()["dept_id"]||"11";
  15. var date=allGetServerTime();
  16. $("#beginTime").val(getDateC(-1,date));
  17. startTime=$("#beginTime").val();
  18. init();
  19. //首页里面加载Iframe展开方法
  20. // setIframe(iframModuleID);
  21. });
  22. function getDateC(digit,date){
  23. date.setDate(date.getDate()+digit);
  24. var m=(date.getMonth()+1)>10?((date.getMonth()+1)):('0'+(date.getMonth()+1))
  25. return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
  26. }
  27. function init(){
  28. queryCD();
  29. if(null==cdid){
  30. find();
  31. }
  32. }
  33. function find(){
  34. var shu=0;
  35. $("#i_add").on("click",function(){
  36. shu++;
  37. if(shu>0&&shu<=2){
  38. var $his_time = $('<span>历史时间:</span>');
  39. $("#i_time").append($his_time);
  40. var input = $('<input type="text" id="time'+shu+'" name="time" class="date dt" dateFmt="yyyy-MM-dd"/></br>');
  41. input.render();
  42. $his_time.after(input);
  43. }else{
  44. top.Dialog.alert("最多可查询三个历史时间!");
  45. }
  46. });
  47. $("#i_search").on("click",function(){
  48. loadChart(cdid);
  49. });
  50. }
  51. function onClickItem(){
  52. $("#comp_id").bind("change",function(){
  53. if(!$(this).attr("relValue")){
  54. top.Dialog.alert("没有选择节点");
  55. }else{
  56. cdycm=$(this).attr("relText");
  57. cdid=$(this).attr("relValue");
  58. }
  59. });
  60. }
  61. function queryCD(){
  62. $.post("/nwyj/ws/ChartServiceImpl/ChartServiceImpl/getCSGRDBDeptInfo",{compId:pageParam.parentId},function(result){
  63. if("FAILURE"==result.state){
  64. $("#i_comp_con").hide();
  65. zeroChartIntoParam("网络异常");
  66. return
  67. }
  68. if(0==result.rows.length){
  69. $("#i_comp_con").hidden();
  70. zeroChartIntoParam("该单位目前尚未开放此项服务");
  71. return
  72. }
  73. for(var index=0,len=result.rows.length;index<len;index++)
  74. {
  75. var item=result.rows[index];
  76. item.key=item["CDYCM"];
  77. item.value=item["CDID"];
  78. if(pageParam.parentId==item["DEPT_ID"])
  79. {
  80. cdid=item["CDID"];
  81. cdycm=item["CDYCM"];
  82. child.unshift(item);
  83. loadChart(cdid,startTime);
  84. }else{
  85. child.push(item);
  86. }
  87. }
  88. if(child.length>1){
  89. /*加载列表 */
  90. var selData={"list":child};
  91. $("#comp_id").data("data",selData)
  92. $("#comp_id").render();
  93. $(".selectbox-wrapper").css("width","239px");
  94. $(".selectbox").css("width","210px");
  95. onClickItem();
  96. }
  97. },"json");
  98. }
  99. function loadChart(id){
  100. var time="";
  101. $("input[name='time']").each(function(){
  102. $(this).val();
  103. time+=$(this).val()+",";
  104. });
  105. //[{"msecond":980,"value":12,"pt":3158815,"lsecond":1468311492,"dateStr":"2016-07-12 16:18:12"}]
  106. $.post("/nwyj/ws/ChartServiceImpl/ChartServiceImpl/getCSGRDBDataInfo",{compId:cdid,startTime:time},function(result){
  107. //alert(result.rows.length);
  108. //console.log(JSON.stringify(result))
  109. if("FAILURE"==result.state){
  110. zeroChartIntoParam("网络异常");
  111. return ;
  112. }
  113. if(result.rows.length==0){
  114. zeroChartIntoParam("尚未查询到数据");
  115. return;
  116. }
  117. veriColor();
  118. removeNoData();
  119. var sArr = [];
  120. var xAxis = [];
  121. var leArr = [];
  122. for(var i=result.rows.length-1; i >=0; i--){
  123. var sp = {type:"line",name:substringTimeName(result.rows[i][0].dateStr),data:[], symbolSize:0,
  124. itemStyle: { normal: {color:pageStyle[pageParam.style]["chartColor"][i]}}};
  125. var spdata = [];
  126. for(var j = 0; j < result.rows[i].length; j++){
  127. spdata.push(result.rows[i][j].value);
  128. if(i==1){
  129. xAxis.push(substringTime(result.rows[i][j].dateStr));
  130. }
  131. };
  132. leArr.push(substringTimeName(result.rows[i][0].dateStr));
  133. sp.data = spdata;
  134. sArr.push(sp);
  135. };
  136. pageParam.opParams={
  137. /* title:"截止时间:"+item["APPEAR_TIME"],//标题
  138. subtext:"当前停运数:"+item["sum"]+" (条)", */
  139. saveName:$("#i_page_head_title").find("h2").html()+searchUtil.getNowFormatDateTime(new Date),
  140. unit:"",//单位
  141. leArr:leArr,//图例
  142. xAxis:xAxis,//x轴
  143. yxf:"MW",//y轴格式化
  144. sArr:sArr,//主数据
  145. trigger:"axis",
  146. legendColor:legendC,
  147. value:"value",
  148. xAxisColor:xAxisC,
  149. yAxisColor:yAxisC
  150. };
  151. chart=getEchart($("#i_page_chart"),getOption,pageParam.opParams,null);
  152. setTitle();
  153. bindEvent();
  154. },"json");
  155. }
  156. function substringTimeName(item){
  157. //var str=item.substring(item.indexOf(" ")-2,item.indexOf(" "));
  158. var str=item.substring(0,10);
  159. return str;
  160. }
  161. function substringTime(item){
  162. //var str=item.substring(item.indexOf(" ")-2,item.indexOf(" "));
  163. var str=item.substring(item.indexOf(" ")+1,item.indexOf(" ")+6);
  164. return str;
  165. }
  166. /**
  167. *设置标题
  168. */
  169. function setTitle(){
  170. $("#i_page_head_title").find("h2").remove();
  171. $("#i_page_head_title").append("<h2>"+cdycm+"</h2>");
  172. }
  173. function bindEvent(){
  174. $(window).resize(function(){
  175. chart.resize();
  176. });
  177. }
  178. //五分钟一个断面
  179. setInterval(function(){
  180. loadChart(cdid,startTime);
  181. }, "300000");