<template>
  <div>中间件</div>
</template>

<script>
import { getToken } from '@/utils/auth'
export default {
  data(){
    return{
      networkQuery:{
        span_id:'07fe3536fd3d424b',
        parent_span_id:'88a432e4c06ea0fd'
      },
    }
  },
  methods:{
    arrayToList(arr) {
      if (!arr.length) return null;

      let obj = arr.filter((item)=>{
        if(item.span_id == this.networkQuery.span_id){
          return item;
        }
      })
      let list = arr.filter((item)=>{
        if(item.span_id != this.networkQuery.span_id){
          return item;
        }
      })
      // let header = new ListNode(obj);
      let header = obj[0];
      let current = header;

      for(let i =0;i<arr.length;i++){
        for(let j =0;j<list.length;j++){
          if(arr[i].parent_id == list[j].id){
            // current.children = new ListNode(list[j]);
            current.children=[list[j]];
            current = current.children
          }
        }
      }
      return header;
    },
    handleData(data) {
          data.forEach((v, k) => {
          v.id = v.span_id;
          v.collapsed = false;
          v.name = v['Enum(tap_side)'];
          // v.label = (v.duration).toFixed(2);
          v.label = v.duration.toFixed(2);
          v.currency='ms';
          // v.rate = v.duration_persent;
          v.rate = '';
          // v.status = (v.status_code == 'STATUS_CODE_ERROR'||v.events_timestamp.length>0||v.http_code>399)?'R':(v.duration>500)?'Y':'G';
          // v.variableValue = v.duration_persent;
          v.status = 'G';
          v.variableValue = '';
          // v.status_code = 'UNSET'
          if (v.children != undefined && v.children.length > 0) {
              v.children = this.handleData(v.children)
            }
          })
          return data
    },
  },
  created(){
    this.$http({
      url: 'http://df-app.cestong.com.cn/v1/stats/querier/network-spans',
      method: 'post',
      headers: {
        'Authorization': 'Bearer ' + getToken() // 特定请求的header
      },
      data:{
        "span_id": "07fe3536fd3d424b",
        "parent_span_id": "88a432e4c06ea0fd"
      }
    }).then(res=>{
      let list = this.handleData([this.arrayToList(res.data.OPT_STATUS)]);

    })
  },

}
</script>

<style>

</style>
