<template>
	<view class="u-page">
		<scroll-view scroll-y="true" 
			@scrolltolower="scrolltolower" refresher-enabled="true" :refresher-triggered="triggered"
			@refresherrefresh="onRefresh" @refresherrestore="onRestore" :refresher-threshold="100">
			<view v-for="(item, index) in indexList" :key="index">
				<up-cell :title="`111`">
					<template #icon>
						<up-avatar shape="square" size="35" :src="item.url"
							customStyle="margin: -3px 5px -3px 0"></up-avatar>
					</template>
				</up-cell>
			</view>
		</scroll-view>
		<tabBar></tabBar>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		onLoad,
		onShow,
		onPullDownRefresh
	} from '@dcloudio/uni-app';
	import tabBar from '@/components/tabBar/tabBar.vue';
	import api from "@/api/api"
	console.log(api)
	const indexList = ref([]);
	const status = ref('loadmore');
	const triggered = ref(false);
	const urls = [
		'https://uview-plus.jiangruyi.com/album/1.jpg',
		'https://uview-plus.jiangruyi.com/album/2.jpg',
		'https://uview-plus.jiangruyi.com/album/3.jpg',
		'https://uview-plus.jiangruyi.com/album/4.jpg',
		'https://uview-plus.jiangruyi.com/album/5.jpg',
		'https://uview-plus.jiangruyi.com/album/6.jpg',
		'https://uview-plus.jiangruyi.com/album/7.jpg',
		'https://uview-plus.jiangruyi.com/album/8.jpg',
		'https://uview-plus.jiangruyi.com/album/9.jpg',
		'https://uview-plus.jiangruyi.com/album/10.jpg',
	];

	onLoad(() => {
		loadmore();
		triggered.value = 'restore'; 
	});
	const onRefresh = () => {
		setTimeout(() => {
			triggered.value = false
		}, 1000)

	}
	const onRestore = () => {
		triggered.value = 'restore'; // 需要重置
		console.log("onRestore");
	};
	const scrolltolower = () => {
		loadmore();
	};
	//  onPullDownRefresh(() => {
	//  getData();

	// });
	const getData = () => {
		setTimeout(() => {
			triggered.value = false;
		}, 2000)
		// api.getData().then(res=>{
		// 	alert(11)
		// 	refresherTriggered.value=false;
		// 	uni.stopPullDownRefresh()
		// })
	}


	const loadmore = () => {
		for (let i = 0; i < 30; i++) {
			indexList.value.push({
				url: urls[uni.$u.random(0, urls.length - 1)],
			});

		}
	};
</script>