<template>
  <el-dialog
    v-model="props.visible"
    title="文件日志详情"
    width="750"
    :close-on-click-modal="false"
    :before-close="dialogClose"
  >
    <el-descriptions column="2" border>
      <el-descriptions-item label="文件名称:" label-class-name="des-width"
        ><a :href="formData.filePath" target="_blank">{{
          formData.originalName
        }}</a></el-descriptions-item
      >
      <el-descriptions-item label="文件类型:" label-class-name="des-width">{{
        formData.fileType
      }}</el-descriptions-item>
      <el-descriptions-item label="文件大小:">{{ formData.fileSize }}B</el-descriptions-item>
      <el-descriptions-item label="请求耗时:">{{ formData.consumeTime }}ms</el-descriptions-item>
      <el-descriptions-item label="业务类型:">{{
        formData.bizType ? (formData.bizType == 1 ? '订单' : '其他') : ''
      }}</el-descriptions-item>
      <el-descriptions-item label="业务ID:">{{ formData.bizId }}</el-descriptions-item>
    </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
      <el-descriptions-item label="业务内容" label-class-name="des-width">
        {{ formData.bizContent }}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
      <el-descriptions-item label="请求状态" label-class-name="des-width">
        {{ formData.status ? '失败' : '成功' }}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
      <el-descriptions-item label="请求参数" label-class-name="des-width">
        {{ formData.param }}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
      <el-descriptions-item label="返回结果" label-class-name="des-width">
        {{ formData.result }}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
      <el-descriptions-item label="错误描述" label-class-name="des-width">
        {{ formData.error }}
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogClose">关闭</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
  import { getFileLogDetail } from '@/api/logger/fileLog';
  import { onMounted, ref } from 'vue';

  const emit = defineEmits(['success', 'update:visible']);
  const formData = ref({});

  /**
   * 定义接收的参数
   */
  const props = defineProps({
    visible: {
      type: Boolean,
      required: true,
      default: false,
    },
    fileId: {
      type: Number,
      required: true,
      default: 0,
    },
  });

  /**
   * 关闭窗体
   */
  const dialogClose = () => {
    emit('update:visible', false);
  };

  /**
   * 设置表单数据
   */
  const setFormData = async () => {
    const data = await getFileLogDetail(props.fileId);
    formData.value = data;
  };

  /**
   * 钩子函数
   */
  onMounted(() => {
    if (props.fileId) {
      setFormData();
    }
  });
</script>
<style lang="scss" scoped>
  :deep(.des-width) {
    width: 120px;
  }
  :deep(.el-descriptions__body .el-descriptions__table .el-descriptions__cell) {
    word-break: break-all;
  }
</style>
