<template>
	<view class="container">
		<swiper class="swiper" :circular="true" :autoplay="false" :duration="500" :previous-margin="'200rpx'"
			:next-margin="'200rpx'" :style="{ height: '300rpx' }" :current="currentIndex"
			:easing-function="easeInOutCubic"
			@change="changeCurrent">
			<swiper-item v-for="(slide, index) in processedSildeItems" :key="index" style="overflow: initial;"
				:class="index==currentIndex? 'swiper-item-active':'swiper-item-normal'" @click="swiperClick(slide)">
				<view :class="index==currentIndex? 'swiper-item active':'swiper-item'">
					<image style="width: 100%;height: 90%;" mode="aspectFill" :src="slide[image]"></image>
					<text class="swiper-text">{{ slide[title] }}</text>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentIndex: 0
			};
		},
		methods: {
			changeCurrent(e) {
				this.currentIndex = e.detail.current
			},
			swiperClick(data){
				this.$emit('swiperClick', data);
			}
		},
		props: {
			sildeItems: {
				type: Array,
				required: true
			},
			image: {
				type: String,
				required: false,
				default: "image"
			},
			title: {
				type: String,
				required: false,
				default: "title"
			}
		},
		computed: {
			processedSildeItems() {
				return [...this.sildeItems, ...this.sildeItems];
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.swiper {
		width: 100%;
		overflow: visible;
		/* 确保部分滑块可见 */
		height: 100%;
		padding: 0 25rpx;
	}

	.swiper-item-active {
		z-index: 10;
		display: flex;
		align-items: center;
	}

	.swiper-item-normal {
		z-index: 1;
		display: flex;
		    align-items: center;
	}

	.swiper-item {
		display: flex;
		height: 80%;
		width: 85%;
		margin: 0 auto;
		justify-content: flex-end;
		align-items: center;
		font-size: 14rpx;
		border-radius: 10px;
		flex-direction: column;
		color: #000;
		.swiper-text {
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			margin-top: 10rpx;
		}
	}

	.active {
		// display: flex;
		height: 100%;
		width: 93%;
		margin: auto;
		justify-content: center;
		font-size: 24rpx;
		.swiper-text {
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}
</style>