<template>
  <LjDialogNew v-bind="$attrs" title="任务日志">
    <div class="task-log-detail flx-col">
      <el-descriptions :column="3" border>
        <el-descriptions-item label="任务类型">{{ props.task.task_type }}</el-descriptions-item>
        <el-descriptions-item label="状态">{{ formatStatus(props.task.status) }}</el-descriptions-item>
        <el-descriptions-item label="创建人">{{ props.task.create_emp }}</el-descriptions-item>
        <el-descriptions-item label="计划时间">{{ props.task.schedule_time }}</el-descriptions-item>
        <el-descriptions-item label="开始时间">{{ props.task.start_time }}</el-descriptions-item>
        <el-descriptions-item label="结束时间">{{ props.task.end_time }}</el-descriptions-item>
        <el-descriptions-item label="总数">{{ props.task.total_count }}</el-descriptions-item>
        <el-descriptions-item label="成功数">{{ props.task.success_count }}</el-descriptions-item>
        <el-descriptions-item label="失败数">{{ props.task.fail_count }}</el-descriptions-item>
        <el-descriptions-item label="日志信息" :span="3">{{ props.task.log_msg }}</el-descriptions-item>
      </el-descriptions>

      <LjVxeTable
        class="mt-12 flx-1"
        :columns="detailColumns"
        :request-api="getDetailData"
        :data-callback="dataCallback"
        :init-param="{ taskid: props.taskid }"
        :dwname="DwnameEnum.tasklogMx"
        :dsname="DwnameEnum.tasklogMx"
        :request-auto="true"
        :pagination="false"
        :tool-button="['refresh', 'setting', 'search', 'location']"
        :auto-load-layout="false"
        :if-search="false"
        :table-props="detailTableProps"
      />
    </div>
  </LjDialogNew>
</template>

<script setup lang="ts" name="tasklog_detailDialog">
import LjDialogNew from "@/components/LjDialog/index-new.vue";
import type { TaskLog } from "@/api/interface/index";
import { DwnameEnum } from "@/enums/dwnameEnum";
import { ElMessage } from "element-plus";
import { useHooks } from "../hooks";
import { useI18n } from "vue-i18n";

const { t } = useI18n();
defineOptions({
  inheritAttrs: false
});

const props = withDefaults(
  defineProps<{
    task?: Partial<TaskLog.TaskLogItem>;
    taskid?: number;
  }>(),
  {
    task: () => ({})
  }
);

const { detailColumns, statusOptions, getDetailData, dataCallback } = useHooks(t);

const detailTableProps = {
  height: 420
};

const formatStatus = (status?: number) => {
  return statusOptions.find(item => item.value === status)?.label ?? "";
};
</script>

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