<template>
  <div class="achievement-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/achievement">科研成果</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">{{ achievement.achievementName }}</h1>
          <div class="detail-meta">
            <span v-if="achievement.achievementCategory" class="meta-item">
              <i class="el-icon-folder"></i>
              {{ achievement.achievementCategory }}
            </span>
            <span v-if="achievement.researchField" class="meta-item">
              <i class="el-icon-cpu"></i>
              {{ achievement.researchField }}
            </span>
            <span v-if="achievement.publishTime" class="meta-item">
              <i class="el-icon-date"></i>
              {{ achievement.publishTime }}
            </span>
            <span v-if="achievement.publisher" class="meta-item">
              <i class="el-icon-user"></i>
              {{ achievement.publisher }}
            </span>
          </div>
        </div>

        <div class="detail-body">
          <div class="detail-thumbnail" v-if="achievement.thumbnail">
            <img :src="achievement.thumbnail" :alt="achievement.achievementName" />
          </div>

          <div class="detail-content">
            <div class="content-section" v-if="achievement.introduction">
              <h3>简介</h3>
              <div class="content-text" v-html="achievement.introduction"></div>
            </div>

            <div class="content-section" v-if="achievement.details">
              <h3>详情</h3>
              <div class="content-text" v-html="achievement.details"></div>
            </div>

            <div class="content-section" v-if="achievement.researchUnit">
              <h3>研究单位</h3>
              <p>{{ achievement.researchUnit }}</p>
            </div>

            <div class="content-section" v-if="achievement.researchers">
              <h3>研究人员</h3>
              <p>{{ achievement.researchers }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAchievementDetail } from '@/api/portal/achievement'

export default {
  name: 'AchievementDetail',
  data() {
    return {
      achievement: {},
      loading: false
    }
  },
  created() {
    const id = this.$route.query.id
    if (id) {
      this.fetchAchievementDetail(id)
    } else {
      this.$message.error('缺少成果ID')
      this.goBack()
    }
  },
  methods: {
    async fetchAchievementDetail(id) {
      this.loading = true
      try {
        const response = await getAchievementDetail(id)
        if (response.code === 200) {
          this.achievement = 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>
.achievement-detail-page {
  width: 100%;
  min-height: calc(100vh - 200px);
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding-bottom: 20px;
}

/* 面包屑导航 */
.breadcrumb-container {
  // background: #f5f7fa;
  padding: 20px 0;
  // border-bottom: 1px solid #e0e0e0;
}

.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>
