<template>
	<!-- 活动列表  参与抽奖  发起抽奖 中奖记录 -->
	<!-- 三个页面 写在一块 通过传参区分 -->
	<view class="LuckList">
		
		<!-- 参与抽奖 发起抽奖 -->
		<view class="listdatas" v-if="type==0 || type==1  || type==2 || type==3">
			<view @tap="tozjxq(item.lottery_id)"  class="Luck_card flex " v-for="(item,index) in dataLotteryList" :key="index">
				<image class="thumbnail" :src="staticUrl+item.prize[0].img" mode=""></image>
				<view class="Luck_card_r flex1">
					<view class="titlebox flex jus-b">
						<view v-if="item.type == 1" class="onestatic">抽奖正在进行中</view>
						<view v-else-if="item.type == 2" class="onestatic">已开奖</view>
						<view v-else-if="item.type == 0" class="onestatic">已停止抽奖</view>
						<view v-else class="onestatic">状态获取中</view>
						<!-- 活动已结束 -->
						<!-- 抱歉您未抽中奖品 -->
						<view class="twostatic">满{{item.pepole_num}}人自动开奖</view>
					</view>
					<view class="Prizelist">
						<view class="Prizeitem oneline" v-for="(item1,index1) in item.prize" :key="index1">{{numberarr[index1]}} 等奖：{{item1.title}}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- edns -->
		
		
		<!-- 中将记录 -->
		<view class="listdatas" v-if="type==4">
			<view @tap="tozjxq(item.lottery_id)" class="Luck_card flex ali-c" v-for="(item,index) in dataLotteryList" :key="index">
				<image class="thumbnail" :src="staticUrl+item.img" mode=""></image>
				<view class="Luck_card_r flex1">
					<view class="titlebox flex jus-b">
						<view class="onestatic">恭喜您抽中{{numberarr[item.grade-1]}}等奖</view>
						<!-- 活动已结束 -->
						<!-- 抱歉您未抽中奖品 -->
						<view class="twostatic">活动已结束</view>
					</view>
					<view class="Prizelist">
						<view class="Prizeitem oneline">{{item.title}} </view>
						<view class="Prizesysbtn flex jus-b ali-c">
							<!-- <view class="times">3月6日 10：20</view> -->
							<view class="times oneline" v-if="item.type == 0" >中奖时间:{{item.start_time}}</view>
							<view class="times oneline" v-if="item.type == 1" >领奖时间:{{item.end_time}}</view>
							<view class="btns flex">
								<view class="sysbtns" v-if="item.type == 0"  :data-goods_id="item.goods_id" :data-win_id="item.win_id" catchtap="goShopping">点击领取</view>
								<view class="sysbtns" v-if="item.type == 1" >已领奖</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		

	</view>
</template>

<script>
	import {LotteryList,slotuserList} from "@/utils/api/LuckDraw.js";
	export default {
		data(){
			return {
				numberarr:["一","二","三","四","五","六","七","八","九","十"],
				type:"",
				page:0,
				dataLotteryList:[],
				isbottomload:true,//瀑布流开关 true 加载  false 关闭
			}
		},
		computed: {
			staticUrl () {//静态资源地址
				return this.$store.state.staticUrl;
			}
		},
		//瀑布流
		onReachBottom() {
			if(this.isbottomload){
				this.getLotteryList();
			}
		},
		onLoad(opdata) {
			let type = opdata.type;
			this.type = type;
			
			//设置动态标题
			//规则略
			
			switch(type) {
				case "0":
				    //代码块
					uni.setNavigationBarTitle({
						title:"关闭的抽奖"
					})
				    break;
				case "1":
			        //代码块
					uni.setNavigationBarTitle({
						title:"发起的抽奖"
					})
			        break;
				case "2":
			        //代码块
					uni.setNavigationBarTitle({
						title:"开奖记录"
					})
			        break;
				case "3":
					//代码块
					uni.setNavigationBarTitle({
						title:"参与的抽奖"
					})
					break;
				case "4":
					//代码块
					uni.setNavigationBarTitle({
						title:"中奖记录"
					})
					break;
				
				default:
			        //默认代码块
			} 
			
			//获取列表
			this.getLotteryList();
			
		},
		methods:{
			//进入详情
			todetailes(){
				
			},
			//查看活动详情
			tozjxq(id){
				uni.navigateTo({
					url:"/pages/LuckDraw/LuckyDetails/LuckyDetails?id="+id,
				})
			},
			async getLotteryList(){
				this.page++;
				
				let res = {};
				
				if(this.type!=3 && this.type!=4){
					res = await LotteryList({
						limit: 10,
						page:this.page,
						type: this.type,
					});
				}else{
					res = await slotuserList({
						limit: 10,
						page:this.page,
						type: this.type,
					});
				}

				if(res.code==0){
					
					if(res.data.length!=0){
						this.dataLotteryList = [...this.dataLotteryList,...res.data];
					}else{
						
						this.isbottomload = false;//关闭
						this.$api.msg("没有更多了~");
					}
					
				}else{
					this.$api.msg(res.msg);
				}
				
			},
			//领取奖品
			goShopping(e){
			    let goods_id = e.currentTarget.dataset.goods_id;
			    let win_id = e.currentTarget.dataset.win_id;
			    uni.navigateTo({
			      url: '/pages/product/product?id=' + goods_id + "&win_id=" + win_id + "&cate_id=0",
			    })
		  },
		}
		
	}
</script>

<style lang="scss">
	@import "./LuckList.scss";
</style>
