<template>
	<div class="notice">
		<div class="title"><u-icon name="volume-up" size="46"></u-icon>恭喜</div>

		<view class="view_box list" :style="{height:listHeight + 'rpx'}">
			<view :style="transitionStyle">
				<template v-for="item in list">
					<view class="item">
						<text class="item_time">{{item.time}}</text> {{item.nickname}}获得{{item.xuefen}}学分
					</view>
				</template>
			</view>
		</view>
		<image @click.stop="handleScreen" src="@/static/images/index/screen.png" mode="" class="amplify">
		</image>
	</div>
</template>

<script>
	var timr = null
	import scrollList from '../components/zh-scrollList/scrollList/scrollList.vue'
	export default {
		components: {
			scrollList,
		},
		name: "ScrollNotice",
		props: {
			noticeList: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				minScrollNum: 10,
				transitionStyle: '',
				list: [],
				listHeight: 200,
			};
		},
		watch: {
			noticeList: {
				handler(news, old) {
					clearInterval(timr)
					timr = null
					this.transitionStyle = ''
					console.log('timr', timr)
					this.list = []
					console.log(this.noticeList)
					this.list = [...this.noticeList, ...this.noticeList]
					this.init()
				},
			}
		},
		created() {

		},
		onHide() {
			console.log('执行这里')
			this.transitionStyle = ''
			clearInterval(timr)
			timr = null
		},
		methods: {
			init() {
				// 主要通过 transition 的过度时间 控制 滚动速度
				setTimeout(() => {
					console.log('zhixing', timr)
					this.transitionStyle = 'transition: all 15s linear 0s;transform: translateY(-50%);'

					if (timr) return
					timr = setInterval(() => {
						this.transitionStyle = ''
						setTimeout(() => {
							this.transitionStyle =
								'transition: all 15s linear 0s;transform: translateY(-50%);'
						}, 20)
					}, 15000)
				}, 20)
			},
			handleScreen() {
				if (this.listHeight == 200) {
					this.listHeight = 600
					return
				}
				if (this.listHeight == 600) {
					this.listHeight = 200
					return
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.view_box {
		// background-color: #aaa2fb;
		height: 200rpx;
		overflow: hidden;
	}

	.notice {
		border-radius: 5px;

		border: 1px solid #CAC1C1;
		overflow: hidden;
		margin-top: 10px;
		position: relative;

		.amplify {
			position: absolute;
			bottom: 10px;
			right: 10px;
			width: 16px;
			height: 16px;
		}

		.title {
			border-radius: 5px 5px 0px 0px;
			padding: 6px 0;
			font-size: 18px;
			display: flex;
			justify-content: center;
			align-items: center;
			background: linear-gradient(90deg, #FB7B58 0%, #F5222D 97%);
			color: #fff;
			text-align: center;

			.u-icon {
				margin-right: 4px;
			}
		}

		.list {
			padding: 4px 16px;

			.item {
				height: 26px;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				line-height: 26px;
				padding: 6px 0px;

				.item_time {
					display: inline-block;
					margin-right: 10px;
				}
			}
		}
	}
</style>