<template>
  <el-row :gutter="20">
    <el-col :span="24">
      <el-input v-model="params.metricsName" placeholder="请输入指标名称" style="width: 200px;margin-right: 10px" size="small"/>
      <el-input v-model="params.objName" placeholder="请输入对象名称" style="width: 200px;margin-right: 10px" size="small" />
      <el-button type="primary" icon="Search" @click="getAnalysis" size="small">搜索</el-button>
    </el-col>
  </el-row>
  <el-table v-loading="loading" :data="analysisList" border width="100%" size="small" style="margin-top:10px">
    <el-table-column label="#" type="index" width="80" align="center"/>
    <el-table-column label="指标名称" prop="metricsName"/>
    <el-table-column label="运行业务对象" prop="objName"/>
    <el-table-column label="分析时间" prop="analyseTime"/>
    <el-table-column label="分析结果">
      <template #default="scope">
        <el-tag v-if="scope.row.result=='趋势恶化'" type="danger">{{scope.row.result}}</el-tag>
        <el-tag v-else >{{scope.row.result}}</el-tag>
      </template>
    </el-table-column>
    <el-table-column label="操作" width="100">
      <template #default="scope">
        <el-button type="primary" link @click="checkAnalyse(scope.row)">查看</el-button>
      </template>
    </el-table-column>
  </el-table>
  <pagination
      style="margin-top:10px"
      v-show="total>0"
      layout="prev, pager, next"
      :total="total"
      :background="false"
      v-model:page="params.pageNum"
      v-model:limit="params.pageSize"
      @pagination="getAnalysis"
  />

  <el-dialog v-model="visible" title="分析结果" width="800">
    <now-analyse :rows="rows"/>
  </el-dialog>

</template>
<script setup lang="ts">
import {listAnalysis} from "@/api/risk/r3"
import {onMounted} from "vue";
import nowAnalyse from "./nowAnalyse.vue"
const params = ref({
  riskType:1,
  metricsName:"",
  objName:"",
  pageNum:1,
  pageSize:10
})
const visible = ref(false)
const analysisList = ref([])
const total = ref(0)
const loading = ref(true)
const rows = ref({})

onMounted(()=>{
  getAnalysis()
})

async function getAnalysis(){
  loading.value = true
  const res = await listAnalysis(params.value)
  analysisList.value = res.rows
  total.value = res.total
  loading.value = false
}

function checkAnalyse(row){
  rows.value = row
  visible.value = true
}


defineExpose({getAnalysis})

</script>
