<template>
	<view>
		<view class="searchBar">
			<search-bar :disabled="false" @onSearch="onSearch"></search-bar>
		</view>
		<view class="homeBtn" @click="home">
			<image src="/static/home.png" style="width: 40upx;height: 40upx;" />
		</view>
		<block v-for="(item, index) in hotList" :key="index">
			<u-line color="#e8e8e8"></u-line>
			<view class="padding-sm flex justify-between align-center bg-white"
				@click="navWithParm(item.id)">
				<view class="flex justify-around align-center">
					<view class="padding-right text-center text-black text-bold" style="width: 60upx;">
						{{item.rank}}</view>
					<view class="padding-right">
						<u-avatar :src="item.avatar" size="130"></u-avatar>
					</view>
					<view>
						<view class="text-bold text-black">{{item.nickName}}</view>
						<view class="margin-tb-xs">{{+item.score}} 热力值</view>
					</view>
				</view>
				<view class="padding-right">
					<button class="cu-btn round  text-white" style="background-color: #583ce6;height: 68upx;">
						<text class="cuIcon-hotfill padding-right-xs"></text>
						<text>打榜</text>
					</button>
				</view>
			</view>
		</block>
		<view style="height: 80rpx;" v-if="status">
			<u-divider bgColor="#f1f1f1;" height="80">到底了</u-divider>
		</view>
	</view>
</template>

<script>
	import searchBar from "@/components/basic/search-bar.vue";
	export default {
		components: {
			searchBar,
		},
		data() {
			return {
				activityId: '',
				hotList: [],
				current: 1,
				size: 30,
				status: false,
				
				searchName:'',
			}
		},
		onLoad(options) {
			this.activityId = options.activityId;
			this.getRankList();
		},
		onReachBottom() {
			if (this.hotList.length < this.current * this.size) {
				this.status = true;
			} else {
				this.current += 1;
				this.getRankList();
			}
		},
		methods: {
			home() {
				uni.navigateTo({
					url: "/pages/activityList/home/home?activityId=" + this.activityId,
				})
			},
			getRankList() {
				let params = {
					activityId: this.activityId,
					size: this.size,
					current: this.current,
					type:0,//选手排名
				}
				if (!this.$u.test.isEmpty(this.searchName)) {
					params.nickName=this.searchName
				}
				this.$u.api.activity.rankList(params).then(res => {
					this.hotList = [...this.hotList, ...res.records];
				})
			},
			//跳转需要带惨方法
			navWithParm(id) {
				uni.navigateTo({
					url: "/pages/activityList/activity/authorBoost?activityId=" + this.activityId +
						"&receiverId=" + id,
				})
			},
			onSearch(value) {
				this.searchName=value
				console.log(this.searchName);
				this.hotList=[]
				this.getRankList()
			}
		}
	}
</script>

<style>

</style>
