<template>
  <view class="goods-detail">
    <!-- 轮播图 -->
    <view class="banner-container">
      <uv-swiper 
      indicator
       indicatorMode="dot"
       indicatorActiveColor="blue"
      height="700rpx"
      :list="bannerImages"></uv-swiper>
    </view>
    
    <!-- 商品信息 -->
    <view class="goods-info">
      <!-- 积分信息 -->
      <view class="points-section">
        <uv-icon name="integral" size="16" color="#218cdd"></uv-icon>
        <text class="points-text">{{ goodsData.points }}积分</text>
      </view>
      
      <!-- 商品标题 -->
      <view class="title-section">
        <text class="goods-title">{{ goodsData.name }}</text>
      </view>
      
    </view>
    
    <!-- 商品详情独立容器 -->
    <view class="detail-container">
      <!-- 商品详情标题 -->
      <view class="detail-title-section">
        <text class="detail-title">商品详情</text>
      </view>
      
      <!-- 商品图集 -->
      <view class="gallery-section">
        <view class="gallery-grid">
          <image 
            v-for="(img, index) in goodsData.gallery" 
            :key="index"
            :src="img" 
            class="gallery-image" 
            mode="aspectFill"
            @click="previewImage(img, goodsData.gallery)"
          ></image>
        </view>
      </view>
    </view>
    
    <!-- 底部操作栏 - 只在待领取状态显示 -->
    <view v-if="status === 'pending'" class="bottom-bar">
      <view class="exchange-btn" @click="confirmReceive">
        <text class="exchange-text">确认取货</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'ExchangeDetail',
  data() {
    return {
      goodsId: '',
      status: 'pending', // pending: 待领取, received: 已领取, cancelled: 系统取消
      goodsData: {
        id: 1,
        name: '哪吒之魔童闹海新款首套装哪吒校内艺术手办树脂摆件学生小礼品',
        points: 100,
        category: '积分兑换',
        exchangeCount: 120,
        stock: 50,
        description: '这是一款美味的薄脆小饼干，口感酥脆，营养丰富。采用优质原料制作，无添加剂，适合全家人享用。每一口都能感受到浓郁的香味和酥脆的口感，是您休闲时光的最佳选择。',
        gallery: [
          '/static/商城_商品1.png',
          '/static/商城_商品2.png',
          '/static/bannerImage.png',
          '/static/商城_商品1.png',
          '/static/商城_商品2.png',
          '/static/bannerImage.png'
        ]
      },
      bannerImages: [
        '/static/商城_商品1.png',
        '/static/商城_商品2.png',
        '/static/bannerImage.png'
      ]
    }
  },
  onLoad(options) {
    if (options.id) {
      this.goodsId = options.id;
    }
    if (options.status) {
      this.status = options.status;
    }
    this.getGoodsDetail(this.goodsId);
  },
  methods: {
    getGoodsDetail(id) {
      // 模拟获取商品详情
      console.log('获取商品详情:', id);
      
      // 根据id设置不同的商品数据
      const goodsMap = {
        '1': {
          id: 1,
          name: '哪吒之魔童闹海新款首套装哪吒校内艺术手办树脂摆件学生小礼品',
          points: 100,
          category: '积分兑换',
          exchangeCount: 120,
          stock: 50,
          description: '这是一款美味的薄脆小饼干，口感酥脆，营养丰富。采用优质原料制作，无添加剂，适合全家人享用。',
          gallery: ['/static/商城_商品1.png', '/static/商城_商品2.png', '/static/bannerImage.png', '/static/商城_商品1.png', '/static/商城_商品2.png', '/static/bannerImage.png']
        },
        '2': {
          id: 2,
          name: '幼儿园宝宝启蒙书',
          points: 145,
          category: '母婴',
          exchangeCount: 85,
          stock: 30,
          description: '专为幼儿园宝宝设计的启蒙读物，内容丰富有趣，图文并茂，有助于培养孩子的阅读兴趣和认知能力。',
          gallery: ['/static/商城_商品2.png', '/static/商城_商品1.png', '/static/bannerImage.png', '/static/商城_商品2.png', '/static/商城_商品1.png', '/static/bannerImage.png']
        }
      };
      
      if (goodsMap[id]) {
        this.goodsData = goodsMap[id];
        this.bannerImages = goodsMap[id].gallery.slice(0, 3);
      }
    },
    
    previewImage(current, urls) {
      uni.previewImage({
        current: current,
        urls: urls
      });
    },
    
    confirmReceive() {
      uni.showModal({
        title: '确认取货',
        content: `确定已取货${this.goodsData.name}吗？`,
        success: (res) => {
          if (res.confirm) {
            // 执行确认取货逻辑
            uni.showToast({
              title: '取货成功',
              icon: 'success'
            });
            
            // 延迟返回上一页
            setTimeout(() => {
              uni.navigateBack();
            }, 1500);
          }
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-detail {
  background: #f8f8f8;
  min-height: 100vh;
  padding-bottom: 120rpx; // 为底部固定栏留出空间
}

.banner-container {
  height: 700rpx;
  .banner-swiper {
    width: 100%;
    
    .banner-image {
      width: 100%;
      height: 100%;
    }
  }
}

.goods-info {
  background: #ffffff;
  margin-top: 20rpx;
  padding: 30rpx;
}

.points-section {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
  
  .points-text {
    font-size: 32rpx;
    font-weight: bold;
    color: #218cdd;
    margin-left: 6rpx;
  }
}

.title-section {
  margin-bottom: 40rpx;
  
  .goods-title {
    font-size: 28rpx;
    color: #333333;
    line-height: 1.5;
    display: block;
  }
}

.detail-container {
  background: #ffffff;
  margin-top: 20rpx;
  padding: 30rpx;
  margin-bottom: 120rpx;
}

.detail-title-section {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30rpx;
  
  .detail-title {
    font-size: 28rpx;
    font-weight: bold;
    color: #333333;
  }
}

.gallery-section {
  margin-bottom: 40rpx;
  
  .gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16rpx;
    
    .gallery-image {
      width: 100%;
      height: 200rpx;
      border-radius: 12rpx;
      border: 1rpx solid #f0f0f0;
    }
  }
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  padding: 20rpx 30rpx;
  border-top: 1rpx solid #f0f0f0;
  z-index: 999;
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  
  .exchange-btn {
    width: 100%;
    height: 80rpx;
    border-radius: 40rpx;
    background-color: #218cdd;
    display: flex;
    align-items: center;
    justify-content: center;
    
    .exchange-text {
      color: #ffffff;
      font-size: 28rpx;
    }
  }
}
</style>