<template>
  <div>
    <el-form
      class="search-form"
      :model="form"
      ref="form"
      label-width="80px"
      :inline="true"
      size="mini"
    >
      <el-form-item label="基站名称">
        <el-select v-model="form.siteId" placeholder="请选择基站名称" clearable>
          <el-option
            v-for="item in siteList"
            :key="item.id"
            :label="item.siteName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="告警对象">
        <el-input
          v-model="form.alarmTargetName"
          clearable
          placeholder="请输入网元设备"
        ></el-input>
      </el-form-item>
      <el-form-item label="告警级别">
        <el-select
          v-model="form.alarmLevelName"
          placeholder="请选择告警级别"
          clearable
        >
          <el-option
            v-for="(val, key) in alarmLeval"
            :key="key"
            :label="val"
            :value="val"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="告警类型">
        <el-select
          v-model="form.alarmType"
          placeholder="请选择告警类型"
          clearable
        >
          <el-option
            v-for="(val, key) in alarmType"
            :key="key"
            :label="val"
            :value="key"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="告警产生时间" label-width="110px">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="toSearch">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { commonQuery } from "@/views/history/api";
import { alarmLeval, alarmType } from "@/const";

export default {
  name: "search",
  data() {
    return {
      siteList: [],
      form: formInit(),
      alarmLeval,
      alarmType,
      dateRange: [],
    };
  },
  mounted() {
    this.getInit();
  },
  methods: {
    toSearch() {
      this.form.startUploadTime = this.dateRange[0];
      this.form.endUploadTime = this.dateRange[1];
      this.$emit("search", this.form);
    },
    reset() {
      this.form = formInit();
      this.dateRange = []
      this.$emit("search");
    },
    getInit() {
      commonQuery().then((res) => {
        this.siteList = res.siteList || [];
      });
    },
  },
};

function formInit() {
  return {
    siteId: null,
    alarmTargetName: "",
    alarmLevelName: null,
  };
}
</script>
<style scoped lang="scss">
.w200 {
  width: 200px;
}
.search-form {
  padding: 10px;
  background-color: #eaf1fe;
  margin-bottom: 20px;
  border-radius: 8px;
  .el-form-item--mini.el-form-item,
  .el-form-item--small.el-form-item {
    margin-bottom: 0;
  }
}
</style>