<template>
	<view class="container">
		<view class="top">
			<image class="back-img" src="../../static/img/start.gif" mode=""></image>
			<view class="top-bottom">
			</view>
			<uni-search-bar class="uni-mt-10" placeholder="请输入喜欢的艺术家代号吧~" clearButton="auto" cancelButton="none"
				@confirm="search" />
			<text>大家都在搜</text>
			<view class="user-list">
				<view class="user-list-box" v-for="(item,index) in userList" :key='item.id'
					@click="goUserDetail(item.scanCode)">
					<image :src="item.img" mode=""></image>
					<text>{{item.tiktokNumber}}</text>
				</view>
				<view class="user-list-box" v-for="(item,index) in userList" :key='item.id'>
					<image :src="item.img" mode=""></image>
					<text>{{item.tiktokNumber}}</text>
				</view>
				<view class="user-list-box" v-for="(item,index) in userList" :key='item.id'>
					<image :src="item.img" mode=""></image>
					<text>{{item.tiktokNumber}}</text>
				</view>
			</view>
		</view>
		<view class="middle">
			<text>近期精选</text>
			<image src="../../static/img/slide-top.svg" mode=""></image>
		</view>
	</view>
</template>

<script>
	import {
		tiktokUserImgs,tiktokUserDetails
	} from '@/api/index.js'
	export default {
		data() {
			return {
				userList: []
			}
		},
		created() {
			this.getUserList()
		},
		onPageScroll(e) {
			// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
			console.log('e.scrollTop', e.scrollTop)
			if (e.scrollTop > 200) {
				uni.redirectTo({
					url: './choiceness'
				})
			}
		},
		methods: {
			search(res) {
				if (res.value) {
					console.log('search',res.value)
					this.goUserDetail(res.value)
				} else {
					uni.showToast({
						title: '请输入艺术家代号',
						icon: 'error'
					})
				}

			},
			// 获取推荐用户列表
			async getUserList() {
				const res = await tiktokUserImgs()
				if (res.data.code === 200) {
					this.userList = res.data.data
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'error'
					})
				}
				console.log('getUserList', res)
			},
			// 前往用户空间
			async goUserDetail(scanCode) {
				if (scanCode) {
					const res = await tiktokUserDetails({
						scanCode
					})
					console.log('tiktokUserDetails',res)
					if (res.data.code === 200) {
						uni.setStorage({
							key: 'userDetail',
							data: res.data.data,
							success() {
								uni.redirectTo({
									url: '../creator/userDetail'
								})
							}
						})
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						})
					}
					
				} else {
					uni.showToast({
						title: '搜索码不能为空',
						icon: 'error'
					})
				}
			},
			// 滚动监听
			handleScroll() {
				let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
				console.log(scrollTop)
			},
		},
	}
</script>

<style lang="less">
	.container {
		.top {
			width: 100vw;

			image {
				width: 100vw;
				height: 400rpx;
			}

			.uni-searchbar {
				border: 1px solid #11A8FD;
				margin: 0 40rpx;
				border-radius: 16rpx;
				padding: 0;

				.uni-searchbar__box {
					padding: 0;
					border-radius: 16rpx !important;
				}
			}

			>text {
				font-weight: bold;
				font-size: 14px;
				display: block;
				text-align: center;
				padding-top: 40rpx;
				padding-bottom: 20rpx;
			}

			.user-list {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				overflow-x: auto;

				.user-list-box {
					width: 140rpx;
					padding: 20rpx;
					text-align: center;

					image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 100rpx;
					}

					text {
						font-size: 24rpx;
						color: #1E1E1E;
						text-align: center;
					}
				}
			}
		}

		.middle {
			text-align: center;
			height: calc(100vh - 248rpx);
			padding-top: 40rpx;

			text {
				font-weight: bold;
				font-size: 14px;
				display: block;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}
</style>
