<template>
  <a-modal v-model:visible="props.visible" title="日志详情" width="800px" @cancel="dialogClose">
    <a-descriptions :column="2" bordered :labelStyle="{ width: '160px' }">
      <a-descriptions-item label="任务名称:">{{ formData.jobName }}</a-descriptions-item>
      <a-descriptions-item label="任务组名:">{{ formData.jobGroup }}</a-descriptions-item>
      <a-descriptions-item label="任务触发器:">{{ formData.jobTrigger }}</a-descriptions-item>
      <a-descriptions-item label="任务信息:">{{ formData.jobMessage }}</a-descriptions-item>
      <a-descriptions-item label="cron执行表达式:">{{
        formData.cronExpression
      }}</a-descriptions-item>
      <a-descriptions-item label="任务开始时间:">{{ formData.startTime }}</a-descriptions-item>
      <a-descriptions-item label="任务结束时间:">{{ formData.endTime }}</a-descriptions-item>
    </a-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <a-button @click="dialogClose">关闭</a-button>
      </span>
    </template>
  </a-modal>
</template>
<script lang="ts" setup>
  import { getJobLogDetail } from '@/api/monitor/job';
  import { onMounted, reactive, shallowRef } from 'vue';

  /**
   * 定义表单参数
   */
  const formData = reactive({
    id: '',
    jobName: '',
    jobGroup: '',
    jobTrigger: '',
    jobMessage: '',
    cronExpression: '',
    startTime: '',
    endTime: '',
  });

  const emit = defineEmits(['update:visible']);

  /**
   * 定义接收的参数
   */
  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);
    for (const key in formData) {
      if (data[key] != null && data[key] != undefined) {
        //@ts-ignore
        formData[key] = data[key];
      }
    }
  };

  /**
   * 钩子函数
   */
  onMounted(() => {
    if (props.logId) {
      setFormData();
    }
  });
</script>
