<template>
	<!-- 参与用户 和 中奖名单 -->
	<!-- 两个页面 两种情况 -->
	<view class="PartakeUser">
		<view class="PartakeUsercount" v-if="type==1">已有{{counts}}人参与抽奖</view>
		<view class="PartakeUsercount" v-if="type==2">已有{{counts}}人抽中<text class="text">{{jpname}}</text></view>
		
		<view class="usercardlist">
			<view class="usercard flex ali-c" v-for="(item,index) in userinfoList" :key="index">
				<image class="usertxs" :src="item.avatar" mode=""></image>
				<view class="usermgs flex1">
					<view class="username">{{item.nickname}}</view>
					<view class="userid">id号{{item.user_id}}号</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {LotteryUserInfo} from "@/utils/api/LuckDraw.js";
	export default {
		data(){
			return {
				type:1,//1 参与用户 2中奖名单
				lottery_id:"",//活动id
				grade:"",
				userinfoList:[],//用户列表
				page:0,
				istoload:true,//瀑布流加载开关
				jpname:"",//奖品名称
				counts:0,//参与人数 以及中奖人数统计
			}
		},
		onLoad(options) {
			this.type = options.type;
			switch (options.type) {
			  case "1":
				//代码块
				uni.setNavigationBarTitle({
				  title: "参与用户"
				})
				break;
			  case "2":
				//代码块
				uni.setNavigationBarTitle({
				  title: "中奖名单"
				})
				break;
			  default:
			  //默认代码块
			}
			 
			 
			 this.grade = options.grade;
			 this.lottery_id = options.lottery_id;
			 this.LotteryUserInfocode();
			 this.jpname = options.jpname;//奖品名称
		},
		onReachBottom() {
			// if(this.istoload){
			// 	this.LotteryUserInfocode();
			// }
		},
		methods:{
			//获取名单 以及参与名单
			async LotteryUserInfocode(){
				this.page++;
				let res = await LotteryUserInfo({
					lottery_id:this.lottery_id,
					type:this.type,
					grade:this.grade,
					limit: 10,
					page: this.page
				});
				
				if(res.code==0){
					
					if(res.data){
						this.counts = res.data.userCount;//统计人数
						if(res.data.userinfo.length!=0){
							this.userinfoList = [...this.userinfoList,...res.data.userinfo];
							
						}else{
							this.$api.msg("没有更多了哦~");
							this.istoload = false;
						}
					}else{
						this.$api.msg("没有更多了哦~");
					}
					
				}else{
					this.$api.msg(res.msg);
				}
			}
		}
	}
</script>

<style lang="scss">
	@import  "./PartakeUser.scss"
</style>
