<template>
  <div class="achievement-container">
    <div class="achievement-content">
      <!-- 左侧导航卡片 -->
      <div class="left-sidebar">
        <div class="sidebar-card">
          <div class="sidebar-header">
            <span class="title">科研成果</span>
          </div>
          <div class="sidebar-decorator">
            <div class="decorator-segment" style="background-color: #4B9F37"></div>
            <div class="decorator-segment" style="background-color: #C51A2D"></div>
            <div class="decorator-segment" style="background-color: #E37221"></div>
            <div class="decorator-segment" style="background-color: #0298DB"></div>
            <div class="decorator-segment" style="background-color: #F8C72E"></div>
            <div class="decorator-segment" style="background-color: #D0103A"></div>
            <div class="decorator-segment" style="background-color: #028542"></div>
            <div class="decorator-segment" style="background-color: #BF8B2E"></div>
            <div class="decorator-segment" style="background-color: #0B97D9"></div>
          </div>
          <div class="sidebar-menu">
            <div 
              class="menu-item"
              :class="{ active: currentMenu === 'overview' }"
              @click="handleMenuClick('overview')"
            >
              成果总体描述
            </div>
            <div 
              class="menu-item"
              :class="{ active: currentMenu === 'sdgsat1' }"
              @click="handleMenuClick('sdgsat1')"
            >
              SDGSAT-1 科学成果
            </div>
          </div>
        </div>
      </div>

      <!-- 右侧内容区域 -->
      <div class="right-content">
        <div class="content-card" v-loading="loading">
          <div class="content-header">
            <span class="title">{{ currentTitle }}</span>
          </div>
          <div class="content-body">
            <!-- 成果总体描述内容 -->
            <div v-if="currentMenu === 'overview'" class="overview-content">
              <div class="rich-text" v-html="overviewData.content || '<p>暂无内容</p>'"></div>
            </div>

            <!-- SDGSAT-1 科学成果内容 -->
            <div v-if="currentMenu === 'sdgsat1'" class="sdgsat1-content">
              <div class="sdgsat1-overview">
                <h3>SDGSAT-1 卫星科学成果</h3>
                <p class="overview-desc">
                  SDGSAT-1（可持续发展科学卫星1号）是全球首颗专门服务于联合国2030可持续发展目标的科学卫星，
                  于2021年11月5日成功发射。该卫星搭载了热红外、微光和多光谱成像仪，
                  为全球可持续发展目标监测提供了独特的数据支撑。
                </p>
              </div>

              <section class="sdgsat1-achievements-list">
                <div class="achievements-list">
                  <div class="achievement-card" v-for="(item, index) in sdgsat1AchievementList" :key="index">
                    <div class="achievement-header">
                      <h3 class="achievement-title">{{ item.achievementName }}</h3>
                    </div>
                    <div class="achievement-body">
                      <div class="achievement-left">
                        <div class="achievement-introduction" v-if="item.introduction">
                          <p>{{ item.introduction }}</p>
                        </div>
                        <div class="achievement-actions">
                          <el-button type="primary" size="small" @click="viewDetail(item.id)">
                            查看详情
                          </el-button>
                        </div>
                      </div>
                      <div class="achievement-right">
                        <div class="achievement-thumbnail" v-if="item.thumbnail">
                          <img :src="item.thumbnail" :alt="item.achievementName" />
                        </div>
                      </div>
                    </div>
                  </div>
                </div>

                <div class="pagination-wrapper">
                  <el-pagination
                    background
                    layout="prev, pager, next"
                    :total="sdgsat1Total"
                    :page-size="sdgsat1PageSize"
                    :current-page="sdgsat1PageNum"
                    @current-change="handleSdgsat1PageChange"
                  />
                </div>
              </section>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSdgsat1AchievementList, getAchievementOverview } from '@/api/portal/achievement'

export default {
  name: 'Achievement',
  data() {
    return {
      loading: true,
      currentMenu: 'overview',
      overviewData: {
        title: '',
        content: ''
      },
      selectedField: '',
      selectedType: '',
      sdgsat1AchievementList: [],
      sdgsat1Total: 0,
      sdgsat1PageSize: 10,
      sdgsat1PageNum: 1
    }
  },
  computed: {
    currentTitle() {
      return this.currentMenu === 'overview' ? '成果总体描述' : 'SDGSAT-1 科学成果'
    }
  },
  mounted() {
    this.fetchAchievementOverview()
  },
  methods: {
    async fetchAchievementOverview() {
      this.loading = true
      try {
        const response = await getAchievementOverview()
        if (response.code === 200 && response.data) {
          this.overviewData = response.data
        }
      } catch (error) {
        console.error('获取成果总体描述失败:', error)
      } finally {
        this.loading = false
      }
    },
    async fetchSdgsat1Achievements() {
      this.loading = true
      try {
        const response = await getSdgsat1AchievementList({
          pageNum: this.sdgsat1PageNum,
          pageSize: this.sdgsat1PageSize
        })
        if (response.code === 200) {
          this.sdgsat1AchievementList = response.rows || []
          this.sdgsat1Total = response.total || 0
        }
      } catch (error) {
        console.error('获取SDGSAT-1成果列表失败:', error)
        this.$message.error('获取成果列表失败')
      } finally {
        this.loading = false
      }
    },
    handleSdgsat1PageChange(page) {
      this.sdgsat1PageNum = page
      this.fetchSdgsat1Achievements()
    },
    viewDetail(id) {
      this.$router.push({
        path: '/portal/achievement/detail',
        query: { id }
      })
    },
    handleMenuClick(menu) {
      this.currentMenu = menu
      if (menu === 'overview') {
        this.fetchAchievementOverview()
      } else if (menu === 'sdgsat1') {
        this.fetchSdgsat1Achievements()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.achievement-container {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 40px 0;
}

.achievement-content {
  max-width: 1390px;
  margin: 0 auto;
  padding: 0 30px;
  display: grid;
  grid-template-columns: 300px 1060px;
  gap: 30px;
  align-items: start;
}

/* 左侧导航卡片 */
.left-sidebar {
  .sidebar-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
  }

  .sidebar-header {
    background: #1EA8C5;
    // padding: 30px 24px;
    height: 58px;
    display: flex;
    align-items: center;
    // justify-content: center;
    padding-left: 19px;

    .title {

font-family: Microsoft YaHei, Microsoft YaHei;
font-weight: bold;
font-size: 18px;
color: #FFFFFF;
line-height: 18px;
text-align: left;
font-style: normal;
text-transform: none;
    }
  }

  .sidebar-decorator {
    width: 100%;
    height: 6px;
    display: flex;
    overflow: hidden;

    .decorator-segment {
      width: 80px;
      height: 100%;

      &:first-child {
        margin-left: -40px;
      }

      &:last-child {
        margin-right: -40px;
      }
    }
  }

  .sidebar-menu {
    padding: 16px 0;

    .menu-item {
      padding: 16px 24px;
      cursor: pointer;
      transition: all 0.3s ease;
      font-size: 16px;
      color: #666666;
      border-left: 3px solid transparent;

      &:hover {
        background-color: #f5f7fa;
        color: #1e3c72;
      }

      &.active {
        background-color: #f0f2f5;
        color: #1e3c72;
        font-weight: 600;
        border-left-color: #1e3c72;
      }
    }
  }
}

/* 右侧内容区域 */
.right-content {
  .content-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    min-height: 600px;
  }

  .content-header {
    padding: 30px 30px 0;

    .title {
      font-size: 20px;
      font-weight: 600;
      color: #1e3c72;
      margin: 0;
    }
  }

  .content-body {
    padding: 30px;
    line-height: 1.8;
    color: #333333;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;

    :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;
      max-width: 100%;
      overflow: hidden;
    }

    :deep(img) {
      max-width: 100% !important;
      width: 100% !important;
      height: auto !important;
      border-radius: 4px;
      margin: 16px 0;
      display: block;
      box-sizing: border-box;
    }

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

/* SDGSAT-1 科学成果样式 */
.sdgsat1-content {
  .sdgsat1-overview {
    margin-bottom: 40px;

    h3 {
      font-size: 20px;
      font-weight: 600;
      color: #1e3c72;
      margin: 0 0 16px 0;
    }

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

.sdgsat1-achievements-list {
  .achievements-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
  }

  .achievement-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    transition: all 0.3s ease;

    &:hover {
      transform: translateY(-3px);
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    }
  }

  .achievement-header {
    padding: 20px 24px;
    border-bottom: 1px solid #f0f0f0;

    .achievement-title {
      font-size: 18px;
      font-weight: 600;
      color: #1e3c72;
      margin: 0;
      line-height: 1.4;
    }
  }

  .achievement-body {
    display: flex;
    padding: 24px;
    gap: 24px;
  }

  .achievement-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .achievement-introduction {
    flex: 1;

    p {
      font-size: 14px;
      color: #666666;
      line-height: 1.8;
      margin: 0;
      text-align: justify;
    }
  }

  .achievement-actions {
    display: flex;
    gap: 12px;
  }

  .achievement-right {
    width: 260px;
    flex-shrink: 0;
  }

  .achievement-thumbnail {
    width: 100%;
    height: 180px;
    border-radius: 6px;
    overflow: hidden;
    background: #f5f7fa;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;

      &:hover {
        transform: scale(1.05);
      }
    }
  }

  .pagination-wrapper {
    display: flex;
    justify-content: center;
    padding: 20px 0;
  }
}

/* 响应式设计 */
@media (max-width: 992px) {
  .achievement-content {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .left-sidebar {
    order: 2;

    .sidebar-menu {
      display: flex;
      overflow-x: auto;
      white-space: nowrap;

      .menu-item {
        border-left: none;
        border-bottom: 3px solid transparent;
        display: inline-block;
        margin-right: 8px;
        border-radius: 4px 4px 0 0;

        &.active {
          border-left: none;
          border-bottom-color: #1e3c72;
        }
      }
    }
  }

  .right-content {
    order: 1;
  }

  .achievement-body {
    flex-direction: column;
  }

  .achievement-right {
    width: 100%;
  }

  .achievement-thumbnail {
    height: 200px;
  }
}

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

  .right-content {
    .content-card {
      min-height: 500px;
    }

    .content-header {
      padding: 20px 20px 0;
    }

    .content-body {
      padding: 20px;
    }
  }

  .left-sidebar {
    .sidebar-header {
      padding: 20px 20px;

      h2 {
        font-size: 20px;
      }
    }

    .sidebar-menu {
      .menu-item {
        padding: 12px 20px;
        font-size: 14px;
      }
    }
  }

  .achievement-header {
    padding: 16px 20px;
  }

  .achievement-body {
    padding: 20px;
    gap: 20px;
  }

  .achievement-thumbnail {
    height: 160px;
  }
}
</style>

<style scoped>
/* 确保图片宽度自适应 */
.content-body >>> img {
  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;
  border-radius: 4px;
  margin: 16px 0;
  display: block;
  box-sizing: border-box;
}

/* 确保富文本编辑器生成的其他元素也不会溢出 */
.content-body >>> .ql-video {
  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;
}
</style>
