<template>
  <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="0">
    <el-form-item label="" prop="metricsName">
      <el-input
          v-model="queryParams.metricsName"
          placeholder="请输入指标名称"
          clearable
      />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="Search" @click="getList">搜索</el-button>
    </el-form-item>
  </el-form>

  <el-table v-loading="loading" border :data="metricsList">
    <el-table-column label="ID" align="center" prop="objMetricsId" width="80"/>
    <el-table-column label="指标分类" align="left" width="120">
      <template #default="scope">
            <span v-for="(item,i) in scope.row.metricsDef.metricsTypes" :key="`${scope.$index}_${item}`">
              {{ item.typeName }}<span v-if="scope.row.metricsTypes && i!==scope.row.metricsTypes.length-1">、</span>
            </span>
      </template>
    </el-table-column>
    <el-table-column label="指标名称" align="left" prop="metricsName" />
    <el-table-column label="指标编码" align="left" prop="metricsCode" />
    <el-table-column label="指标当前值" align="left" prop="dvalue" />
<!--    <el-table-column label="告警规则" align="left" prop="alarmRule" />-->
    <el-table-column label="更新时间" align="left" prop="updateTime" width="180">
      <template #default="scope">
        <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
      <template #default="scope">
        <el-button link type="primary" icon="DataLine" @click="metricsEcharts(scope.row)">指标趋势</el-button>
      </template>
    </el-table-column>
  </el-table>

  <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
  />

  <el-dialog title="趋势指标" v-model="openDialog" :width="1000" append-to-body >
    <echarts-info :objMetricsId="objMetricsId" />
  </el-dialog>
</template>
<script setup lang="ts">
import { listMetrics } from "@/api/obj/metrics";
import {ref, watchEffect} from "vue";
import echartsInfo from "./echartsInfo.vue"
const { proxy } = getCurrentInstance();
const props = defineProps(['rowId'])
const loading = ref(true);
const metricsList = ref([]);
const total = ref(0);
const openDialog = ref(false)
const objMetricsId = ref(null)
const queryParams = reactive({
  objId: props.rowId,
  pageNum: 1,
  pageSize: 10,
  metricsName:""
});
watchEffect(()=>{
  queryParams.objId = props.rowId
  getList()
})

/** 查询业务对象指标列表 */
function getList() {
  loading.value = true;
  listMetrics(queryParams).then(response => {
    metricsList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function metricsEcharts(row){
  openDialog.value = true
  objMetricsId.value = row.objMetricsId
}

</script>
<style scoped lang="scss">
</style>
