<template>
	<view class="whole">
		<view class="content">
			<view class="left">
				<template v-for="(item, index) in list" :key="item.id">
					<view class="row" @click="toPage(item.id)" v-if="index % 2 == 0">
						<view class="img">
							<image :src="item.explain_video + '?x-oss-process=video/snapshot,t_1000,m_fast'" mode="widthFix"></image>
							<view class="icon"><up-icon name="play-right-fill" size="14" color="#fff" /></view>
						</view>
						<view class="desc">{{item.description}}</view>
						<view class="num">{{item.visitor}}人看过 | {{item.order_count}}人跟团</view>
					</view>
				</template>
			</view>
			<view class="left">
				<template v-for="(item, index) in list" :key="item.id">
					<view class="row" @click="toPage(item.id)" v-if="index % 2 == 1">
						<view class="img">
							<image :src="item.explain_video + '?x-oss-process=video/snapshot,t_1000,m_fast'" mode="widthFix"></image>
							<view class="icon"><up-icon name="play-right-fill" size="14" color="#fff" /></view>
						</view>
						<view class="desc">{{item.description}}</view>
						<view class="num">{{item.visitor}}人看过 | {{item.order_count}}人跟团</view>
					</view>
				</template>
			</view>
		</view>
		
		<view class="noMore" v-if="list.length && !has_more && !loading">— 没有更多了 —</view>
		<view v-if="!list.length && !loading">
			<up-empty mode="list" icon="https://ct-upimg.yx090.com/g.ii090/images/sprite/empty/list.png" text="暂无数据"></up-empty>
		</view>
		<view v-if="loading" class="loadbox">
			<up-loading-icon text="加载中..." textSize="14"></up-loading-icon>
		</view>
		
	</view>
	
</template>

<script>
	import { ref, reactive, toRefs } from 'vue'
	import { get } from '@/Api/request.js'
	
	export default {
		setup() {
			const data = reactive({
				last_id: 0,
				loading: true,
				has_more: true,
				list: []
			})
			
			function getList() {
				data.loading = true
				get('/api/app/goods/videos', {last_id: data.last_id, pageSize: 20}).then(res => {
					data.list = data.list.concat(res.data)
					data.last_id = res.last_id
					data.has_more = res.has_more
					data.loading = false
				}).catch(() => {
					data.loading = false
				})
			}
			
			function toPage(id) {
				uni.navigateTo({
					url: '/pages/groups/video?id=' + id
				})
			}
			
			return {
				...toRefs(data),
				getList,
				toPage
			}
		},
		async onLoad(options) {
			// await this.$onLaunched
			this.getList()
		},
		onReachBottom() {
			if (this.has_more && !this.loading) {
				this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.whole{
		background-color: #EDEDED;
		min-height: 100vh;
	}
	.content{
		padding: 24rpx 1.5%;
		box-sizing: border-box;
		display: flex;
		flex-wrap: wrap;
		.left{
			width: 50%;
			padding: 0 1.5%;
			box-sizing: border-box;
		}
		.row{
			background-color: #fff;
			border-radius: 10rpx;
			width: 100%;
			margin-bottom: 24rpx;
			overflow: hidden;
			.img{
				width: 100%;
				position: relative;
				image{
					width: 100%;
					height: auto;
				}
				.icon{
					position: absolute;
					top: 20rpx;
					right: 20rpx;
					background-color: rgba(0,0,0,0.5);
					border-radius: 50%;
					width: 26px;
					height: 26px;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
			.desc{
				font-size: 28rpx;
				overflow: hidden !important;
				text-overflow: ellipsis !important;
				display: -webkit-box !important;
				-webkit-line-clamp: 2 !important;
				-webkit-box-orient: vertical !important;
				white-space: break-spaces !important;
				padding: 0 20rpx;
				margin: 10rpx 0;
			}
			.num{
				font-size: 24rpx;
				padding: 10rpx 20rpx 20rpx;
				color: #999;
			}
		}
	}
	.noMore{
		text-align: center;
		font-size: 24rpx;
		color: #999;
		margin: auto;
		padding: 30rpx 0 60rpx;
		width: 100%;
	}
	.noMsg{
		width: 100%;
		height: 100vh;
		display: flex;
		align-items: center;
		flex-direction: column;
		padding-top: 20%;
		box-sizing: border-box;
		font-size: 26rpx;
		color: #9D9D9D;
	}
	.loadbox{
		padding: 30rpx 0;
		text-align: center;
		color: #666;
	}
</style>
