<template>
  <div class="value-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>核心价值与作用</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">{{ valueDetail.title }}</h1>
        </div>

        <!-- 详情内容 -->
        <div class="detail-body">
          <!-- 摘要 -->
          <div class="content-section" v-if="valueDetail.summary">
            <h3>摘要</h3>
            <div class="summary-box">
              <p>{{ valueDetail.summary }}</p>
            </div>
          </div>

          <!-- 内容 -->
          <div class="content-section" v-if="valueDetail.content">
            <h3>详情</h3>
            <div class="content-text" v-html="valueDetail.content"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getValueDetail } from '@/api/portal/home'

export default {
  name: 'ValueDetail',
  data() {
    return {
      loading: true,
      valueDetail: {
        title: '',
        summary: '',
        content: ''
      }
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    goBack() {
      this.$router.back()
    },
    async getDetail() {
      this.loading = true
      try {
        const { id } = this.$route.query
        if (!id) {
          this.$message.error('缺少价值ID')
          this.loading = false
          return
        }
        
        console.log('获取价值详情，ID:', id)
        
        const response = await getValueDetail(id)
        console.log('API响应:', response)
        
        if (response.code === 200 && response.data) {
          this.valueDetail = response.data
          console.log('价值详情数据:', this.valueDetail)
        } else {
          console.error('API响应格式错误:', response)
          this.$message.error('获取价值详情失败：响应格式错误')
        }
      } catch (error) {
        console.error('获取价值详情失败:', error)
        this.$message.error('获取价值详情失败：网络错误')
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.value-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;
    line-height: 1.4;
  }
}

.detail-body {
  padding: 40px;
}

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

.summary-box {
  padding: 20px;
  background: #f5f7fa;
  border-left: 4px solid #2a5298;
  border-radius: 4px;

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

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

  ::v-deep {
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      color: #1e3c72;
      margin-top: 24px;
      margin-bottom: 16px;
    }

    p {
      margin-bottom: 15px;

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

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

    a {
      color: #2a5298;
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    }

    ul,
    ol {
      margin-left: 24px;
      margin-bottom: 16px;
    }

    li {
      margin-bottom: 8px;
    }
  }
}

@media (max-width: 768px) {
  .breadcrumb-wrapper {
    padding: 0 20px;
  }

  .page-container {
    padding: 20px;
  }

  .detail-header {
    padding: 30px 20px;

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

  .detail-body {
    padding: 20px;
  }

  .content-section {
    margin-bottom: 30px;

    h3 {
      font-size: 18px;
    }
  }
}
</style>
