<template>
  <div class="home-container">
    <Header />
    <div class="content-container">
      <router-view v-if="$route.path !== '/home'"></router-view>
      <!-- 首页内容，仅在路径为 /home 时显示 -->
      <div v-else class="home-content">
        <!-- 轮播图区域 -->
        <div class="carousel-section">
          <el-carousel :interval="4000" type="card" height="300px">
            <el-carousel-item v-for="item in carouselImages" :key="item.id">
              <el-image :src="item.url" fit="cover" class="carousel-image" />
            </el-carousel-item>
          </el-carousel>
        </div>

        <!-- 快捷功能区域 -->
        <div class="quick-access">
          <div class="quick-item" @click="$router.push('/delivery')">
            <el-icon><Van /></el-icon>
            <span>我要寄件</span>
          </div>
          <div class="quick-item" @click="$router.push('/check')">
            <el-icon><Search /></el-icon>
            <span>运单查询</span>
          </div>
          <div class="quick-item" @click="$router.push('/service')">
            <el-icon><Service /></el-icon>
            <span>服务指南</span>
          </div>
        </div>

        <!-- 公告区域 -->
        <div class="notice-section">
          <h3><el-icon><Bell /></el-icon> 最新公告</h3>
          <el-scrollbar height="150px">
            <div v-for="notice in notices" :key="notice.id" class="notice-item">
              <span class="notice-title">{{ notice.title }}</span>
              <span class="notice-date">{{ notice.date }}</span>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import Header from '../components/Header.vue';
import { ref } from 'vue';
import { Van, Search, Service, Bell } from '@element-plus/icons-vue';

// 轮播图数据
const carouselImages = ref([
  { id: 1, url: 'src/assets/sf1.jpg' },
  { id: 2, url: 'src/assets/sf2.jpg' },
  { id: 3, url: 'src/assets/sf3.png' },
  { id: 4, url: 'src/assets/sf4.jpg' },
  { id: 5, url: 'src/assets/sf5.jpg' },
  { id: 6, url: 'src/assets/sf6.jpg' },
  { id: 7, url: 'src/assets/sf7.jpg' },
  { id: 8, url: 'src/assets/sf8.jpg' },
]);

// 公告数据
const notices = ref([
  { id: 1, title: '关于春节期间快递服务安排的通知', date: '2024-02-01' },
  { id: 2, title: '服务升级公告：新增智能快递柜服务', date: '2024-01-28' },
  { id: 3, title: '关于恶劣天气影响部分地区配送的通知', date: '2024-01-25' },
  { id: 4, title: '快递服务费用调整通知', date: '2024-01-20' },
]);
</script>

<style scoped>
.home-container {
  width: 100%;
  height: 100vh;
  display: flex;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

.content-container {
  flex: 1;
  margin-left: 220px;
  height: 100vh;
  overflow: hidden;
  background-color: #f0f2f5;
  position: relative;
}

.home-content {
  position: fixed;
  top: 60px;
  right: 0;
  width: calc(100% - 220px);
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 20px;
  box-sizing: border-box;
}

/* 轮播图样式 */
.carousel-section {
  margin: 0 auto;
  max-width: 1200px;
  margin-bottom: 30px;
}

.carousel-image {
  width: 100%;
  height: 100%;
  border-radius: 8px;
}

/* 快捷功能区域样式 */
.quick-access {
  display: flex;
  justify-content: space-around;
  margin: 30px auto;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  max-width: 1200px;
}

.quick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 20px;
  border-radius: 8px;
  transition: all 0.3s;
}

.quick-item:hover {
  background: #f5f7fa;
  transform: translateY(-5px);
}

.quick-item .el-icon {
  font-size: 40px;
  color: #409EFF;
  margin-bottom: 10px;
}

/* 公告区域样式 */
.notice-section {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  max-width: 1200px;
  margin: 0 auto;
}

.notice-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
  color: #303133;
}

.notice-item {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid #ebeef5;
  cursor: pointer;
}

.notice-item:hover {
  background: #f5f7fa;
}

.notice-date {
  color: #909399;
  font-size: 14px;
}

/* 响应式布局 */
@media screen and (max-width: 768px) {
  .content-container {
    margin-left: 64px;
  }

  .home-content {
    width: calc(100% - 64px);
  }
  
  .quick-access {
    flex-direction: column;
    gap: 15px;
  }
}
</style>