<template>
  <Dialog v-model="dialogVisible" title="详情" width="80%">
    <div class="detail-container">
      <!-- 一行4个 -->
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="form-item">
            <div class="section-title">接口编码</div>
            <span>{{ detailData.infCode }}</span>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="form-item">
            <div class="section-title">接口名称</div>
            <span>{{ detailData.infName }}</span>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="form-item">
            <div class="section-title">调用结果</div>
            <span>{{ detailData.infResult === 0 ? '失败' : '成功' }}</span>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="form-item">
            <div class="section-title">请求时间</div>
            <span>{{ formatDate(detailData.infCallTime) }}</span>
          </div>
        </el-col>
      </el-row>

      <!-- 一行1个 -->
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="form-item">
            <div class="section-title">接口信息</div>
            <span class="wrap-text">{{ detailData.infInfo }}</span>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="form-item">
            <div class="section-title">请求参数</div>
            <span class="wrap-text">{{ detailData.infRequestParams }}</span>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="form-item">
            <div class="section-title">接口返回信息</div>
            <span class="wrap-text">{{ detailData.infResponse }}</span>
          </div>
        </el-col>
      </el-row>
    </div>
  </Dialog>
</template>
<script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import * as LoginLogApi from '@/api/system/loginLog'

defineOptions({ name: 'SystemLoginLogDetail' })

const dialogVisible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({} as any) // 详情数据

/** 打开弹窗 */
const open = async (data: any) => {
  dialogVisible.value = true
  // 设置数据
  detailLoading.value = true
  try {
    // 调用接口获取详情
    const response = await LoginLogApi.getThirdPartyCallLogDetail({ id: data.id })
    console.log('response', response)
    detailData.value = response
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<style scoped>
.wrap-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}
.form-item {
  margin-bottom: 15px;
}
</style>
