<template>
  <basicModal @register="modalRegister" ref="modalRef" class="basicModal basicFormModal">
    <template #default>
      <n-descriptions
        class="margin-top"
        :column="2"
        bordered
        :labelStyle="{ width: '120px' }"
        label-placement="left"
      >
        <n-descriptions-item label="文件名称:"
          ><a :href="formData.filePath" target="_blank">{{
            formData.originalName
          }}</a></n-descriptions-item
        >
        <n-descriptions-item label="文件类型:">{{ formData.fileType }}</n-descriptions-item>
        <n-descriptions-item label="文件大小:">{{ formData.fileSize }}B</n-descriptions-item>
        <n-descriptions-item label="请求耗时:">{{ formData.consumeTime }}s</n-descriptions-item>
        <n-descriptions-item label="业务类型:">{{
          formData.bizType ? (formData.bizType == 1 ? '订单' : '其他') : ''
        }}</n-descriptions-item>
        <n-descriptions-item label="业务ID:">{{ formData.bizId }}</n-descriptions-item>
        <n-descriptions-item label="业务内容" :span="3">
          {{ formData.bizContent }}
        </n-descriptions-item>
        <n-descriptions-item label="请求状态" :span="3">
          {{ formData.status ? '失败' : '成功' }}
        </n-descriptions-item>
        <n-descriptions-item label="请求参数" :span="3">
          {{ formData.param }}
        </n-descriptions-item>
        <n-descriptions-item label="返回结果" :span="3">
          {{ formData.result }}
        </n-descriptions-item>
        <n-descriptions-item label="错误描述" :span="3">
          {{ formData.error }}
        </n-descriptions-item>
      </n-descriptions>
    </template>
    <template #action>
      <n-button @click="handleClose">取消</n-button>
    </template>
  </basicModal>
</template>
<script lang="ts" setup>
  import { getFileLogDetail } from '@/api/logger/fileLog';
  import { onMounted, ref } from 'vue';
  import { useModal } from '@/components/Modal';

  /**
   * 定义参数变量
   */
  const emit = defineEmits(['success', 'update:visible']);
  const formData = ref({});
  const [modalRegister, { openModal }] = useModal({
    title: '文件日志详情',
    subBtuText: '确定',
    width: 800,
  });

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

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

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

  /**
   * 钩子函数
   */
  onMounted(() => {
    if (props.fileLogId) {
      setFormData();
    }
  });
  //导出方法
  defineExpose({
    openModal,
  });
</script>
<style lang="less" scoped>
  :deep(.n-descriptions__body .n-descriptions__table .n-descriptions__cell) {
    word-break: break-all;
  }
</style>
