<template>
  <div class="app-container">
    <div class="main-right-box">
      <div class="main-search-box">
        <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" size="small">
          <el-form-item label="机构名称">
            <org-tree
              v-model="queryParams.orgId"
              @defaultKey="getDefaultKey"
              @checkChange="changeCheckBox"
              @click="handleNodeClick"
              :showCheckSub="false"
              ref="orgTree"
            ></org-tree>
          </el-form-item>
          <el-form-item label="监控主机" prop="reasons">
            <el-input
              v-model="queryParams.reasons"
              clearable
              placeholder="请输入关键字"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="摄像头" prop="type">
            <el-select v-model="queryParams.type" clearable placeholder="请选择介绍信类型">
              <el-option
                v-for="dict in dict.type.out_in_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="报警状态" prop="approveStatus">
            <el-select v-model="queryParams.approveStatus" clearable placeholder="请选择审批状态">
              <el-option
                v-for="dict in dict.type.out_in_approve_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="告警类型" prop="approveStatus">
            <el-select v-model="queryParams.approveStatus" clearable placeholder="请选择审批状态">
              <el-option
                v-for="dict in dict.type.out_in_approve_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="报警/恢复时间">
            <DataRangePicker
              style="width: 240px"
              v-model="queryParams.dateRange"
              key="daterange"
              type="daterange"
              :editable="false"
              :clearable="false"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            />
          </el-form-item>
        </el-form>

        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button icon="el-icon-refresh" size="mini" type="primary" @click="resetQuery">重置</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </div>
      <el-table v-loading="loading" :data="dataList" border height="646" size="small">
        <el-table-column label="序号" type="index" align="center" width="70"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="center" label="组织机构" prop="type" width="180"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="center" label="监控主机" prop="reasons" width="140"/>
        <el-table-column :show-overflow-tooltip="true" align="center" label="摄像头" prop="letterNo" width="140"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="center" label="通道号" prop="letterNo" width="140"></el-table-column>
        <el-table-column align="center" label="报警/恢复时间" prop="letterNo" width="180"></el-table-column>
        <el-table-column align="center" label="信号丢失" prop="letterNo" width="100"></el-table-column>
        <el-table-column align="center" label="遮挡" prop="letterNo" ></el-table-column>
        <el-table-column align="center" label="亮度" prop="letterNo" ></el-table-column>
        <el-table-column align="center" label="偏色" prop="letterNo" ></el-table-column>
        <el-table-column align="center" label="雪花" prop="letterNo" ></el-table-column>
        <el-table-column align="center" label="条纹" prop="letterNo" ></el-table-column>
        <el-table-column align="center" label="对比度" prop="letterNo" ></el-table-column>
        <el-table-column align="center" label="模糊" prop="letterNo" ></el-table-column>
        <el-table-column label="操作" align="center"  width="120" >
          <template slot-scope="r">
            <el-button type="text" @click="openAlarmHistoryDialog(r.row)">告警历史记录</el-button>
          </template>
        </el-table-column>

      </el-table>

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

    </div>
<!--  请  -->
    <dialog-alarm-history ref="alarmHistoryDialog"></dialog-alarm-history>

  </div>
</template>

<script>
import OrgTree from "@/components/orgTree/orgQuerySelector.vue";
import DataRangePicker from "@/components/dateTime/daterange.picker.vue";
import DialogAlarmHistory from "./dialog.alarm.history";
import {getLetterApproveList} from "@/api/core/letter";
import dayjs from 'dayjs';
export default {
  components: {DataRangePicker, OrgTree,DialogAlarmHistory },
  dicts: ['letter_status', 'out_in_type', 'out_in_approve_status'],
  data() {
    return {
      loading:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reasons: null,
        type: null,
        approveStatus: null,
        orgId: this.$store.getters.orgId,
      },
      dataList:[],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    dayjs,

    openAlarmHistoryDialog(row) {
      this.$refs.alarmHistoryDialog.show(row);
    },
    getDefaultKey(key) {
      this.queryParams.orgId = key;
      this.getList();
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.orgId = data.id;
      this.handleQuery();
    },
    /** 下穿状态改变*/
    changeCheckBox() {
      this.queryParams.checkSub = !this.queryParams.checkSub;
      this.getList();
    },

    /** 查询介绍信列表 */
    getList() {
      this.loading = true;
      getLetterApproveList(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
