<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="list" border size="small">
      <el-table-column label="文件名称" prop="fileName" show-overflow-tooltip>
        <template #default="{row}">
          <el-link type="primary" @click="showDetail(row)">{{ row.fileName || row.FILE_NAME }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="文号" prop="wh" width="200">
        <template #default="{row}">{{ row.wh || row.WH }}</template>
      </el-table-column>
      <el-table-column label="出台时间" width="140">
        <template #default="{row}">{{ fmtDate(row.startDate || row.START_DATE) }}</template>
      </el-table-column>
    </el-table>

    <!-- 文件详情弹窗 -->
    <el-dialog v-model="detailVisible" :title="detailItem?.fileName || detailItem?.wpName || detailItem?.sysName" width="700px">
      <iframe-view :url="detailItem?.url" style="height: 79vh;"></iframe-view>
    </el-dialog>
  </div>
</template>

<script setup>
import {onMounted, ref} from 'vue'
import {listFile} from '@/api/hzz/rule'
import IframeView from "@/views/hlgl/IframeView.vue";

const loading = ref(false)
const list = ref([])
const detailVisible = ref(false)
const detailItem = ref(null)

const showDetail = (item) => {
  detailVisible.value = true
  detailItem.value = item
}

const fmtDate = (d) => d ? String(d).substring(0, 10) : '-'

onMounted(async () => {
  loading.value = true
  try {
    // 默认查询太湖流域考核文件
    const res = await listFile({types: 'xgwj', pageNum: 1, pageSize: 500})
    list.value = res.rows || []
  } catch { /* 接口可能未就绪 */
  } finally {
    loading.value = false
  }
})
</script>
