<template>
  <el-dialog
    :visible.sync="visible"
    v-bind="modalOptions"
  >
    <el-form
      ref="formData"
      :model="formData"
      size="mini"
      label-position="left"
      label-suffix=":"
      label-width="200px"
    >
      <!-- 定时任务信息 -->
      <el-form-item label="ID" prop="jobId">
        {{ formData.jobId || '--' }}
      </el-form-item>
      <el-form-item label="定时器名称" prop="jobName">
        {{ formData.jobName || '--' }}
      </el-form-item>
      <el-form-item label="spring bean 名称" prop="beanName">
        {{ formData.beanName || '--' }}
      </el-form-item>
      <el-form-item label="方法名" prop="methodName">
        {{ formData.methodName || '--' }}
      </el-form-item>
      <el-form-item label="参数" prop="params">
        {{ formData.params || '--' }}
      </el-form-item>
      <el-form-item label="cron表达式" prop="cronExpression">
        {{ formData.cronExpression || '--' }}
      </el-form-item>
      <el-form-item label="任务状态" prop="status">
        <span v-if="formData.status === 0">正常</span>
        <span v-else-if="formData.status === 1">暂停</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="任务类型" prop="taskType">
        {{ formData.taskType || '--' }}
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        {{ formData.remark || '--' }}
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        {{ formData.createTime || '--' }}
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { getIdQuartzJob } from '@/api/timedTasksManagement/timedTasksList'

export default {
  name: 'DetailModal',
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '800px',
        title: '查看定时任务详情'
      },
      visible: false,
      formData: {
        jobId: '',
        jobName: '',
        beanName: '',
        methodName: '',
        params: '',
        cronExpression: '',
        status: '',
        taskType: '',
        remark: '',
        createTime: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      if (params.jobId) {
        this.getInfo(params.jobId)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await getIdQuartzJob({ id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
          jobId: res.data.jobId || '',
          jobName: res.data.jobName || '',
          beanName: res.data.beanName || '',
          methodName: res.data.methodName || '',
          params: res.data.params || '',
          cronExpression: res.data.cronExpression || '',
          status: res.data.status,
          taskType: res.data.taskType || '',
          remark: res.data.remark || '',
          createTime: res.data.createTime || ''
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

