vibration.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var xhr = new XMLHttpRequest();
  2. var url = "tower/org";
  3. obj="";
  4. obj2 = "";
  5. xhr.open("GET",url);
  6. xhr.onload = function(){
  7. obj = JSON.parse(xhr.responseText);
  8. //insertHTML();
  9. start();
  10. onChangeColumn1();
  11. onChangeColumn2();
  12. onChangeColumn3();
  13. click_button();
  14. };
  15. xhr.send();
  16. function insertHTML(data){
  17. var tower_select = document.getElementById('tower');
  18. //aria.innerHTML=data[0].tower_name;
  19. var inner='';
  20. for(var i=0;i<data.length;i++){
  21. inner+='<option value="'+data[i].tower_name+'">'+data[i].tower_name+'</option>';
  22. }
  23. document.getElementById("tower").innerHTML=inner;
  24. }
  25. function click_button() {
  26. //alert("click");
  27. companySelect=document.getElementById("company-list");
  28. factorySelect=document.getElementById("factory-list");
  29. departmentSelect=document.getElementById("department-list");
  30. towerGroupSelect=document.getElementById("towerGroup-list");
  31. if(companySelect.value!=0 && factorySelect.value!=0 && departmentSelect.value!=0 && towerGroupSelect.value!=0){
  32. var url2 = "tower/?company="+ companySelect.value + "&factory=" + factorySelect.value + "&department=" +departmentSelect.value + "&towerGroup=" +towerGroupSelect.value ;
  33. var xhr2 = new XMLHttpRequest();
  34. xhr2.open("GET",url2);
  35. xhr2.onload = function(){
  36. obj2 = JSON.parse(xhr2.responseText);
  37. insertHTML(obj2);
  38. console.log(obj2);
  39. show_tower_info();
  40. };
  41. xhr2.send();
  42. }
  43. }
  44. function show_tower_info(){
  45. tower =document.getElementById("tower").value;
  46. console.log(tower);
  47. inner = '';
  48. for(var i=0;i<obj2.length;i++){
  49. if(obj2[i].tower_name === tower){
  50. for(var ii=0;ii<obj2[i].tower_data.Moter.length;ii++){
  51. inner += '<p >'+ obj2[i].tower_data.Moter[ii].DataValue + ',' + obj2[i].tower_data.Moter[ii].CVIndex+'</p>';
  52. }
  53. }
  54. }
  55. document.getElementById("tower_info").innerHTML = inner;
  56. console.log(inner);
  57. }
  58. //document就是這html文件。
  59. //getElementById是裡面的方法,參數給"college-list"抓到這id標籤列
  60. function start(){
  61. companySelect=document.getElementById("company-list");
  62. factorySelect=document.getElementById("factory-list");
  63. departmentSelect=document.getElementById("department-list");
  64. towerGroupSelect=document.getElementById("towerGroup-list");
  65. var inner='';
  66. var company_arr = new Array();
  67. for(var i=0;i<obj.length;i++){
  68. if(company_arr.indexOf(obj[i].company)==-1 && obj[i].able==1){
  69. inner=inner+'<option value="'+obj[i].company+'">公司'+obj[i].company+'</option>';
  70. company_arr.push(obj[i].company);
  71. }
  72. }
  73. //innerHTML 賦值inner給這element屬性
  74. companySelect.innerHTML=inner;
  75. }
  76. //製造一個字串,以html的語法填入院的陣列
  77. function onChangeColumn1() {
  78. companySelect=document.getElementById("company-list");
  79. factorySelect=document.getElementById("factory-list");
  80. departmentSelect=document.getElementById("department-list");
  81. towerGroupSelect=document.getElementById("towerGroup-list");
  82. factorySelect.innerHTML='';
  83. let factory_arr = new Array();
  84. let factory_inner = '';
  85. for(var i=0;i<obj.length;i++){
  86. if( companySelect.value == obj[i].company){
  87. if(factory_arr.indexOf(obj[i].factory)==-1 && obj[i].able==1){
  88. factory_inner=factory_inner+'<option value="'+obj[i].factory+'">廠區'+obj[i].factory+'</option>';
  89. factory_arr.push(obj[i].factory);
  90. }
  91. }
  92. //alert(companySelect.value);
  93. }
  94. factorySelect.innerHTML=factory_inner;
  95. }
  96. function onChangeColumn2() {
  97. companySelect=document.getElementById("company-list");
  98. factorySelect=document.getElementById("factory-list");
  99. departmentSelect=document.getElementById("department-list");
  100. towerGroupSelect=document.getElementById("towerGroup-list");
  101. departmentSelect.innerHTML='';
  102. let department_arr = new Array();
  103. let department_inner = '';
  104. for(var i=0;i<obj.length;i++){
  105. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory){
  106. if(department_arr.indexOf(obj[i].department)==-1 && obj[i].able==1){
  107. department_inner=department_inner+'<option value="'+obj[i].department+'">課'+obj[i].department+'</option>';
  108. department_arr.push(obj[i].department);
  109. }
  110. }
  111. }
  112. document.getElementById("department-list").innerHTML=department_inner;
  113. }
  114. function onChangeColumn3() {
  115. companySelect=document.getElementById("company-list");
  116. factorySelect=document.getElementById("factory-list");
  117. departmentSelect=document.getElementById("department-list");
  118. towerGroupSelect=document.getElementById("towerGroup-list");
  119. towerGroupSelect.innerHTML='';
  120. let towerGroup_inner = '';
  121. for(var i=0;i<obj.length;i++){
  122. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department){
  123. if( obj[i].able==1){
  124. for(var ii=0;ii<obj[i].group.length;ii++){
  125. towerGroup_inner=towerGroup_inner+'<option value="'+obj[i].group[ii]+'">機組'+obj[i].group[ii]+'</option>';
  126. }
  127. }
  128. }
  129. }
  130. document.getElementById("towerGroup-list").innerHTML= towerGroup_inner;
  131. }