<template>
  <div>
    <div class="nav-title">调度日志</div>
    <div class="search">
      <el-form
        class="search-form"
        :model="form"
        ref="form"
        :inline="true"
        size="mini"
      >
        <el-form-item label="执行器：">
          <el-select v-model="form.jobGroup" placeholder="请选择">
            <el-option
              v-for="item in groupList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="任务">
          <el-input
            v-model="form.jobDesc"
            placeholder="请输入任务描述"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="form.triggerStatus" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="时间">
          <el-input
            v-model="form.executorHandler"
            placeholder="请输入JobHandler"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="toSearch">查询</el-button>
          <el-button type="primary" @click="handleEdit()">新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        :data="tableData"
        style="width: 100%"
        :header-cell-style="{ background: '#EAF1FE', color: '#666666' }"
      >
        <el-table-column prop="jobId" label="任务ID" align="center" />
        <el-table-column prop="triggerTime" label="调度时间" align="center" />
        <el-table-column prop="triggerCode" label="调度结果" align="center">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.triggerCode === 200 ? 'success' : 'danger'"
              >{{ scope.row.triggerCode === 200 ? "成功" : "失败" }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="triggerMsg" label="调度备注" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="handleView(scope.row.triggerMsg)"
              >查看</el-button
            >
            <!-- <div v-html="scope.row.triggerMsg"></div> -->
          </template>
        </el-table-column>
        <el-table-column prop="handleTime" label="执行时间" align="center" />
        <el-table-column prop="handleCode" label="执行结果" align="center">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.handleCode === 200 ? 'success' : 'danger'"
              >{{ scope.row.handleCode === 200 ? "成功" : "失败" }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="handleMsg" label="执行备注" align="center" />
      </el-table>
    </div>
    <el-dialog
      title="告警详情"
      :visible.sync="centerDialogVisible"
      width="600px"
      center
    >
      <div v-html="dialogInfo"></div>
    </el-dialog>
  </div>
</template>

<script>
import { jobgroupList, joblogList } from "@/api/job.js";
export default {
  data() {
    return {
      tableData: [],
      dialogInfo: "",
      centerDialogVisible: false,
      form: {
        jobGroup: "",
      },
      groupList: [],
    };
  },
  mounted() {
    this.handleJobGroupList();
    this.handleJoblogList();
  },
  methods: {
    async handleJobGroupList() {
      let data = {
        start: 0,
        length: 999,
      };
      const queryParams = new URLSearchParams(data).toString();
      const res = await jobgroupList(queryParams);
      this.groupList = res.data;
      this.form.jobGroup = res.data[0].id;
    },
    handleView(e) {
      this.dialogInfo = e;
      this.centerDialogVisible = true;
    },
    async handleJoblogList() {
      let data = {
        jobGroup: 0,
        jobId: 0,
        logStatus: -1,
        filterTime: "2024-12-09 00:00:00 - 2025-01-15 23:59:59",
        start: 0,
        length: 10,
      };
      const queryParams = new URLSearchParams(data).toString();
      const res = await joblogList(queryParams);
      console.log(res);
      this.tableData = res.data;
    },
  },
};
</script>

<style lang="scss" scoped>
.nav-title {
  color: #02a7f0;
  font-size: 20px;
  position: relative;
  padding-left: 16px;
  font-weight: bold;
  line-height: 28px;
}
.nav-title::before {
  content: "";
  position: absolute;
  left: 0px;
  top: 1px;
  width: 5px;
  height: 100%;
  background-color: #02a7f0;
  border-radius: 4px;
}
.search {
  margin: 16px 0;
  .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>