<template>
<div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="0">
      <el-form-item label="" style="width: 308px;margin-right:10px">
        <el-date-picker
            v-model="daterangeAlarmTime"
            value-format="YYYY-MM-DD"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="recordList" border>
      <el-table-column label="告警ID" align="center" prop="modelId" width="80"/>
      <el-table-column label="业务模型" align="center" prop="modelName"/>
      <el-table-column label="最近1小时系统压力值" align="center" prop="access"/>
      <el-table-column label="告警数量" align="center" prop="num" />
      <el-table-column label="操作" align="center" prop="alarmTime" width="180">
        <template #default="scope">
          <el-button type="text" plain icon="Position" @click="handleDetails(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"
    />
  </div>
</template>

<script setup name="Record">
import {getBizAccess} from "@/api/alarm/record";
import {useRouter} from "vue-router";

const {proxy} = getCurrentInstance();
const {alarm_level} = proxy.useDict('alarm_level');

const recordList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangeAlarmTime = ref([]);
const router = useRouter();

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 20,
  },
});

function handleDetails(row){
  console.log(row,router)
}

const {queryParams, form} = toRefs(data);

/** 查询告警记录列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangeAlarmTime && '' != daterangeAlarmTime) {
    queryParams.value.params["start"] = daterangeAlarmTime.value[0];
    queryParams.value.params["end"] = daterangeAlarmTime.value[1];
  }
  getBizAccess(queryParams.value).then(response => {
    recordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeAlarmTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
