<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="业务类型" align="center" >
        <template #default="scope">
          <span v-if="biz_type.length">{{ biz_type.find(p=>p.value === scope.row.bizType ).label }}</span>
        </template>
      </el-table-column>
      <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 {getBizType} from "@/api/alarm/record";
import {useRouter} from "vue-router";

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

const recordList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");
const daterangeAlarmTime = ref([]);
const router = useRouter();

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

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

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

/** 查询告警记录列表 */
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];
  }
  getBizType(queryParams.value).then(response => {
    recordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

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

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


getList();
</script>
