<template>
	<view class="custom-swiper-wrapper">
		<swiper class="custom-swiper" :current="activeIndex" @change="onSwiperChange" circular :duration="300"
			indicator-dots="false" autoplay="false" display-multiple-items="1" :previous-margin="outerMargin"
			:next-margin="outerMargin" indicator-color="rgba(255, 255, 255, 0.5)" indicator-active-color="#FFEB66">
			<swiper-item v-for="(item, index) in products" :key="index">
				<!-- 用容器包裹item，通过padding控制内部间距 -->
				<view class="item-container">
					<!-- <view class="swiper-item" :class="{ 'swiper-item-active': index === currentCenterIndex }">
						<image class="item-image" :src="item.image" mode="aspectFit"></image>
						<view class="item-text" v-if="index === currentCenterIndex">
							<view class="text-title">{{ item.title }}</view>
							<view class="text-desc">{{ item.desc }}</view>
						</view>
					</view> -->
					<view class="swiper-item" :class="{ 'swiper-item-active': index === currentCenterIndex }">
						<image class="item-image" :src="item.imgUrl" mode="aspectFit"></image>
						<view class="item-text" v-if="index === currentCenterIndex">
							<view class="text-title">{{ item.prizeLevel }}等奖</view>
							<view class="text-desc">{{ item.productName }}</view>
						</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		string
	} from 'uview-plus/libs/function/test';

	export default {
		props: {
			products: {
				type: Array,
				default: "",
			}
		},
		data() {
			return {
				activeIndex: 0, // 初始激活项索引（建议从1开始，避免循环时偏移）
				outerMargin: '120rpx', // 轮播左右外部间距
				// swiperData: [{
				// 		image: "/static/images/zfb.png",
				// 		title: "二等奖",
				// 		desc: "纳美科学高浓度小苏打牙膏",
				// 	},
				// 	{
				// 		image: "/static/images/red_bg.png",
				// 		title: "二等奖",
				// 		desc: "纳美科学高浓度小苏打牙膏",
				// 	},
				// 	{
				// 		image: "/static/images/share.png",
				// 		title: "二等奖",
				// 		desc: "纳美科学高浓度小苏打牙膏",
				// 	},
				// 	{
				// 		image: "/static/images/integral.png",
				// 		title: "二等奖",
				// 		desc: "纳美科学高浓度小苏打牙膏",
				// 	}
				// ],
			};
		},
		computed: {
			// 计算中心项索引（解决循环轮播时的索引匹配问题）
			currentCenterIndex() {
				if (this.products.length === 0) return 0;
				return this.activeIndex % this.products.length;
			}
		},
		methods: {
			onSwiperChange(e) {
				this.activeIndex = e.detail.current;
			},
		},
	};
</script>

<style scoped>
	.custom-swiper-wrapper {
		width: 100%;
		overflow: hidden;
		/* padding: 20rpx 0; */
	}

	.custom-swiper {
		width: 100%;
		height: 500rpx;
		/* 固定高度，避免item被截断 */
	}

	/* 控制item之间的间距容器 */
	.item-container {
		padding: 0 20rpx;
		/* 左右内边距，控制item之间的间距 */
	}

	/* 基础item样式 */
	.swiper-item {
		width: 100% !important;
		/* 宽度占满容器，配合padding控制实际宽度 */
		height: 348rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 12rpx 19rpx 2rpx rgba(219, 73, 22, 0.6);
		border-radius: 24rpx;
		border: 4rpx solid #FFCA96;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
		padding: 20rpx 0;
		transition: all 0.3s ease;
	}

	/* 中心项激活样式 */
	.swiper-item-active {
		transition: all 0.5s ease;
		height: 420rpx;
		/* 中心项高度增加 */
		z-index: 10;
		/* 确保中心项在最上层 */
	}

	.item-image {
		width: 280rpx;
		height: 280rpx;
	}

	.item-text {
		text-align: center;
	}

	.text-title {
		font-weight: 500;
		font-size: 32rpx;
		color: #222222;
		margin: 20rpx 0 10rpx;
	}

	.text-desc {
		font-size: 24rpx;
		color: #757575;
	}
</style>