<script setup lang="ts">
import { computed } from 'vue';
import type { SelectOption } from 'naive-ui';

defineOptions({
  name: 'JobOperateView'
});

const visible = defineModel<boolean>('visible', { default: false });
const props = withDefaults(
  defineProps<{
    rowData: Api.SystemManage.JobLog | null;
    statusOptions?: Api.SystemManage.DictInfo[];
    jobGroupOptions: Array<SelectOption>;
  }>(),
  {
    statusOptions: () => []
  }
);

const filterJobGroup = computed(() => {
  const jobGroup = props.jobGroupOptions?.find(item => item.value === props.rowData?.jobGroup);
  return jobGroup?.label || '/';
});
const filterStatus = computed(() => {
  const status = props.statusOptions.find(item => item.dictValue === props.rowData?.status);
  return status?.dictLabel || '/';
});
</script>

<template>
  <NModal v-model:show="visible" title="调度日志详细：" preset="card" class="w-800px">
    <NScrollbar class="pr-20px">
      <NForm label-placement="left" require-mark-placement="left" :label-width="130">
        <NGrid responsive="screen" item-responsive>
          <NFormItemGi span="24 m:12" label="日志序号：" path="jobLogId">
            {{ rowData?.jobLogId }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="任务名称：" path="jobName">
            {{ rowData?.jobName }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="任务组名：" path="jobGroup">
            {{ filterJobGroup }}
          </NFormItemGi>
          <NFormItemGi span="24 m:12" label="执行时间：" path="createTime">
            {{ rowData?.createTime }}
          </NFormItemGi>
          <NFormItemGi span="24" label="调用方法：" path="invokeTarget">
            {{ rowData?.invokeTarget }}
          </NFormItemGi>
          <NFormItemGi span="24" label="日志信息：" path="jobMessage">
            {{ rowData?.jobMessage }}
          </NFormItemGi>
          <NFormItemGi span="24" label="执行状态：" path="status">
            {{ filterStatus }}
          </NFormItemGi>
          <NFormItemGi v-if="rowData?.status === '1'" span="24" label="异常信息：" path="exceptionInfo">
            {{ rowData?.exceptionInfo }}
          </NFormItemGi>
        </NGrid>
      </NForm>
    </NScrollbar>
    <template #footer>
      <NSpace justify="end" :size="16">
        <NButton @click="visible = false">关闭</NButton>
      </NSpace>
    </template>
  </NModal>
</template>

<style scoped></style>
