<template>
	<view class="main">
		<view class="first">
			<input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索赛事名称">
		</view>
		<view class="second">
			<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
				<view class="list-scroll-view">
					<view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
						<view class="list_1">
							<view class="left">
								<image class="image" mode="aspectFill" :src="item.logo||config.logoUrl"></image>
							</view>
							<view class="right">
								<view class="name">
									{{item.name||'暂无名称'}}
								</view>
								<view class="other">
									{{item.address||'暂无地点'}} | {{item.date||'暂无日期'}}
								</view>
								<view class="other">
									{{item.format||'暂无赛制'}}
								</view>
							</view>
						</view>
						<view class="list_2">{{item.ranking||'暂无排名'}}</view>
					</view>
					<view class="is_bottom" v-if="is_bottom">
						<text>{{config.bottomTitle||'到底了！'}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref } from 'vue';
	//该依赖已内置不需要单独安装
	import { onShow } from "@dcloudio/uni-app";
	interface PropsItem {
		name ?: string,
		address ?: string,
		type ?: string,
		logo ?: string,
		date ?: string,
		format ?: string,
		ranking ?: string,
	};
	// 基本信息
	const config = ref({ bottomTitle: '', logoUrl: '' });
	// 查询
	const searchInfo = ref({ name: '' });
	// 列表
	const list = ref<PropsItem[]>([{ name: '肝帝33联赛' }]);
	// 分页
	const skip = ref(0);
	const limit = ref(6);
	const page = ref(0);
	const total = ref(0);
	// 数据是否触底
	const scrollTop = ref(0);
	const is_bottom = ref(false);

	onShow(() => {
		searchConfig();
		search();
	})
	// config信息
	const searchConfig = async () => {
		config.value = uni.getStorageSync('config');
	};
	// 查询列表
	const search = async () => {
		console.log('查询');
	};
	//查询
	const toInput = (e : any) => {
		if (searchInfo.value.name) searchInfo.value.name = e.detail.value
		searchInfo.value = { name: '' }
		clearPage();
		search();
	};
	// 球队详情
	const toInfo = (item : any) => {
		console.log(item);
	};
	// 分页
	const toPage = () => {
		if (total.value > list.value.length) {
			uni.showLoading({
				title: '加载中',
				mask: true
			})
			page.value = page.value + 1
			skip.value = page.value * limit.value;
			search();
			uni.hideLoading();
		} else is_bottom.value = true
	};
	const toScroll = (e : any) => {
		let up = scrollTop.value;
		scrollTop.value = e.detail.scrollTop
		let num = Math.sign(up - e.detail.scrollTop);
		if (num == 1) is_bottom.value = false
	};
	// 清空数据
	const clearPage = () => {
		list.value = []
		skip.value = 0
		limit.value = 6
		page.value = 0
	};
</script>
<style lang="scss" scoped>
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 66vh;

		.first {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 2vw;
			border-bottom: 1px solid var(--f5Color);

			input {
				width: 100%;
				padding: 2vw;
				background-color: var(--f1Color);
				font-size: var(--font14Size);
				border-radius: 5px;
			}
		}

		.second {
			position: relative;
			flex-grow: 1;

			.list {
				border-bottom: 1px solid var(--f5Color);
				padding: 3vw;

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

					.left {
						width: 15vw;

						.image {
							width: 15vw;
							height: 15vw;
							border-radius: 20vw;
						}
					}

					.right {
						width: 75vw;
						margin: 0 0 0 2vw;

						.name {
							font-size: var(--font16Size);
						}

						.other {
							margin: 1vw 0 0 0;
							font-size: var(--font14Size);
							color: var(--f85Color);
						}
					}
				}

				.list_2 {
					text-align: right;
					font-size: var(--font14Size);
					color: var(--fFFColor);
				}
			}
		}
	}

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}

	.is_bottom {
		width: 100%;
		text-align: center;

		text {
			padding: 2vw 0;
			display: inline-block;
			color: var(--f85Color);
			font-size: var(--font14Size);
		}
	}
</style>