<template>
  <div class="progress-container">
    <div class="progress-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 === 'project' }"
              @click="handleMenuClick('project')"
            >
              项目实施进展
            </div>
            <div 
              class="menu-item"
              :class="{ active: currentMenu === 'milestone' }"
              @click="handleMenuClick('milestone')"
            >
              里程碑事件
            </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="rich-text-rendering">
            <!-- 项目实施进展内容 -->
            <div v-if="currentMenu === 'project'" class="project-progress">
              <div class="rich-text" v-html="implementationProgress.content || '<p>暂无内容</p>'"></div>
            </div>
            
            <!-- 里程碑事件内容 -->
            <div v-if="currentMenu === 'milestone'" class="milestone-content">
              <div class="milestone-timeline">
                <div v-for="(item, index) in milestoneList" :key="item.id" class="milestone-timeline-item">
                  <div class="milestone-timeline-marker"></div>
                  <div class="milestone-timeline-content">
                    <h3 class="milestone-title">{{ item.eventName }}</h3>
                    <div class="milestone-description" v-html="item.eventDescription"></div>
                  </div>
                </div>
                <div v-if="milestoneList.length === 0" class="empty-data">
                  <i class="el-icon-info"></i>
                  <span>暂无里程碑事件数据</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getImplementationProgress, getMilestoneList } from '@/api/portal/progress'

export default {
  name: 'Progress',
  data() {
    return {
      loading: true,
      currentMenu: 'project',
      implementationProgress: {
        title: '',
        content: ''
      },
      milestoneList: []
    }
  },
  computed: {
    currentTitle() {
      return this.currentMenu === 'project' ? '项目实施进展' : '里程碑事件'
    }
  },
  created() {
    this.getImplementationProgress()
    this.getMilestoneList()
  },
  methods: {
    handleMenuClick(menu) {
      this.currentMenu = menu
    },
    // 获取项目实施进展数据
    getImplementationProgress() {
      this.loading = true
      getImplementationProgress().then(response => {
        if (response.data) {
          this.implementationProgress = response.data
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 获取里程碑事件数据
    getMilestoneList() {
      this.loading = true
      getMilestoneList().then(response => {
        if (response.data) {
          this.milestoneList = response.data.sort((a, b) => {
            return new Date(a.eventTime) - new Date(b.eventTime)
          })
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 格式化日期
    formatDate(dateStr) {
      if (!dateStr) return ''
      const date = new Date(dateStr)
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, '0')
      const day = String(date.getDate()).padStart(2, '0')
      return `${year}-${month}-${day}`
    }
  }
}
</script>

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

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

/* 里程碑时间轴样式 */
.milestone-timeline {
  position: relative;
  padding-left: 30px;

  &::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, #1e3c72 0%, #2a5298 50%, #e8e8e8 100%);
  }

  .milestone-timeline-item {
    position: relative;
    padding: 20px 0;
    border-bottom: 1px solid #f0f0f0;

    &:last-child {
      border-bottom: none;
    }

    .milestone-timeline-marker {
      position: absolute;
      left: -26px;
      top: 24px;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: #c0c4cc;
      border: 3px solid #fff;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

      &.latest {
        background: #1e3c72;
        width: 20px;
        height: 20px;
        left: -28px;
        top: 22px;
        box-shadow: 0 0 0 4px rgba(30, 60, 114, 0.2);
      }
    }

    .milestone-timeline-content {
      .milestone-time {
        font-size: 14px;
        color: #909399;
        margin-bottom: 8px;
      }

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

      .milestone-description {
        font-size: 15px;
        color: #606266;
        line-height: 1.8;

        :deep(p) {
          margin-bottom: 10px;
        }
      }
    }
  }

  .empty-data {
    text-align: center;
    padding: 60px 0;
    color: #909399;

    i {
      font-size: 48px;
      margin-bottom: 16px;
      display: block;
    }

    span {
      font-size: 16px;
    }
  }
}
</style>