<template>
  <div class="app-container">
    <el-form :model="queryParams" :inline="true">
      <el-form-item label="行政区划编码">
        <el-input v-model="queryParams.adCode" placeholder="请输入行政区划编码" clearable style="width:180px" />
      </el-form-item>
      <el-form-item label="考核时间">
        <el-input v-model="queryParams.assTime" placeholder="yyyy-MM-dd" clearable style="width:180px" />
      </el-form-item>
      <el-form-item label="生效日期">
        <el-input v-model="queryParams.effDate" placeholder="yyyy-MM-dd" clearable style="width:180px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="20">
      <!-- 考核总分卡片 -->
      <el-col :span="24" style="margin-bottom:20px">
        <el-card shadow="hover">
          <template #header><span>考核总分</span></template>
          <el-table v-loading="scoreLoading" :data="scoreList" border size="small">
            <el-table-column label="行政区划编码" prop="AD_CODE" width="150" />
            <el-table-column label="行政区划名称" prop="AD_NAME" width="200" />
            <el-table-column label="总分" prop="SCORE" width="120" />
          </el-table>
        </el-card>
      </el-col>

      <!-- 考核方法与分数 -->
      <el-col :span="24" style="margin-bottom:20px">
        <el-card shadow="hover">
          <template #header><span>考核方法名称与分数</span></template>
          <el-table v-loading="methodLoading" :data="methodList" border size="small">
            <el-table-column label="行政区划编码" prop="AD_CODE" width="150" />
            <el-table-column label="行政区划名称" prop="AD_NAME" width="200" />
            <el-table-column label="考核方法" prop="MTH_NAME" :show-overflow-tooltip="true" />
            <el-table-column label="分数" prop="SCORE" width="100" />
            <el-table-column label="考核时间" prop="ASS_TIME" width="120" />
          </el-table>
        </el-card>
      </el-col>

      <!-- 考核文件 -->
      <el-col :span="24">
        <el-card shadow="hover">
          <template #header><span>考核相关文件</span></template>
          <el-table v-loading="fileLoading" :data="fileList" border size="small">
            <el-table-column label="考核名称" prop="ASS_NAME" :show-overflow-tooltip="true" />
            <el-table-column label="文件标题" prop="FILE_TITL" :show-overflow-tooltip="true" />
            <el-table-column label="提交单位" prop="ENTER_UNIT" width="160" />
            <el-table-column label="总分" prop="TOTAL_POINTS" width="100" />
            <el-table-column label="提交时间" prop="ENTER_TM" width="120" />
            <el-table-column label="附件" width="100">
              <template #default="scope">
                <el-link v-if="scope.row.FILE_PATH" :href="scope.row.FILE_PATH" target="_blank" type="primary">查看</el-link>
                <span v-else>-</span>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { getTotalScore, getMthNameAndScore, getMethodFile } from '@/api/hzz/assess'

const queryParams = ref({ adCode: '', assTime: '', effDate: '' })
const scoreLoading = ref(false)
const methodLoading = ref(false)
const fileLoading = ref(false)
const scoreList = ref([])
const methodList = ref([])
const fileList = ref([])

const handleQuery = async () => {
  const { adCode, assTime, effDate } = queryParams.value
  if (!adCode || !assTime || !effDate) return

  scoreLoading.value = true
  methodLoading.value = true
  fileLoading.value = true
  try {
    const [scoreRes, methodRes, fileRes] = await Promise.all([
      getTotalScore(adCode, assTime, effDate),
      getMthNameAndScore(adCode, assTime, effDate),
      getMethodFile(adCode, effDate)
    ])
    scoreList.value = scoreRes.data || []
    methodList.value = methodRes.data || []
    fileList.value = fileRes.data || []
  } finally {
    scoreLoading.value = false
    methodLoading.value = false
    fileLoading.value = false
  }
}
</script>
