<template>
  <el-dialog
    v-model="props.visible"
    title="执行日志详情"
    width="750"
    :close-on-click-modal="false"
    :before-close="dialogClose"
  >
    <el-descriptions class="margin-top" :column="2" border>
      <el-descriptions-item label="任务名称" label-class-name="des-width">
        {{ formData.jobName }}
      </el-descriptions-item>
      <el-descriptions-item label="任务组名" label-class-name="des-width">
        {{ formData.jobGroup }}
      </el-descriptions-item>
      <el-descriptions-item label="任务触发器">
        {{ formData.jobTrigger }}
      </el-descriptions-item>
      <el-descriptions-item label="任务日志信息">
        {{ formData.jobMessage }}
      </el-descriptions-item>
      <el-descriptions-item label="执行表达式">
        {{ formData.cronExpression }}
      </el-descriptions-item>
      <el-descriptions-item label="执行状态">
        <el-tag :type="formData.status ? 'danger' : 'success'">{{
          formData.status ? '异常' : '正常'
        }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="任务开始时间">
        {{ formData.startTime }}
      </el-descriptions-item>
      <el-descriptions-item label="任务结束时间">
        {{ formData.endTime }}
      </el-descriptions-item>
      <el-descriptions-item label="执行时间">
        {{ formData.createTime }}
      </el-descriptions-item>
      <el-descriptions-item label="执行耗时"> {{ formData.consumeTime }}ms </el-descriptions-item>
      <el-descriptions-item label="执行异常信息" :span="3">
        {{ formData.exceptionInfo }}
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogClose">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
  import { getJobLogDetail } from '@/api/monitor/job';
  import { onMounted, ref } from 'vue';

  const emit = defineEmits(['success', 'update:visible']);
  const formData = ref({});

  /**
   * 定义接收的参数
   */
  const props = defineProps({
    visible: {
      type: Boolean,
      required: true,
      default: false,
    },
    logId: {
      type: Number,
      required: true,
      default: 0,
    },
  });

  /**
   * 关闭窗体
   */
  const dialogClose = () => {
    emit('update:visible', false);
  };

  /**
   * 设置表单数据
   */
  const setFormData = async () => {
    const data = await getJobLogDetail(props.logId);
    formData.value = data;
  };

  /**
   * 钩子函数
   */
  onMounted(() => {
    if (props.logId) {
      setFormData();
    }
  });
</script>
<style lang="scss" scoped>
  :deep(.des-width) {
    width: 120px;
  }
  :deep(.el-descriptions__body .el-descriptions__table .el-descriptions__cell) {
    word-break: break-all;
  }
</style>
