<template>
  <div class="progress-detail-page">
    <!-- 面包屑导航 -->
    <div class="breadcrumb-container">
      <div class="breadcrumb-wrapper">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item><a href="/portal">首页</a></el-breadcrumb-item>
          <el-breadcrumb-item><a href="/portal/progress">计划进展</a></el-breadcrumb-item>
          <el-breadcrumb-item>动态详情</el-breadcrumb-item>
        </el-breadcrumb>
        <el-button class="back-btn" icon="el-icon-arrow-left" size="small" @click="goBack">返回</el-button>
      </div>
    </div>

    <div class="page-container">
      <div class="detail-card" v-loading="loading">
        <div class="detail-header">
          <h1 class="detail-title">{{ progress.title }}</h1>
          <div class="detail-meta">
            <span v-if="progress.publishTime" class="meta-item">
              <i class="el-icon-date"></i>
              {{ progress.publishTime }}
            </span>
            <span v-if="progress.source" class="meta-item">
              <i class="el-icon-office-building"></i>
              {{ progress.source }}
            </span>
          </div>
        </div>

        <div class="detail-body">
          <div class="detail-thumbnail" v-if="progress.coverImage">
            <img :src="progress.coverImage" :alt="progress.title" />
          </div>

          <div class="detail-content">
            <div class="content-section" v-if="progress.summary">
              <h3>摘要</h3>
              <p>{{ progress.summary }}</p>
            </div>

            <div class="content-section" v-if="progress.contentCn">
              <h3>详情</h3>
              <div class="content-text" v-html="progress.contentCn"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getProgressDetail } from '@/api/portal/progress'

export default {
  name: 'ProgressDetail',
  data() {
    return {
      progress: {},
      loading: false
    }
  },
  created() {
    const id = this.$route.query.id
    if (id) {
      this.fetchProgressDetail(id)
    } else {
      this.$message.error('缺少动态ID')
      this.goBack()
    }
  },
  methods: {
    async fetchProgressDetail(id) {
      this.loading = true
      try {
        const response = await getProgressDetail(id)
        if (response.code === 200) {
          this.progress = response.data || {}
        } else {
          this.$message.error('获取动态详情失败')
        }
      } catch (error) {
        console.error('获取动态详情失败:', error)
        this.$message.error('获取动态详情失败')
      } finally {
        this.loading = false
      }
    },
    goBack() {
      this.$router.back()
    }
  }
}
</script>

<style lang="scss" scoped>
.progress-detail-page {
  width: 100%;
  min-height: calc(100vh - 200px);
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding-bottom: 20px;
}

/* 面包屑导航 */
.breadcrumb-container {
  padding: 20px 0;
}

.breadcrumb-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .back-btn {
    margin-left: 20px;
  }
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px;
}

.detail-card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.detail-header {
  padding: 40px 40px 30px;
  border-bottom: 1px solid #f0f0f0;

  .detail-title {
    font-size: 32px;
    font-weight: 700;
    color: #1e3c72;
    margin: 0 0 20px 0;
    line-height: 1.4;
  }

  .detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;

    .meta-item {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 14px;
      color: #666666;

      i {
        font-size: 16px;
        color: #2a5298;
      }
    }
  }
}

.detail-body {
  padding: 40px;
}

.detail-thumbnail {
  width: 100%;
  max-height: 500px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 40px;
  background: #f5f7fa;

  img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
}

.detail-content {
  .content-section {
    margin-bottom: 40px;

    &:last-child {
      margin-bottom: 0;
    }

    h3 {
      font-size: 20px;
      font-weight: 600;
      color: #1e3c72;
      margin: 0 0 20px 0;
      padding-bottom: 10px;
      border-bottom: 2px solid #2a5298;
    }

    .content-text {
      font-size: 15px;
      color: #333333;
      line-height: 1.8;
      text-align: justify;

      ::v-deep {
        p {
          margin-bottom: 15px;

          &:last-child {
            margin-bottom: 0;
          }
        }

        img {
          max-width: 100%;
          height: auto;
          border-radius: 8px;
          margin: 20px 0;
        }
      }
    }

    p {
      font-size: 15px;
      color: #333333;
      line-height: 1.8;
      margin: 0;
    }
  }
}

@media (max-width: 768px) {
  .detail-header {
    padding: 30px 20px;

    .detail-title {
      font-size: 24px;
    }
  }

  .detail-body {
    padding: 20px;
  }

  .detail-thumbnail {
    max-height: 300px;
  }
}
</style>
