<template>
  <div class="value-detail">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <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>
    </div>

    <!-- 白色背景内容区域 -->
    <div class="content-container" v-loading="loading">
      <!-- 标题 -->
      <div class="value-title">
        <h1>{{ valueDetail.title }}</h1>
      </div>

      <!-- 摘要 -->
      <div class="value-summary" v-if="valueDetail.summary">
        <p>{{ valueDetail.summary }}</p>
      </div>

      <!-- 详情内容 -->
      <div class="value-content" v-html="valueDetail.content"></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: {
    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 {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 40px 0;
}

/* 面包屑导航 */
.breadcrumb {
  max-width: 1390px;
  margin: 0 auto 30px;
  padding: 0 30px;
}

/* 内容容器 */
.content-container {
  max-width: 1390px;
  margin: 0 auto;
  padding: 40px 60px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* 标题样式 */
.value-title {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e0e0e0;

  h1 {
    font-size: 28px;
    font-weight: 700;
    color: #1e3c72;
    line-height: 1.4;
    margin: 0;
  }
}

/* 摘要样式 */
.value-summary {
  margin-bottom: 30px;
  padding: 20px;
  background: #f5f7fa;
  border-left: 4px solid #1e3c72;
  border-radius: 4px;

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

/* 内容样式 */
.value-content {
  line-height: 1.8;
  color: #333;
  font-size: 16px;

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

  :deep(p) {
    margin-bottom: 16px;
    line-height: 1.8;
  }

  :deep(img) {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 20px 0;
  }

  :deep(a) {
    color: #1e3c72;
    text-decoration: none;

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

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

  :deep(li) {
    margin-bottom: 8px;
  }
}

/* 响应式适配 */
@media (max-width: 768px) {
  .value-detail {
    padding: 20px 0;
  }

  .breadcrumb {
    padding: 0 20px;
    margin-bottom: 20px;
  }

  .content-container {
    padding: 20px;
    margin: 0 20px;
  }

  .value-title {
    h1 {
      font-size: 22px;
    }
  }
}
</style>
