<template>
	<view>
		<view class="prize-news">
			<view class="prize-news-item" :style="{ animation: activeAnimation }">
				<view class="prize-news-item-one" v-for="(item, index) in barrageList" :key="index">
					<image class="img" :src="item.avatar" lazy-load mode="aspectFill"></image>
					<view class="title">
						<view class="name">恭喜</view>
						<view class="prize">{{ item.nickName }}</view>
						<view class="name">{{ item.type == 1 ? '刮出了' : '兑换了' }}</view>
						<view class="prize">{{ item.prizeInfo }}</view>
					</view>
				</view>
			</view>
			<view class="prize-news-item" :style="{ animation: activeAnimation }">
				<view class="prize-news-item-one" v-for="(item, index) in barrageList" :key="index">
					<image class="img" :src="item.avatar" lazy-load mode="aspectFill"></image>
					<view class="title">
						<view class="name">恭喜</view>
						<view class="prize">{{ item.nickName }}</view>
						<view class="name">{{ item.type == 1 ? '刮出了' : '兑换了' }}</view>
						<view class="prize">{{ item.prizeInfo }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "prize-barrage",
		props: {
			barrageList: {
				type: Array,
				default: () => []
			},
			time: {
				type: [Number, String],
				default: 10
			},
		},
		data() {
			return {
				activeAnimation: "moveLeft 10s linear infinite normal"
			};
		},
		created() {
			this.setAnimation()
		},
		methods: {
			setAnimation() {
				let time = Math.ceil(this.barrageList.length / 5 * this.time)
				this.activeAnimation = `moveLeft ${ time }s linear infinite normal`
			}
		}
	}
</script>

<style lang="scss" scoped>
	.prize-news {
		display: flex;
		width: 100vw;
		height: 50rpx;
		margin-bottom: 12rpx;
		overflow: hidden;

		.prize-news-item {
			display: flex;
			height: 50rpx;

			.prize-news-item-one {
				display: flex;
				align-items: center;
				padding: 0 40rpx 0 4rpx;
				height: 50rpx;
				background: rgba(255, 255, 255, .5);
				border-radius: 25rpx;
				font-size: 24rpx;

				margin-right: 60rpx;
				.img {
					display: inline-block;
					width: 46rpx;
					height: 46rpx;
					vertical-align: middle;
					border-radius: 50%;
				}

				.title {
					display: flex;
					align-items: center;

					.name {
						white-space: nowrap;
						margin: 0 16rpx;
					}

					.prize {
						white-space: nowrap;
						color: #F27120;
					}
				}
			}
		}
	}
</style>
