Quellcode durchsuchen

Merge branch 'master' of http://git.choozmo.com:3000/aaron-1015/mechanical into master

jeter20131220 vor 3 Jahren
Ursprung
Commit
25e705b01c
1 geänderte Dateien mit 20 neuen und 7 gelöschten Zeilen
  1. 20 7
      static/home.js

+ 20 - 7
static/home.js

@@ -2,6 +2,7 @@ start();
 user_role = '';
 data = '';
 obj = '';
+check = 0;
 // 之後透過 fetch 取得fastapi後端資料!
 function start(){
     var xhr = new XMLHttpRequest();
@@ -53,7 +54,7 @@ function company_show(){
     //顯示company按鈕
     var inner='';
     var company_arr = new Array();
-    
+    check = 0;
     for(var i=0;i<obj[1].length;i++){
         if(company_arr.indexOf(obj[1][i].company)==-1){
             inner+="<button class='btn text-white m-1' id='company " +obj[1][i].company+ "' onclick=\"factory_show(\'"+obj[1][i].company+"\');\"";
@@ -119,6 +120,7 @@ function factory_show(company){
     inner+="<button type='button' class='btn btn btn-outline-success m-1' id='factory C' onclick=\"department_show(\'"+obj[1][0].company+"\',\'C\');\"";
     inner += ">廠區C</button>";
     document.getElementById('company').innerHTML="";
+    document.getElementById('company_text').innerHTML=company;
     document.getElementById('company_name').innerHTML="<button type='button' class='btn btn-primary m-1' onclick=\"company_show();\">返回</button> 公司"+ company + "";
     document.getElementById('factory_select').innerHTML=inner;
     factory_health(factory_arr);
@@ -144,7 +146,7 @@ function department_show(company,factory){
     var inner='';
     var department_arr = new Array();
     for(var i=0;i<obj[1].length;i++){
-        if(department_arr.indexOf(obj[1][i].department)==-1 && obj[1][i].company==company&& obj[1][i].factory==factory){
+        if(department_arr.indexOf(obj[1][i].department)==-1 && obj[1][i].company==company/*&& obj[1][i].factory==factory*/){
             inner+='<option selected value="'+obj[1][i].department+'">課'+obj[1][i].department+'</option>';
             department_arr.push(obj[1][i].department);
         }
@@ -162,36 +164,47 @@ function department_show(company,factory){
     else if(factory==='C'){
         newLocation(24.12,121.42);
     }
+    clear();
+    if(check ===0) {
+        factory_show(company);
+    }
+    document.getElementById('company_name').innerHTML="<button type='button' class='btn btn-primary m-1' onclick=\"factory_show('"+company+"');\">返回</button> 廠區"+ factory + "";
     document.getElementById("department_list").style.display="";
     department_change();
 }
 
 function department_change(){
     console.log("change");
+    check = 0 ;
     var inner='<table style="font-size: 16px;" class="table text-center"><thead><tr><th>機組</th><th>健康狀態</th><th>機組狀態</th></tr></thead>';
     var tower_group_arr = new Array();
     for(var i=0;i<obj[1].length;i++){
-        if(tower_group_arr.indexOf(obj[1][i].group)==-1 && obj[1][i].company==document.getElementById('company_text').innerHTML&& obj[1][i].factory==document.getElementById('factory_text').innerHTML&& obj[1][i].department==document.getElementById("department_list").value){
+        if(tower_group_arr.indexOf(obj[1][i].group)==-1 && obj[1][i].company==document.getElementById('company_text').innerHTML/*&& obj[1][i].factory==document.getElementById('factory_text').innerHTML&& obj[1][i].department==document.getElementById("department_list").value*/){
             inner+='<tr><td>' + obj[1][i].group + '</td><td>健康</td><td><button class="btn btn-primary m-1" onclick=\"towerGroup_show();\">查看</button></td></tr><tr><td>2</td><td>健康</td><td><button class="btn btn-primary m-1" onclick=\"towerGroup_show();\">查看</button></td></tr><tr><td>3</td><td>健康</td><td><button class="btn btn-primary m-1" onclick=\"towerGroup_show();\">查看</button></td></tr>' ;
             tower_group_arr.push(obj[1][i].group);
+            console.log(inner);
         }
     }
-    inner += '</table>'
+    inner += '</table>';
     document.getElementById('department_text').innerHTML=document.getElementById("department_list").value;
     document.getElementById('department_show').innerHTML=inner;
     
 }
 
 function towerGroup_show(){
+    check = 1;
     var inner= '';
     var tower_group_arr = new Array(); 
     for(var i=0;i<obj[1].length;i++){
-        if(tower_group_arr.indexOf(obj[1][i].group)==-1 && obj[1][i].company==document.getElementById('company_text').innerHTML&& obj[1][i].factory==document.getElementById('factory_text').innerHTML&& obj[1][i].department==document.getElementById("department_text").innerHTML){
+        if(tower_group_arr.indexOf(obj[1][i].group)==-1 && obj[1][i].company==document.getElementById('company_text').innerHTML/*&& obj[1][i].factory==document.getElementById('factory_text').innerHTML&& obj[1][i].department==document.getElementById("department_text").innerHTML*/){
             inner += tower(obj[1][i].group);
             tower_group_arr.push(obj[1][i].group);
         }
     }
-    
+    clear();
+    company = document.getElementById('company_text').innerHTML
+    factory= document.getElementById('factory_text').innerHTML
+    document.getElementById('company_name').innerHTML="<button type='button' class='btn btn-primary m-1' onclick=\"department_show('"+company+"','" + factory+"');\">返回</button> 課"+ document.getElementById("department_list").value + "";
     document.getElementById('towergroup').innerHTML=inner;
 }
 
@@ -199,7 +212,7 @@ function tower(tower_group){
     //顯示tower
     var inner= '<p class="fw-bold">機組'+tower_group +'</p><table style="font-size: 16px;" class="table text-center"><tr><th>設備</th><th>馬達效能</th><th>機組狀態</th></tr>';
     for(var i=0;i<obj[1].length;i++){
-        if(obj[1][i].company==document.getElementById('company_text').innerHTML&& obj[1][i].factory==document.getElementById('factory_text').innerHTML&& obj[1][i].department==document.getElementById("department_text").innerHTML&&obj[1][i].group==tower_group){
+        if(obj[1][i].company==document.getElementById('company_text').innerHTML/*&& obj[1][i].factory==document.getElementById('factory_text').innerHTML&& obj[1][i].department==document.getElementById("department_text").innerHTML*/&&obj[1][i].group==tower_group){
             inner+='<tr><td>' + obj[1][i].tower + '</td><td>健康</td><td><button class="btn btn-primary m-1">查看</button></td></tr>';
         }
     }