tower2.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. var xhr = new XMLHttpRequest();
  2. var url = "tower/org";
  3. obj="";
  4. xhr.open("GET",url);
  5. xhr.onload = function(){
  6. obj = JSON.parse(xhr.responseText);
  7. //insertHTML();
  8. start();
  9. };
  10. xhr.send();
  11. function insertHTML(data){
  12. var aria = document.getElementById('test');
  13. var tower_select = document.getElementById('tower');
  14. //aria.innerHTML=data[0].tower_name;
  15. var inner='<option value=0>請選擇水塔</option>';
  16. for(var i=0;i<data.length;i++){
  17. inner=inner+'<option value="'+data[i].tower_name+'">'+data[i].tower_name+'</option>';
  18. }
  19. tower_select.innerHTML=inner;
  20. }
  21. obj2 = "";
  22. function click_button() {
  23. //alert("click");
  24. companySelect=document.getElementById("company-list");
  25. factorySelect=document.getElementById("factory-list");
  26. departmentSelect=document.getElementById("department-list");
  27. towerGroupSelect=document.getElementById("towerGroup-list");
  28. if(companySelect.value!=0 && factorySelect.value!=0 && departmentSelect.value!=0 && towerGroupSelect.value!=0){
  29. var url2 = "tower/?company="+ companySelect.value + "&factory=" + factorySelect.value + "&department=" +departmentSelect.value + "&towerGroup=" +towerGroupSelect.value ;
  30. var xhr2 = new XMLHttpRequest();
  31. xhr2.open("GET",url2);
  32. xhr2.onload = function(){
  33. obj2 = JSON.parse(xhr2.responseText);
  34. insertHTML(obj2);
  35. };
  36. xhr2.send();
  37. }
  38. }
  39. function tower_info(){
  40. towerSelect=document.getElementById("tower");
  41. tower = towerSelect.value;
  42. inner = "";
  43. for(var i=0;i<obj2.length;i++){
  44. if(obj2[i].tower_name == tower){
  45. inner = '<p> DCS </P> '+
  46. '<p> 入水溫度 = '+ obj2[i].tower_data.DCS.hotTemp + ' </P> ' +
  47. '<p> 出水溫度 = '+ obj2[i].tower_data.DCS.coldTemp + ' </P> ' +
  48. '<p> 水流量 = '+ obj2[i].tower_data.DCS.waterFlow + ' </P> ' +
  49. '<p> 風扇馬達電流 = '+ obj2[i].tower_data.DCS.fanMotorCur + ' </P> ' +
  50. '<p> 風扇馬達轉速頻率 = '+ obj2[i].tower_data.DCS.fanMotorSpeedFreq + ' </P><br> ' +
  51. '<p> 風扇震動 </P> '+
  52. '<p> 馬達震動 = '+ obj2[i].tower_data.Moter.ch01.Vrms + ' </P> ' +
  53. '<p> 減速機震動 = '+ obj2[i].tower_data.Fan.reducer + ' </P> ' +
  54. '<p> 靜壓機 = '+ obj2[i].tower_data.Fan.staticPressure + ' </P> ' +
  55. '<p> 水流量 = '+ obj2[i].tower_data.Fan.waterFlow + ' </P> ' +
  56. '<p> 濕求溫度 = '+ obj2[i].tower_data.Fan.wetTemp + ' </P> ' +
  57. '<p> 水冷槽溫度1 = '+ obj2[i].tower_data.Fan.coldTempData1 + ' </P> ' +
  58. '<p> 水冷槽溫度2 = '+ obj2[i].tower_data.Fan.coldTempData2 + ' </P><br> ' +
  59. '<p> 馬達震動 </P> '+
  60. '<p> ch001,通道1'+ obj2[i].tower_data.Moter.ch01.Vrms + ',' + obj2[i].tower_data.Moter.ch01.CV+' </P> ' +
  61. '<p> ch002,通道2'+ obj2[i].tower_data.Moter.ch02.Vrms + ',' + obj2[i].tower_data.Moter.ch02.CV+' </P> '
  62. ;
  63. }
  64. }
  65. console.log(obj2[0].tower_data.DCS.hotTemp);
  66. document.getElementById("tower_info").innerHTML = inner;
  67. }
  68. //document就是這html文件。
  69. //getElementById是裡面的方法,參數給"college-list"抓到這id標籤列
  70. function start(){
  71. companySelect=document.getElementById("company-list");
  72. factorySelect=document.getElementById("factory-list");
  73. departmentSelect=document.getElementById("department-list");
  74. towerGroupSelect=document.getElementById("towerGroup-list");
  75. var inner='<option value=0>請選擇公司</option>';
  76. var company_arr = new Array();
  77. for(var i=0;i<obj.length;i++){
  78. if(company_arr.indexOf(obj[i].company)==-1 && obj[i].able==1){
  79. inner=inner+'<option value="'+obj[i].company+'">公司'+obj[i].company+'</option>';
  80. company_arr.push(obj[i].company);
  81. }
  82. }
  83. //innerHTML 賦值inner給這element屬性
  84. companySelect.innerHTML=inner;
  85. }
  86. //製造一個字串,以html的語法填入院的陣列
  87. function onChangeColumn1() {
  88. companySelect=document.getElementById("company-list");
  89. factorySelect=document.getElementById("factory-list");
  90. departmentSelect=document.getElementById("department-list");
  91. towerGroupSelect=document.getElementById("towerGroup-list");
  92. factorySelect.innerHTML='<option value=0>請選擇工廠</option>';
  93. let factory_arr = new Array();
  94. let factory_inner = '<option value=0>請選擇工廠</option>';
  95. for(var i=0;i<obj.length;i++){
  96. if( companySelect.value == obj[i].company){
  97. if(factory_arr.indexOf(obj[i].factory)==-1 && obj[i].able==1){
  98. factory_inner=factory_inner+'<option value="'+obj[i].factory+'">工廠'+obj[i].factory+'</option>';
  99. factory_arr.push(obj[i].factory);
  100. }
  101. }
  102. //alert(companySelect.value);
  103. }
  104. factorySelect.innerHTML=factory_inner;
  105. }
  106. function onChangeColumn2() {
  107. companySelect=document.getElementById("company-list");
  108. factorySelect=document.getElementById("factory-list");
  109. departmentSelect=document.getElementById("department-list");
  110. towerGroupSelect=document.getElementById("towerGroup-list");
  111. departmentSelect.innerHTML='<option value=0>請選擇廠區</option>';
  112. let department_arr = new Array();
  113. let department_inner = '<option value=0>請選擇廠區</option>';
  114. for(var i=0;i<obj.length;i++){
  115. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory){
  116. if(department_arr.indexOf(obj[i].department)==-1 && obj[i].able==1){
  117. department_inner=department_inner+'<option value="'+obj[i].department+'">廠區'+obj[i].department+'</option>';
  118. department_arr.push(obj[i].department);
  119. }
  120. }
  121. }
  122. document.getElementById("department-list").innerHTML=department_inner;
  123. }
  124. function onChangeColumn3() {
  125. companySelect=document.getElementById("company-list");
  126. factorySelect=document.getElementById("factory-list");
  127. departmentSelect=document.getElementById("department-list");
  128. towerGroupSelect=document.getElementById("towerGroup-list");
  129. towerGroupSelect.innerHTML='<option value=0>請選擇機組</option>';
  130. let towerGroup_inner = '<option value=0>請選擇機組</option>';
  131. for(var i=0;i<obj.length;i++){
  132. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department){
  133. if( obj[i].able==1){
  134. for(var ii=0;ii<obj[i].group.length;ii++){
  135. towerGroup_inner=towerGroup_inner+'<option value="'+obj[i].group[ii]+'">機組'+obj[i].group[ii]+'</option>';
  136. }
  137. }
  138. }
  139. }
  140. document.getElementById("towerGroup-list").innerHTML= towerGroup_inner;
  141. }