<template>
	<scroll-view style="height:100%" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="triggered"
		@scrolltolower="scrolltolower" @refresherrefresh="onRefresh" refresher-default-style="black">
		<view class="videoBox" v-for="item in videoList" :key="item" @click="goDetail(item)">
			<!-- :style='{backgroundImage:"../../../static/1.png"}' -->
			<view class="leftBox">
				<view class="time">
					04:30
				</view>
				<i class="custom-icon custom-icon-start-full"></i>
			</view>
			<view class="info">
				<view class="content">
					{{item.title}}
				</view>
				<view class="attentionSituation">
					<view class="time">
						{{item.updateTime ? formatDate(Date.parse(item.updateTime)): ""}}
					</view>
					<view class="playCount">
						1万次播放
					</view>
				</view>

			</view>
		</view>
	</scroll-view>
</template>

<script>
	import { getVideoList } from '@/api/video.js'
	import { formatDate } from '@/utils/util.js'
	export default {
		data() {
			return {
				loadingStatus: 'loadmore', // 上拉loading
				triggered: false, // 下拉是否激活
				videoList: [],
				total: 0,
				pageNum: 1,
				pageSize: 10,
				isRequesting: false, // 是否正在请求，如果是则返回，用于节流
				videoParams: {
					pageNum: 1,
					pageSize: 10,
					checkStatus: '5', // 已发布的数据
				},
			};
		},
		methods: {
			// 上拉加载
			scrolltolower() {
				if (this.videoList.length < this.total) {
					this.pageNum += 1;
					// 继续请求下一页，记得保留原先数组
					this.getList();
				} else {
					uni.showToast({
						title: "没有更多了",
						icon: "none",
						duration: 2000,
					});
					return;
				}
			},
			// 自定义下拉刷新被触发
			onRefresh() {
				// 开启下拉自定义样式
				this.triggered = true;
				//  重新调用
				this.getList();
				// 1秒之后复位
				setTimeout(() => {
					this.triggered = false;
				}, 1000);
			},
			getList(params={}) {
				this.isRequesting = true
				getVideoList({...this.videoParams,...params}).then(res => {
					// console.log("res:", res)
					this.videoList = [...this.videoList, ...res.rows]
					// console.log('videoList', this.videoList)
					this.total = res.total
					this.loadingStatus = this.videoList.length >= this.total ? 'nomore' : 'loading'
				}).finally(() => this.isRequesting = false)
			},
			// 点击资讯跳转详情
			goDetail(val) {
				console.log('跳转')
				uni.navigateTo({
					url: '/pages/video/detail'
				});
			},
		}
	}
</script>

<style lang="scss">
	.videoBox {
		width: 96%;
		background-color: #fff;
		padding: 20rpx;
		height: 260rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		border-radius: 24rpx;
		box-shadow: 0 0 10rpx 6rpx rgba(0, 0, 0, 0.1);
		color: #666;
		display: flex;
		justify-content: space-between;

		.leftBox {
			width: 40%;
			height: 100%;
			margin-right: 20rpx;
			// background-color: red;
			position: relative;
			border-radius: 12rpx;
			border: 1px solid #eee;

			.time {
				width: 90rpx;
				height: 40rpx;
				border-radius: 40rpx;
				text-align: center;
				line-height: 40rpx;
				color: #fff;
				background-color: rgba(0, 0, 0, 0.1);
				position: absolute;
				top: 20rpx;
				right: 10rpx;
			}

			.custom-icon {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				font-size: 60rpx;
				&::before {
					background: rgba(0,0,0,0.1);
					-webkit-background-clip: text;
					-webkit-text-fill-color: transparent;
					font-weight: bold;
				}
			}

		}

		.info {
			flex: 1;
			// width: 100%;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.content {
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical;
				font-size: 32rpx;
				font-weight: 600;
			}

			.attentionSituation {
				font-size: 24rpx;
				display: flex;
				align-items: center;
				color: #aaa;

				.time {
					margin-right: 20rpx;
				}

			}

		}
	}
</style>