<template>
  <div class="sdgsat1-achievements-page">
    <div class="page-container">
      <div class="page-header">
        <h1>SDGSAT-1 卫星科学成果</h1>
        <p class="subtitle">展示SDGSAT-1卫星的科学研究成果与应用</p>
      </div>

      <div class="achievements-list">
        <div class="achievement-card" v-for="(item, index) in achievementList" :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="total"
          :page-size="pageSize"
          :current-page="pageNum"
          @current-change="handlePageChange"
        />
      </div>
    </div>
  </div>
</template>

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

export default {
  name: 'Sdgsat1Achievements',
  data() {
    return {
      achievementList: [],
      loading: false,
      total: 0,
      pageSize: 10,
      pageNum: 1
    }
  },
  created() {
    this.fetchAchievementList()
  },
  methods: {
    async fetchAchievementList() {
      this.loading = true
      try {
        const response = await getSdgsat1AchievementList({
          pageNum: this.pageNum,
          pageSize: this.pageSize
        })
        if (response.code === 200) {
          this.achievementList = response.rows || []
          this.total = response.total || 0
        }
      } catch (error) {
        console.error('获取SDGSAT-1成果列表失败:', error)
        this.$message.error('获取成果列表失败')
      } finally {
        this.loading = false
      }
    },
    handlePageChange(page) {
      this.pageNum = page
      this.fetchAchievementList()
    },
    viewDetail(id) {
      this.$router.push({
        path: '/portal/achievement/detail',
        query: { id }
      })
    }
  }
}
</script>

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

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

.page-header {
  text-align: center;
  margin-bottom: 50px;

  h1 {
    font-size: 42px;
    font-weight: 700;
    color: #1e3c72;
    margin: 0 0 15px 0;
  }

  .subtitle {
    font-size: 18px;
    color: #666666;
    margin: 0;
  }
}

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

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

  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  }
}

.achievement-header {
  padding: 25px 30px;
  border-bottom: 1px solid #f0f0f0;

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

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

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

.achievement-introduction {
  flex: 1;

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

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

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

.achievement-thumbnail {
  width: 100%;
  height: 200px;
  border-radius: 8px;
  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: 30px 0;
}

@media (max-width: 768px) {
  .achievement-body {
    flex-direction: column-reverse;
  }

  .achievement-right {
    width: 100%;
  }

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