<template>
  <view class="home-container">
    <!-- 状态栏 -->
    <view class="status-bar">
      <text class="time">9:41</text>
      <view class="status-icons">
        <text class="signal">📶</text>
        <text class="wifi">📶</text>
        <text class="battery">🔋</text>
      </view>
    </view>

    <!-- 头部信息 -->
    <view class="header">
      <view class="location-info">
        <text class="location-icon">📍</text>
        <text class="company-name">福鼎创特物联科技有限公司</text>
        <text class="arrow">></text>
      </view>
      <view class="header-actions">
        <text class="action-icon">⋯</text>
        <text class="action-icon">🎯</text>
      </view>
    </view>

    <!-- 公告栏 -->
    <view class="announcement-bar">
      <text class="speaker-icon">📢</text>
      <text class="announcement-text">暂无更多公告! 暂无更多公告! 暂无更多公告!</text>
    </view>

    <!-- 轮播图 -->
    <view class="banner-section">
      <view class="banner-card" v-for="(banner, index) in bannerList" :key="banner.id" v-show="currentBannerIndex === index">
        <view class="banner-left">
          <view class="product-info">
            <text class="flame-icon">🔥</text>
            <text class="product-name">{{banner.name}}</text>
            <text class="product-desc">{{banner.desc}}</text>
          </view>
          <image class="product-image" :src="banner.image" mode="aspectFit"></image>
        </view>
        <view class="banner-right">
          <text class="product-features">{{banner.features}}</text>
        </view>
      </view>
      <!-- 轮播指示器 -->
      <view class="banner-dots">
        <view 
          v-for="(banner, index) in bannerList" 
          :key="index"
          class="dot" 
          :class="{ active: currentBannerIndex === index }"
          @click="onDotClick(index)"
        ></view>
      </view>
    </view>

    <!-- 设备列表 -->
    <view class="equipment-section">
      <view class="section-title">我的租赁设备</view>
      <view class="equipment-list">
        <view 
          v-for="equipment in equipmentList" 
          :key="equipment.id" 
          class="equipment-item"
          @click="onEquipmentClick(equipment)"
        >
          <image class="equipment-image" :src="equipment.image" mode="aspectFit"></image>
          <view class="equipment-info">
            <view class="equipment-header">
              <text class="equipment-name">{{equipment.name}}</text>
              <text class="status-badge" :class="equipment.status">{{equipment.status === 'normal' ? '正常' : '异常'}}</text>
            </view>
            <view class="equipment-details">
              <text class="detail-item">租赁时间: {{equipment.startTime}}</text>
              <text class="detail-item">到期时间: {{equipment.endTime}}</text>
            </view>
            <button class="renew-btn" @click.stop="onRenew(equipment)">去续费</button>
          </view>
        </view>
      </view>
    </view>

    <!-- 底部导航 -->
    <view class="bottom-nav">
      <view 
        v-for="(nav, index) in ['首页', '申请租赁', '个人中心']" 
        :key="index"
        class="nav-item" 
        :class="{ active: index === 0 }"
        @click="onNavClick(index)"
      >
        <text class="nav-icon">{{index === 0 ? '🏠' : index === 1 ? '➕' : '😊'}}</text>
        <text class="nav-text">{{nav}}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      title: '设备租赁',
      currentBannerIndex: 0,
      bannerList: [
        {
          id: 1,
          name: '渝锦汇',
          desc: '商用节能灶燃烧器',
          features: '商用节能灶燃烧器，高效节能，安全可靠，适用于各类餐饮场所。采用先进燃烧技术，热效率高，节能环保。',
          image: '/static/stove.svg'
        },
        {
          id: 2,
          name: '节能燃烧器',
          desc: '高效节能设备',
          features: '新一代节能燃烧器，热效率提升30%，节能环保，安全可靠。',
          image: '/static/burner.svg'
        }
      ],
      equipmentList: [
        {
          id: 1,
          name: '商用节能灶',
          status: 'normal',
          startTime: '2025-07-25 13:23:59',
          endTime: '2026-07-25 13:23:59',
          image: '/static/stove.svg'
        },
        {
          id: 2,
          name: '节能燃烧器',
          status: 'normal',
          startTime: '2025-07-25 13:23:59',
          endTime: '2026-07-25 13:23:59',
          image: '/static/burner.svg'
        }
      ]
    }
  },
  onLoad() {
    // 页面加载时的逻辑
    this.startBannerAutoPlay();
  },
  methods: {
    // 轮播图自动播放
    startBannerAutoPlay() {
      setInterval(() => {
        this.currentBannerIndex = (this.currentBannerIndex + 1) % this.bannerList.length;
      }, 3000);
    },
    
    // 点击轮播指示器
    onDotClick(index) {
      this.currentBannerIndex = index;
    },
    
    // 去续费
    onRenew(equipment) {
      uni.showToast({
        title: `正在处理${equipment.name}的续费`,
        icon: 'none'
      });
    },
    
    // 点击设备项
    onEquipmentClick(equipment) {
      uni.showToast({
        title: `查看${equipment.name}详情`,
        icon: 'none'
      });
    },
    
    // 点击底部导航
    onNavClick(index) {
      const navItems = ['首页', '申请租赁', '个人中心'];
      uni.showToast({
        title: `切换到${navItems[index]}`,
        icon: 'none'
      });
    }
  }
}
</script>

<style scoped>
.home-container {
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 120rpx; /* 为底部导航留出空间 */
  max-width: 750rpx;
  margin: 0 auto;
}

/* 状态栏 */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 30rpx;
  background-color: #f5f5f5;
  font-size: 28rpx;
  color: #333;
}

.status-icons {
  display: flex;
  gap: 10rpx;
}

/* 头部信息 */
.header {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
  padding: 20rpx 30rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.location-info {
  display: flex;
  align-items: center;
  gap: 10rpx;
  flex: 1;
}

.company-name {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.arrow {
  font-size: 24rpx;
  color: #666;
}

.header-actions {
  display: flex;
  gap: 20rpx;
}

.action-icon {
  font-size: 32rpx;
  color: #333;
}

/* 公告栏 */
.announcement-bar {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
  padding: 15rpx 30rpx;
  display: flex;
  align-items: center;
  gap: 15rpx;
  overflow: hidden;
}

.speaker-icon {
  font-size: 24rpx;
  color: #333;
}

.announcement-text {
  font-size: 24rpx;
  color: #333;
  white-space: nowrap;
  animation: scroll-text 20s linear infinite;
}

@keyframes scroll-text {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

/* 轮播图 */
.banner-section {
  padding: 30rpx;
}

.banner-card {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  display: flex;
  gap: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.banner-left {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
  flex: 1;
}

.product-info {
  display: flex;
  align-items: center;
  gap: 10rpx;
}

.flame-icon {
  font-size: 24rpx;
  color: #ff4757;
}

.product-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
}

.product-desc {
  font-size: 24rpx;
  color: #666;
}

.product-image {
  width: 200rpx;
  height: 150rpx;
  border-radius: 10rpx;
  background-color: #f8f9fa;
}

.banner-right {
  flex: 1;
}

.product-features {
  font-size: 24rpx;
  color: #666;
  line-height: 1.6;
}

.banner-dots {
  display: flex;
  justify-content: center;
  gap: 10rpx;
  margin-top: 20rpx;
}

.dot {
  width: 16rpx;
  height: 16rpx;
  border-radius: 50%;
  background-color: #ddd;
}

.dot.active {
  background-color: #ff9a9e;
}

/* 设备列表 */
.equipment-section {
  padding: 0 30rpx;
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 20rpx;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #eee;
}

.equipment-list {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.equipment-item {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  display: flex;
  gap: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.equipment-item:active {
  transform: scale(0.98);
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.15);
}

.equipment-image {
  width: 120rpx;
  height: 120rpx;
  border-radius: 10rpx;
  background-color: #f8f9fa;
  flex-shrink: 0;
}

.equipment-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.equipment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15rpx;
}

.equipment-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
}

.status-badge {
  padding: 4rpx 12rpx;
  border-radius: 20rpx;
  font-size: 20rpx;
  color: #fff;
}

.status-badge.normal {
  background-color: #52c41a;
}

.status-badge.warning {
  background-color: #faad14;
}

.status-badge.error {
  background-color: #ff4d4f;
}

.equipment-details {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
  margin-bottom: 15rpx;
}

.detail-item {
  font-size: 24rpx;
  color: #666;
}

.renew-btn {
  align-self: flex-end;
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
  color: #fff;
  border: none;
  border-radius: 25rpx;
  padding: 15rpx 30rpx;
  font-size: 24rpx;
  font-weight: 500;
}

/* 底部导航 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 20rpx 0;
  box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8rpx;
  padding: 10rpx;
  transition: all 0.3s ease;
}

.nav-item:active {
  transform: scale(0.95);
}

.nav-icon {
  font-size: 40rpx;
  color: #999;
}

.nav-text {
  font-size: 20rpx;
  color: #999;
}

.nav-item.active .nav-icon,
.nav-item.active .nav-text {
  color: #ff9a9e;
}
</style>
