<template>
  <BasicLayout>
    <template #wrapper>
      <el-card class="box-card" style="flex:1;">
        <div v-if="activeName==&quot;first&quot;" class="block-container" style="margin-bottom:20px">
          <div class="row">
            <div class="col">
              <el-tooltip placement="bottom" effect="dark" :visible-arrow="false">
                <div slot="content">
                  <i class="dot" />
                  <span>{{ digitsObj.Span }}</span>
                </div>
                <div class="border-bottom">
                  <div class="block-box px-3 py-4">
                    <div class="col-tit">SPANS/min</div>
                    <div class="col-con">{{ digitsObj.Span !=undefined?digitsObj.Span:0 }}</div>
                  </div>
                </div>
              </el-tooltip>
            </div>
            <div class="col">
              <el-tooltip placement="bottom" effect="dark" :visible-arrow="false">
                <div slot="content">
                  <i class="dot" />
                  <span>{{ digitsObj.Http }}</span>
                </div>
                <div class="border-bottom">
                  <div class="block-box px-3 py-4">
                    <div class="col-tit">HTTP/min</div>
                    <div class="col-con">{{ digitsObj.Http !=undefined?digitsObj.Http:0 }}</div>
                  </div>
                </div>
              </el-tooltip>
            </div>
            <div class="col">
              <el-tooltip placement="bottom" effect="dark" :visible-arrow="false">
                <div slot="content">
                  <i class="dot" />
                  <span>{{ digitsObj.Rpc }}</span>
                </div>
                <div class="border-bottom">
                  <div class="block-box px-3 py-4">
                    <div class="col-tit">RPC/min</div>
                    <div class="col-con">{{ digitsObj.Rpc !=undefined?(digitsObj.Rpc).toFixed(2):0 }}</div>
                  </div>
                </div>
              </el-tooltip>
            </div>
            <div class="col">
              <el-tooltip placement="bottom" effect="dark" :visible-arrow="false">
                <div slot="content">
                  <i class="dot" />
                  <span>{{ digitsObj.Error!=undefined?digitsObj.Error:0 }}</span>
                </div>
                <div class="border-bottom">
                  <div class="block-box px-3 py-4">
                    <div class="col-tit">HTTPERROR/min</div>
                    <div class="col-con">{{ digitsObj.Error!=undefined?(digitsObj.Error).toFixed(2):0 }}</div>
                  </div>
                </div>
              </el-tooltip>
            </div>
            <div class="col">
              <el-tooltip placement="bottom" effect="dark" :visible-arrow="false">
                <div slot="content">
                  <i class="dot" />
                  <span>{{ digitsObj.DB }}</span>
                </div>
                <div class="border-bottom">
                  <div class="block-box px-3 py-4">
                    <div class="col-tit">DATABASE/min</div>
                    <div class="col-con">{{ digitsObj.DB !=undefined?digitsObj.DB :0 }}</div>
                  </div>
                </div>
              </el-tooltip>
            </div>
          </div>
        </div>
        <div v-if="activeName==&quot;second&quot;" class="scaleMain-warrper">
          <div v-if="chartLoading3" v-loading="chartLoading3" />
          <div v-else>
            <div v-if="isShowChart3" id="scaleMain" class="scaleMain-box" />
            <div v-else class="no-data-des">暂无数据</div>
          </div>
        </div>
        <div class="link-box">
          <router-link class="to-inline-block" :to="{path:'/service/InterfaceSublist/index'}">
            <el-button type="primary" size="mini">接口解析</el-button>
          </router-link>
          <router-link class="to-inline-block" :to="{path:'/service/process/index'}">
            <el-button type="primary" size="mini">进程解析</el-button>
          </router-link>
        </div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="对比分析" name="first">
            <el-form ref="timeQuery" :model="timeQuery" :inline="true" label-width="100px" style="text-align: right;">
              <el-form-item label="时间跨度" prop="hour_num">
                <el-select v-model="timeQuery.hour_num" placeholder="时间选择" clearable size="small" @keyup.enter.native="handletimeQuery" @change="changetimeQuery">
                  <el-option
                    v-for="time in timeOptions"
                    :key="time.value"
                    :label="time.label"
                    :value="time.value"
                  />
                </el-select>
              </el-form-item>
            </el-form>
            <div>
              <h6 class="h6">活跃度</h6>
              <div class="echartsWrap">
                <div v-if="chartLoading" v-loading="chartLoading" />
                <div v-else>
                  <div v-if="isShowChart" id="serviceActive" ref="Echarts" style="width:100vw;height:220px" />
                  <div v-else class="no-data-des">暂无数据</div>
                </div>
              </div>

              <h6 class="h6">错误率分布</h6>
              <div class="echartsWrap">
                <div v-if="chartLoading2" v-loading="chartLoading2" />
                <div v-else>
                  <div v-if="isShowChart2" id="errorRate" style="width:100vw;height:220px" />
                  <div v-else class="no-data-des">暂无数据</div>
                </div>
              </div>

            </div>
          </el-tab-pane>
          <el-tab-pane label="Span列表" name="second">
            <div style="display:flex">
              <el-form ref="spansQuery" :model="spansQuery" :inline="true" label-width="100px">
                <el-form-item label="自定义属性" prop="span_attribute_key">
                  <el-input
                    v-model="spansQuery.span_attribute_key"
                    placeholder="请输入自定义属性"
                    clearable
                    size="small"
                    @keyup.enter.native="handleSpansQuery"
                  />
                </el-form-item>
                <el-form-item label="自定义属性值" prop="span_attribute_value">
                  <el-input
                    v-model="spansQuery.span_attribute_value"
                    placeholder="请输入自定义属性值"
                    clearable
                    size="small"
                    @keyup.enter.native="handleSpansQuery"
                  />
                </el-form-item>
                <el-form-item label="Span类型" prop="span_kind">
                  <el-select v-model="spansQuery.span_kind" placeholder="Span类型" clearable size="small" @keyup.enter.native="handleSpansQuery" @change="changeSpansQuery">
                    <el-option
                      v-for="kind in spanOptions"
                      :key="kind.value"
                      :label="kind.label"
                      :value="kind.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="延迟大于" prop="min_duration">
                  <el-input
                    v-model="spansQuery.min_duration"
                    placeholder=""
                    clearable
                    size="small"
                    type="number"
                    class="Dur_input"
                    @keyup.enter.native="handleSpansQuery"
                  >
                    <template slot="append">ms</template>
                  </el-input>
                </el-form-item>
                <el-form-item label="调用方法" prop="request_method">
                  <el-input
                    v-model="spansQuery.request_method"
                    placeholder="请输入调用方法"
                    clearable
                    size="small"
                    @keyup.enter.native="handleSpansQuery"
                  />
                </el-form-item>
                <el-form-item label="" prop="only_exception">
                  <el-checkbox v-model="spansQuery.only_exception" :true-label="1" :false-label="0" @keyup.enter.native="handleSpansQuery" @change="changeErrorSpans">仅异常</el-checkbox>
                </el-form-item>
                <el-form-item label="" prop="only_database">
                  <el-checkbox v-model="spansQuery.only_database" :true-label="1" :false-label="0" @keyup.enter.native="handleSpansQuery" @change="changeSQLSpans">仅SQL</el-checkbox>
                </el-form-item>
              </el-form>
              <div style="display:inline-block;vertical-align: middle;">
                <el-dropdown
                  style="margin-left: 10px"
                  size="mini"
                  trigger="click"
                  placement="bottom"
                >
                  <el-button type="primary" size="mini">
                    <!-- 下拉菜单 -->
                    <i class="el-icon-s-grid" />
                    <!-- 配置项 -->
                    <i class="el-icon-arrow-down" />
                  </el-button>
                  <el-dropdown-menu slot="dropdown">
                    <el-checkbox-group
                      v-model="colSelect"
                      style="text-align: left"
                      @change="columnChange"
                    >
                      <el-dropdown-item
                        v-for="(item, index) in colData"
                        :key="index"
                      ><el-checkbox :label="item.title">{{
                        item.title
                      }}</el-checkbox></el-dropdown-item>
                    </el-checkbox-group>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div style="padding-bottom:16px;">
              <el-table
                v-loading="loading"
                :data="spansList"
                @sort-change="sortChangeTable"
              >
                <el-table-column v-if="isShow('TraceId')" label="TraceId" prop="trace_id" :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    <span @click="goto(scope.row)">{{ scope.row.trace_id }}</span>
                  </template>
                </el-table-column>
                <el-table-column v-if="isShow('服务名')" label="服务名" prop="service_name" :show-overflow-tooltip="true" />
                <el-table-column v-if="isShow('日期')" label="日期" sortable="custom" prop="datetime" :show-overflow-tooltip="true" />
                <el-table-column v-if="isShow('方法')" label="方法" prop="method" :show-overflow-tooltip="true" />
                <el-table-column v-if="isShow('Code')" label="Code" prop="code" :show-overflow-tooltip="true" />
                <el-table-column v-if="isShow('持续时间(ms)')" label="持续时间(ms)" prop="duration" :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.duration>=2000" type="danger">{{ scope.row.duration }}</el-tag>
                    <el-tag v-if="scope.row.duration<2000" type="info">{{ scope.row.duration }}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column
                  v-if="isShow('SpanId')"
                  label="SpanId"
                  prop="span_id"
                  :show-overflow-tooltip="true"
                />
              </el-table>

              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="spansQuery.pageIndex"
                :limit.sync="spansQuery.pageSize"
                @pagination="getServiceSpans"
              />
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </template>
  </BasicLayout>
</template>
<script>
import { digitsService, serviceSpans, serviceCompare, serviceErrors, listServiceStats } from '@/api/service'
import storage from '@/utils/storage'
import moment from 'moment'
export default {
  name: 'ServiceSpace',
  props: {
    nodeServieName: {
      type: String,
      default: ''
    },
    id: {
      type: Number,
      default: 1
    }

  },
  data() {
    return {
      timeQuery: {
        app_alias: '',
        service_name: this.nodeServieName,
        hour_num: 1
      },
      timeOptions: [
        {
          value: 1,
          label: '1 小时'
        },
        {
          value: 3,
          label: '3 小时'
        },
        {
          value: 6,
          label: '6 小时'
        },
        {
          value: 12,
          label: '12 小时'
        },
        {
          value: 24,
          label: '24 小时'
        }
      ],
      spanOptions: [
        {
          value: 'SPAN_KIND_CLIENT',
          label: 'SPAN_KIND_CLIENT'
        },
        {
          value: 'SPAN_KIND_SERVER',
          label: 'SPAN_KIND_SERVER'
        },
        {
          value: 'SPAN_KIND_INTERNAL',
          label: 'SPAN_KIND_INTERNAL'
        },
        {
          value: 'SPAN_KIND_CONSUMER',
          label: 'SPAN_KIND_CONSUMER'
        },
        {
          value: 'SPAN_KIND_PRODUCER',
          label: 'SPAN_KIND_PRODUCER'
        }
      ],
      // 设置选中的列的复选框
      colSelect: [
        'TraceId',
        '服务名',
        '日期',
        '方法',
        'Code',
        '持续时间(ms)'
      ],
      colData: [
        { title: 'TraceId', istrue: false },
        { title: '服务名', istrue: false },
        { title: '日期', istrue: false },
        { title: '方法', istrue: false },
        { title: 'Code', istrue: false },
        { title: '持续时间(ms)', istrue: false },
        { title: 'SpanId', istrue: false }
      ],
      loading: false,
      total: 0,
      activeName: 'first',
      digitsObj: {},
      digitsQuery: {
        app_alias: '',
        service_name: this.nodeServieName
      },
      timer: null,
      spansQuery: {
        app_alias: '',
        request_method: '',
        service_name: this.nodeServieName, // 支持多个，多个并列
        only_exception: 0, // 仅显示异常trace相关
        only_database: 0, // 仅显示数据库相关
        // 支持分页，参数与之前一致
        // 支持时间筛选，参数与之前一致
        trace_id: '', // trace id, 字符串
        span_kind: '', // 固定5个值,建议下拉列表,分别为SPAN_KIND_CLIENT SPAN_KIND_SERVER SPAN_KIND_INTERNAL SPAN_KIND_CONSUMER SPAN_KIND_PRODUCER
        span_attribute_key: '', // 字符串
        span_attribute_value: '', // 字符串
        min_duration: 0, // 最小耗时
        max_duration: 0, // 最大耗时
        start_time: 0,
        end_time: 0,
        pageIndex: 1,
        pageSize: 10,
        sort_field: 'Timestamp',
        sort_type: 'DESC'
      },
      spansList: [],
      ServiceCompareObj: {
        current: [],
        forward: [],
        time: []
      },
      errorRateObj: {
        current: [],
        forward: [],
        time: []
      },
      compareChart: null,
      errorChart: null,
      statsQuery: {
        id: this.id,
        start_time: '',
        end_time: ''
      },
      statsObj: {
        quantiles: {
          p50: [],
          p90: [],
          p99: [],
          time: []
        }
      },
      chartLoading: false,
      isShowChart: false,
      chartLoading2: false,
      isShowChart2: false,
      chartLoading3: false,
      isShowChart3: false
    }
  },
  watch: {
    '$store.state.time.globalTimes': {
      handler(newValue, oldValue) {
        if (newValue) {
          this.digitsQuery.start_time = newValue.startTime
          this.digitsQuery.end_time = newValue.endTime
          this.statsQuery.start_time = newValue.startTime
          this.statsQuery.end_time = newValue.endTime

          this.spansQuery.start_time = newValue.startTime
          this.spansQuery.end_time = newValue.endTime

          this.getDigitsService()
          this.getlistServiceStats()
          this.getServiceSpans()
          this.isShowChart3 = (((this.statsObj || {}).quantiles || {}).time || []).length > 0
          if (this.activeName === 'second' && this.isShowChart3) {
            setTimeout(() => {
              this.drawEchartsScale(this.statsObj)
            }, 300)
          }
          if (newValue.timeOut) {
            if (newValue.timeOut == 1) {
              clearInterval(this.timer)
            } else {
              clearInterval(this.timer)
              this.Refresh(newValue.timeOut)
            }
          }
        }
      },
      // immediate: true,
      deep: true
    },
    '$store.state.alias.currentAlias': { // 当前应用切换
      handler(newValue, oldValue) {
        this.appItem = storage.get('appsItem')
        this.digitsQuery.app_alias = newValue
        this.spansQuery.app_alias = newValue
        this.timeQuery.app_alias = newValue
      },
      deep: true
    }
  },
  mounted() {
    this.initData()
  },

  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    initData() {
      // appItem中的id和app_id是一样的
      this.appItem = storage.get('appsItem')
      this.digitsQuery.service_name = this.nodeServieName
      this.spansQuery.service_name = this.nodeServieName
      this.timeQuery.service_name = this.nodeServieName
      this.statsQuery.id = this.id
      const start_time = this.$store.state.time.globalTimes.startTime
      const end_time = this.$store.state.time.globalTimes.endTime
      if (JSON.stringify(this.appItem) != '{}') {
        this.digitsQuery.app_alias = this.appItem.alias
        this.digitsQuery.app_id = this.appItem.id
        this.digitsQuery.start_time = start_time
        this.digitsQuery.end_time = end_time
        this.spansQuery.app_alias = this.appItem.alias
        this.spansQuery.start_time = start_time
        this.spansQuery.end_time = end_time
        this.timeQuery.app_alias = this.appItem.alias
        this.statsQuery.start_time = start_time
        this.statsQuery.end_time = end_time
      }

      this.getDigitsService()
      this.getServiceSpans()
      this.getServiceCompare()
      this.getErrorRateCompare()
      this.getlistServiceStats()

      this.columnChange()
    },
    Refresh(timeOut) {
      this.timer = setInterval(() => {
        this.getDigitsService()
        this.getlistServiceStats()
        this.getServiceSpans()
        this.getServiceCompare()
        this.getErrorRateCompare()
      }, timeOut)
    },
    // 获取延迟比例charts 数据
    getlistServiceStats() {
      this.chartLoading3 = true
      this.statsObj = {}
      this.statsQuery.id = this.id
      listServiceStats(this.statsQuery).then(response => {
        this.chartLoading3 = false
        if (response && response.code == 200) {
          this.statsObj = response.data
        } else {
          this.statsObj = {}
        }
      })
    },
    drawEchartsScale(row) {
      const _this = this
      const myChartScale = this.$echarts5.init(document.getElementById('scaleMain'))
      // 绘制趋势echarts
      const option = {
        tooltip: {
          trigger: 'axis',
          // confine: false,
          // appendToBody: true,
          show: true,
          formatter: function(params) {
            storage.set('paramsValue', params)
            const axisValueLabel = params[0].axisValueLabel
            let str0 = ''
            params.forEach((item, idx) => {
              // str1+=`${}`
              str0 += `${item.marker}${item.seriesName}<span style='margin-left:30px;text-align:right;font-weight:400'>${item.data}</span>`
              switch (idx) {
                case 0:
                  str0
                  break
                case 1:
                  str0
                  break
                default:
                  str0
              }
              str0 += idx === params.length - 1 ? '' : '<br/>'
            })
            return axisValueLabel + '<br>' + str0
          }
        },
        title: {
          text: '延迟比例',
          // subtext: 'ms',
          textStyle: {
            fontSize: 14
          }
          // triggerEvent: true,
        },
        grid: {
          // top:'5%',
          left: '3%',
          right: '6%',
          bottom: '1%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: row.quantiles.time,
          axisLabel: {
            textStyle: {
              fontSize: 12,
              textAlign: 'center'
            },
            formatter: function(params) {
              // let newParams = moment(params).format('YYYY-MM-DD HH:mm:ss');
              // let newArr = newParams.split(' ')
              // let time = newArr[0] + "\n" + newArr[1]
              // return time;

              let newParams = ''
              const dateStr = params.substring(0, 10)
              // dateStr = dateStr.replace(/\-/g, function(match) {
              //   return match.replace(/\-/g, '.');
              // });
              const timeStr = params.substring(11, 19)
              newParams = dateStr + '\n' + timeStr
              return newParams
            }
          }
        },
        yAxis: {
          type: 'value',
          scale: true,
          gridIndex: 0,
          axisLabel: {
            formatter: '{value}'
          },
          axisLine: {
            show: true
          },
          axisTick: {
            show: true
          },
          splitLine: {
            show: true
          }
        },
        series: [
          {
            name: 'P.50',
            type: 'line',
            stack: 'Total',
            symbol: 'none',
            // symbol: 'emptyCircle',//拐点
            data: row.quantiles.p50
          },
          {
            name: 'P.95',
            type: 'line',
            stack: 'Total',
            symbol: 'none', // 拐点
            // symbol: 'emptyCircle',//拐点
            data: row.quantiles.p90
          },
          {
            name: 'P.99',
            type: 'line',
            stack: 'Total',
            symbol: 'none', // 拐点
            // symbol: 'emptyCircle',//拐点
            data: row.quantiles.p99
          }
        ]
      }
      myChartScale.setOption(option)
      myChartScale.getZr().off('click')
      myChartScale.getZr().on('click', params => {
        const data = storage.get('paramsValue')
        const timestamp = moment(data[0].name).unix()
        _this.spansQuery.start_time = timestamp
        _this.spansQuery.end_time = timestamp
        _this.getServiceSpans()
      })
    },
    parseQueryString(url) {
      var json = {}
      var arr = url.substr(url.indexOf('?') + 1).split('&')
      arr.forEach(item => {
        var tmp = item.split('=')
        json[tmp[0]] = decodeURIComponent(tmp[1])
      })
      return json
    },
    handletimeQuery() {
      this.getServiceCompare()
      this.getErrorRateCompare()
    },
    changetimeQuery(val) {
      this.timeQuery.hour_num = val
      this.getServiceCompare()
      this.getErrorRateCompare()
    },
    handleSpansQuery() {
      this.getServiceSpans()
    },
    changeErrorSpans(val) {
      this.spansQuery.only_exception = val
      this.getServiceSpans()
    },
    changeSQLSpans(val) {
      this.spansQuery.only_database = val
      this.getServiceSpans()
    },
    changeSpansQuery(val) {
      this.spansQuery.span_kind = val
      this.getServiceSpans()
    },
    // 控制列的显示和隐藏
    columnChange(val) {
      this.colData.filter((i) => {
        if (this.colSelect.indexOf(i.title) !== -1) {
          i.istrue = true
        } else {
          i.istrue = false
        }
      })
    },
    handleClick(tab, event) {
      if (tab.name === 'second') {
        this.isShowChart3 = (((this.statsObj || {}).quantiles || {}).time || []).length > 0
        if (this.isShowChart3) {
          this.$nextTick(() => {
            this.drawEchartsScale(this.statsObj)
          })
        }
      }
    },

    getDigitsService() {
      this.digitsQuery.service_name = this.nodeServieName
      digitsService(this.digitsQuery).then((res) => {
        if (res.code == 200) {
          this.digitsObj = res.data
        }
      })
    },
    getServiceSpans() {
      this.spansQuery.service_name = this.nodeServieName
      serviceSpans(this.spansQuery).then((res) => {
        if (res.code == 200) {
          this.spansList = res.data.list
          this.total = res.data.count
        }
      })
    },
    getServiceCompare() {
      this.ServiceCompareObj = {}
      this.chartLoading = true
      this.timeQuery.service_name = this.nodeServieName
      serviceCompare(this.timeQuery).then(res => {
        this.chartLoading = false
        if (res && res.code == 200) {
          this.ServiceCompareObj = res.data
          this.isShowChart = (((res.data || {}).time) || []).length > 0
          if (this.isShowChart) {
            this.$nextTick(() => {
              this.initServiceCompareChart(this.ServiceCompareObj)
            })
          }
        } else {
          this.ServiceCompareObj = {}
        }
      })
    },
    initServiceCompareChart(data) {
      this.compareChart = this.$echarts5.getInstanceByDom(this.$refs.Echarts)
      if (this.compareChart == null) {
        this.compareChart = this.$echarts5.init(this.$refs.Echarts)
      }

      this.compareChart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        legend: {
          data: ['当前时段', '前续时段']
        },
        grid: {
          // top:'5%',
          left: '3%',
          right: '16%',
          bottom: '1%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            // type:'time',
            data: data.time
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '当前时段',
            type: 'bar',
            tooltip: {
              valueFormatter: function(value) {
                return value
              }
            },
            barWidth: 8,
            data: data.current != undefined ? data.current : []
          },
          {
            type: 'line',
            name: '前续时段',
            tooltip: {
              valueFormatter: function(value) {
                return value
              }
            },
            lineStyle: {
              width: 3
            },
            data: data.forward != undefined ? data.forward : []
          }
        ]
      })

      this.compareChart.group = 'group1'
      this.$echarts5.connect('group1')
    },
    getErrorRateCompare() {
      this.errorRateObj = {}
      this.chartLoading2 = true
      this.timeQuery.service_name = this.nodeServieName
      serviceErrors(this.timeQuery).then(res => {
        this.chartLoading2 = false
        if (res.code == 200) {
          this.errorRateObj = res.data
          this.isShowChart2 = (((res.data || {}).time) || []).length > 0
          if (this.isShowChart2) {
            this.$nextTick(() => {
              this.initErrorRateCompareChart(this.errorRateObj)
            })
          }
        } else {
          this.errorRateObj = {}
        }
      })
    },
    initErrorRateCompareChart(data) {
      this.errorChart = this.$echarts5.getInstanceByDom(document.getElementById('errorRate'))
      if (this.errorChart == null) {
        this.errorChart = this.$echarts5.init(document.getElementById('errorRate'))
      }
      this.errorChart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        legend: {
          data: ['当前时段', '前续时段']
        },
        grid: {
          // top:'5%',
          left: '3%',
          right: '16%',
          bottom: '1%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: data.time
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '当前时段',
            type: 'bar',
            tooltip: {
              valueFormatter: function(value) {
                return value
              }
            },
            barWidth: 8,
            data: data.current != undefined ? data.current : []
          },
          {
            type: 'line',
            name: '前续时段',
            tooltip: {
              valueFormatter: function(value) {
                return value
              }
            },
            lineStyle: {
              width: 3
            },
            data: data.forward != undefined ? data.forward : []
          }
        ]
      })

      this.errorChart.group = 'group1'
      this.$echarts5.connect('group1')
    },
    goto(row) {
      const datetime = Date.parse(row.datetime) / 1000
      const href = this.$router.resolve({
        path: '/latency/index',
        query: {
          id: row.trace_id,
          span_id: row.span_id,
          datetime: datetime
        }
      })
      window.open(window.location.origin + '/' + href.href, '_blank')
    },
    isShow(label) {
      return this.colData.filter(i => i.title === label)[0].istrue
    },
    sortChangeTable(val) {
      // desc（倒序）和asc（正序）
      if (val.order === 'descending') {
        this.spansQuery.sort_type = 'DESC'
      } else if (val.order === 'ascending') {
        this.spansQuery.sort_type = 'ASC'
      }
      this.getServiceSpans()
    }

  }

}
</script>
<style lang="scss" scoped>
.echartsWrap{
  width:100%;
  height: 240px;
}
.h6{
  font-size: 14px;
}
.Dur_input ::v-deep .el-input__inner{
  width:100px;
}
.noData{
    width: 100%;
    height: 200px;
    background: #fff;
}
.no-data-des{
  text-align: center;
  font-size: 14px;
  height: 288px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #606266;
}
.noData_title{
    margin-bottom: 0px;
    padding: 2px 5px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.57143;
    font-family: Inter, Helvetica, Arial, sans-serif;
}
.link-box{
  display:none;
  text-align: right;
  // position:relative;
  // top:26px;
  .to-inline-block{
    display: inline-block;
    + .to-inline-block{
      margin-left:10px;
    }
    button{
      font-size:14px;
    }
  }
}
.scaleMain-warrper{
  width:100%;
  height:240px;
  margin-bottom:36px;
  margin-top:16px
}

.scaleMain-box{
  width:100%;
  height:240px;
}

</style>
