<!-- 驾驶舱相似同类事件 -->
<template>
  <div class="L-ultimately-container">
    <header>
      驾驶舱相似同类事件
      <span class="title-span">解释：分析出与目标工单的属于同类型的相似事件。规则：返回相似度排名超过0.92的结果，最多返回10条。</span>
    </header>
    <div class="tabs">
      <el-tabs
        v-model="activeName"
        @tab-click="handleClick"
        style="color: #edeef0"
      >
        <el-tab-pane label="调用记录" name="first" />
        <el-tab-pane label="重训练" name="third" />
      </el-tabs>
    </div>
    <div class="container-info" id="L-size-main">
      <header id="L-header">
        <el-form :inline="true" :model="formInline" size="small" class="demo-form-inline">
          <el-form-item label="事件标题：">
            <el-input v-model="formInline.title" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="调用时间：">
            <!-- <el-date-picker
              class="ignoreElement"
              v-model="formInline.firstWarnTime"
              format="yyyy"
              value-format="yyyy"
              type="year"
              placeholder="选择年份">
            </el-date-picker> -->
            <el-date-picker
              v-model="formInline.time"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="请选择"
            >
            </el-date-picker>
          </el-form-item>
          
          <el-form-item>
            <el-button size="mini" @click="resetQuery('queryFrom')">重置</el-button>
            <el-button size="mini" type="primary" @click="handleQuery('queryFrom')">查询</el-button>
          </el-form-item>
        </el-form>
      </header>
      <section>
        <!--  :height="tabHeader" -->
        <el-table v-loading="loading" :data="tableData" :height="tabHeader">
          <el-table-column type="index" label="序号" width="100px" class-name="table-operation" align="center"/>
          <el-table-column label="事件标题" key="title" width="400px" prop="title" />
          <el-table-column label="调用时间" key="createTime" width="300px" prop="createTime" />
          <el-table-column label="关联事件数量" key="count" width="200px" prop="count" align="center" />
          <el-table-column label="操作" class-name="table-operation-anniu" align="center">
            <template slot-scope="scope">
              <div @click="audit(scope.row)" class="go-audit" v-if="activeName == 'first'">
                <img src="@/assets/images/audit.png" alt="">
                <span>审核</span>
              </div>
              <el-button v-else @click="audit(scope.row)" type="text" style="margin-right: 5px;" class="sqbtn sqbtn1">
                查看详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination 
          id="L-pagination"
          :total="total"
          :page="pagination.current"
          :limit="pagination.size"
          layout="total, prev, pager, next, jumper"
          @pagination="getPagination"
          :current-page.sync="pagination.current" 
        ></pagination>
      </section>
    </div>
    <relevancyEventAudit title="关联事件审核" ref="eventAudit" :auditStatus="auditStatus" @closeDialog="getList" />
  </div>
</template>
<script>
import { colonyEventPage } from "@/api/eventPage"
import relevancyEventAudit from '@/views/components/relevancyEventAudit.vue'
export default {
  components:{
    relevancyEventAudit,
  },
  data() {
    return {
      activeName: "first",
      active: 0,
      formInline:{
        title:"",
        time:[],
      },
      loading: false,
      tableData: [],
      tabHeader: null,
      total:0,
      pagination: {
        current: 1,
        size: 10,
        isReport:null,
      },
      auditStatus: 1,
    }
  },
  mounted(){
    this.getList();
    this.cancalDebounce();
    window.addEventListener('resize', this.cancalDebounce);
  },
  destroyed() {
    window.removeEventListener('resize', this.cancalDebounce);
  },
  methods:{
    // 切换tab
    handleClick(e) {
      if (this.activeName == "first") {
        this.pagination.isReport = null;
        this.auditStatus = 1;
        this.getList();
      } else if (this.activeName == "third") {
        this.pagination.isReport = 1;
        this.auditStatus = 2;
        this.getList();
      }
    },
    // 获取页码
    getPagination(pages) {
      this.pagination.current = pages.page;
      this.pagination.size = pages.limit;
      this.getList();
    },
    getList(){
      this.loading = true;
      colonyEventPage(this.pagination).then(res=>{
        this.tableData = res.data.records
        this.total = res.data.total
        this.loading = false;
      }).catch(err=>{
        this.tableData = [];
        this.loading = false;
      })
    },
    resetQuery(){
      this.formInline = {
        title:"",
        time:[],
      }
      this.pagination = {
        current: 1,
        size: 10,
        isReport: this.activeName == "first" ? null : this.activeName == "third" ? 1 : null,
      }
      this.getList();
    },
    handleQuery(){
      if(this.formInline.time.length > 0) {
        this.formInline.startTime = this.formInline.time[0]
        this.formInline.endTime = this.formInline.time[1]
      }
      this.pagination = {...this.pagination,...this.formInline}
      this.getList();
    },
    audit(item){
      this.$refs.eventAudit.open(item);
    },
    // 屏幕尺寸变化
    cancalDebounce(){
      const element = document.getElementById('L-size-main'); // 通过元素的 ID 获取元素
      const header = document.getElementById('L-header'); // 通过元素的 ID 获取元素
      const pagination = document.getElementById('L-pagination'); // 通过元素的 ID 获取元素
      const elementHeight = element.offsetHeight;
      const headerHeight = header.offsetHeight;
      const paginationtHeight = pagination.offsetHeight;
      this.tabHeader = elementHeight - headerHeight - paginationtHeight;
    }
  },
}
</script>
<style lang="scss" scoped>

</style>
