<template>
  <div>
    <el-dialog
      :title="title + '日志'"
      :visible.sync="showFormDia"
      :before-close="handleClose"
      width="65%"
    >
      <el-form ref="formInfo" :model="params" label-width="150px">
        <el-row>
          <!-- <el-col :span="11">
            <el-form-item label="任务名称：" prop="taskName">
              <el-input
                size="small"
                readonly
                v-model="params.taskName"
              ></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="11">
            <el-form-item label="任务编号：" prop="taskId">
              <el-input
                size="small"
                :readonly="true"
                v-model="params.taskId"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="调度编号：" prop="sysJoblogId">
              <el-input
                size="small"
                style="width: 100%"
                :readonly="true"
                v-model="params.sysJoblogId"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item inline="true" label="任务开始时间：" prop="startTime">
              <el-input
                size="small"
                :readonly="true"
                v-model="params.startTime"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="任务结束时间：" prop="endTime">
              <el-input
                size="small"
                :readonly="true"
                v-model="params.endTime"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="任务结果：" prop="result">
              <el-input
                size="small"
                :readonly="true"
                v-model="params.result"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="任务状态：" prop="status">
              <el-input size="small" :readonly="true" v-model="params.status">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-form-item label="任务说明：" prop="taskMemo">
              <el-input
                type="textarea"
                :rows="4"
                v-model="params.taskMemo"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'FormDialog',
  props: {
    showFormDia: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    pId: {
      type: String,
      default: ''
    },
    tableData: {
      type: Array,
      default: ''
    },
    taskMemo: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      params: {
        endTime: null, //任务结束时间
        result: null, //任务结果
        startTime: null, //任务开始时间
        status: null, //任务状态
        sysJoblogId: null, //调度id
        taskId: null, //任务id
        taskMemo: null
      }
    }
  },
  created() {
    this.getDetailInfo()
  },
  methods: {
    handleClose() {
      this.params = {
        endTime: null, //任务结束时间
        result: null, //任务结果
        startTime: null, //任务开始时间
        status: null, //任务状态
        sysJoblogId: null, //调度id
        taskId: null //任务id
      }
      this.$emit('closeFormDiao')
    },
    getDetailInfo() {
      if (this.title === '查看') {
        this.tableData.forEach(ii => {
          if (this.pId === ii.id) {
            this.params.endTime = ii.endTime
            this.params.startTime = ii.startTime
            this.params.result = ii.result
            this.params.sysJoblogId = ii.sysJoblogId
            this.params.taskId = ii.taskId
            this.params.status = ii.status
            if (this.params.status === 0) {
              this.params.status = '失败'
            } else {
              this.params.status = '成功'
            }
          }
        })
      }
    },
    getRowKey(row) {
      return row.id
    }
  }
}
</script>

<style lang="scss" scoped></style>
