<template>
  <div class="consultation-page">
    <div class="page-header">
      <h1 class="page-title">决策咨询</h1>
      <p class="page-desc">提供市县决策、前沿观察、行业资讯等决策咨询服务</p>
    </div>

    <!-- 分类标签 -->
    <div class="category-tabs">
      <a-radio-group v-model:value="activeType" button-style="solid" @change="handleTypeChange">
        <a-radio-button value="">全部</a-radio-button>
        <a-radio-button value="city">市县决策</a-radio-button>
        <a-radio-button value="frontier">前沿观察</a-radio-button>
        <a-radio-button value="industry">行业资讯</a-radio-button>
        <a-radio-button value="enterprise">企业动态</a-radio-button>
        <a-radio-button value="research">研究热点</a-radio-button>
        <a-radio-button value="academic">学术活动</a-radio-button>
        <a-radio-button value="other">其他汇编</a-radio-button>
      </a-radio-group>
    </div>

    <!-- 文章列表 -->
    <div class="article-list">
      <div v-for="article in articles" :key="article.id" class="article-item" @click="handleView(article)">
        <div class="article-content">
          <h3 class="article-title">{{ article.title }}</h3>
          <p class="article-overview">{{ article.overview }}</p>
          <div class="article-meta">
            <span class="meta-item">{{ article.source }}</span>
            <span class="meta-item">{{ article.publishTime }}</span>
          </div>
        </div>
      </div>

      <div v-if="loading" class="loading-placeholder">
        <a-spin size="large" />
      </div>

      <div v-if="!loading && articles.length === 0" class="empty-placeholder">
        <a-empty description="暂无文章" />
      </div>
    </div>

    <!-- 分页 -->
    <div class="pagination-wrap" v-if="total > pageSize">
      <a-pagination
        v-model:current="currentPage"
        :total="total"
        :page-size="pageSize"
        @change="handlePageChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { message } from 'ant-design-vue'

useHead({ title: '决策咨询 - 决策咨询网' })

const route = useRoute()
const router = useRouter()

const activeType = ref((route.query.type as string) || '')
const currentPage = ref(1)
const pageSize = ref(12)
const total = ref(0)
const loading = ref(false)
const articles = ref<any[]>([])

async function loadArticles() {
  loading.value = true
  try {
    // TODO: 接入实际API
  } catch (e: any) {
    message.error('加载失败')
  } finally {
    loading.value = false
  }
}

function handleTypeChange() {
  currentPage.value = 1
  loadArticles()
}

function handlePageChange(page: number) {
  currentPage.value = page
  loadArticles()
}

function handleView(article: any) {
  router.push(`/consultation/${article.id}`)
}

watch(() => route.query.type, (newType) => {
  activeType.value = (newType as string) || ''
  loadArticles()
})

onMounted(() => {
  loadArticles()
})
</script>

<style scoped>
.consultation-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  color: #1f2937;
  margin: 0 0 12px;
}

.page-desc {
  font-size: 16px;
  color: #6b7280;
  margin: 0;
}

.category-tabs {
  margin-bottom: 32px;
  text-align: center;
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.article-item {
  padding: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: all 0.2s;
}

.article-item:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.article-title {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 8px;
}

.article-overview {
  font-size: 14px;
  color: #6b7280;
  margin: 0 0 12px;
  line-height: 1.6;
}

.article-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #9ca3af;
}

.loading-placeholder,
.empty-placeholder {
  padding: 60px 0;
  text-align: center;
}

.pagination-wrap {
  margin-top: 40px;
  text-align: center;
}
</style>
