<template>
	<view class="activity">
		<u-navbar leftIconSize="0" :placeholder="true" bgColor="#ffffff">
			<view slot="left" style="font-size: 32rpx;">免费抽奖</view>
		</u-navbar>
		<view class="status" slot="left">
			<u-tabs @change="changeTab" :scrollable="false" :list="statusArr" lineWidth="30" lineHeight="3"
				lineColor="#E96737" :activeStyle="{
									color: '#E96737',
									transform: 'scale(1)',
									width: '150rpx',
									
								}" :inactiveStyle="{
									color: '#999999',
									transform: 'scale(1)',
									width: '150rpx'
								}" itemStyle="padding-left: 11px; padding-right: 11px; height: 44px;text-align: center;  ">
			</u-tabs>
		</view>
		<view class="list">
			<view v-for="(item,index) in list" :key="index" class="list-view">
				<view class="list-view-slot">
					<view @click="toRecord(item)">
						<view>
							<image :src="item.picUrl" mode="" class="list-view-slot-img"></image>
						</view>
						<view class="list-view-slot-bor">
							<view  class="list-view-slot-bor-title">
								<view class="time bor-title">{{item.title}}</view>
								<view v-if="item.status.value == 2" class="time" >开始时间：{{ $parseTime(item.startTime, '{y}-{m}-{d} {h}:{i}:{s}')}}</view>
								<view v-else class="time" >开奖时间：{{ $parseTime(item.endTime, '{y}-{m}-{d} {h}:{i}:{s}')}}</view>
							</view>
							<view class="details">
								<button class="details-button" v-if="item.status.value == 3" >查看详情</button>
								<button class="details-buttonTwo" v-else-if="item.isHit == 0" >未中奖</button>
								<button class="details-buttonTwo" v-else-if="item.isHit == 1">已中奖</button>
								<button class="details-buttonTwo" v-else >即将开始</button>
							</view>
						</view>
					</view>
				</view>

			</view>

			<view class="flex empty" v-if="!list.length && !loading">
				<u-empty text="活动为空" mode="order" />
			</view>
		</view>
		<custom-tab-bar :activeValue="'activity'" />
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import $http from '@/utils/request.js'
	export default {
		data() {
			return {
				list: [],
				statusArr: [{
					name: '参与抽奖'
				}, {
					name: '已开奖',
				},{disabled: true},{disabled: true},{disabled: true}],
				triggerStatus: 0,
			}
		},
		onLoad(opthios) {
			if(opthios.triggerStatus){
				this.triggerStatus = opthios.triggerStatus
			}
		},
		onShow() {
			this.pageList()
		},
		methods: {
			toRecord(item){
				if(!uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/login/index'
					})
					return
				}
				uni.navigateTo({
					url: item.status.value == 4 ?`/packageOperate/activity/record?id=${ item.id }`:`/packageOperate/activity/index?id=${ item.id }`
				})
			},
			changeTab(e) {
				if (e.index == 0) {
					this.triggerStatus = 0
				} else if (e.index == 1) {
					this.triggerStatus = 1
				}
				this.pageList()
			},
			pageList() {
				this.pageNum = 1
				this.list = []
				this.getList()
			},
			getList() {
				uni.showLoading({
					title: '加载中'
				});
				this.loading = true
				$http.post(`/api/v1/mp/user/marketing/list?pageNum=${ this.pageNum }&pageSize=20`, {
					triggerStatus: this.triggerStatus,
				}).then(res => {
					uni.hideLoading();
					this.loading = false
					if (res.code == 0) {
						res.rows.forEach(item => {
							let picUrlArr = item.picUrl.split(',')
							item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/750'
							item.status = JSON.parse(item.status)
						})
						this.total = res.total
						this.list = this.list.concat(res.rows)
					}
				}).catch(() => {
					uni.hideLoading();
					this.loading = false
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.activity {
		width: 100%;
		height: 100%;
		// 设置ios刘海屏底部横线安全区域
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
	.status {
		width: 100%;
		position: fixed;
		z-index: 100;
		background-color: #FFFFFF;
		box-shadow: 0 5rpx 5rpx #ececec;
	}
	.list {
		padding: 120rpx 20rpx 100rpx;
		&-view {
			text-align: center;
			height: 530rpx;
			&-slot {
				background-color: #FFFFFF;
				// margin-bottom: 20rpx;
				border-radius: 22rpx;
				&-img {
					 width: 100%;
					 height: 370rpx;
					 border-radius: 22rpx 22rpx 0 0;
					
				}
				&-bor {
					line-height: 50rpx;
					width: 700rpx;
					height: 120rpx;
					margin: 0 auto;
					padding:10rpx 20rpx 0 20rpx;
					border-radius: 0 0 22rpx 22rpx ;
					&-title {
						text-align: left; float: left;
						.time {
							color: #333333;
						}
						.bor-title {
							font-size: 34rpx;
						}
					}
					.details {
						float: right;
						.details-button{
							width: 200rpx;
							height: 72rpx;
							line-height: 72rpx;
							background-color: #F9822C;
							color: #fff;
							margin-top: 18rpx;
							font-size: 30rpx;
							border-radius: 36rpx;
						}
						.details-buttonTwo{
							width: 200rpx;
							height: 72rpx;
							line-height: 72rpx;
							background-color: #BBBBBB;
							color: #fff;
							margin-top: 18rpx;
							font-size: 30rpx;
							border-radius: 36rpx;
						}
					}
					
				}
			}
		}

	}

	.empty {
		height: 60vh;
	}
</style>
