<template>
	<view>
		<view v-if="pagesNum > 1">
			<u-navbar title="获奖名单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
		</view>
		<view v-else>
			<u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff" title="获奖名单">
				<view class="nav-left flex" slot="left" @click="toActivity">
					<u-icon name="arrow-left" size="20" color="#333"></u-icon>
				</view>
			</u-navbar>
		</view>
		<view class="list">
			<view v-for="(item,index) in list" :key="index" class="list-view">
				<view class="award flex">
					<view class="award-avatar">
						<image :src="item.avatar" mode=""></image>
					</view>

					<view class="award-nickNames">
						<view class="nickName"><text>{{item.nickName}}</text>
							<view v-if="item.awardName == '一等奖'" class="awardName">
								<image src="../static/activity/one.png" mode="">
								</image>
								<text style="color: #FFD225;">{{item.awardName}}</text>
							</view>
							<view v-else-if="item.awardName == '二等奖'" class="awardName">
								<image src="../static/activity/two.png" mode="">
								</image>
								<text style="color: #94CBEC;">{{item.awardName}}</text>
							</view>
							<view v-else-if="item.awardName == '三等奖'" class="awardName">
								<image src="../static/activity/three.png" mode=""></image>
								<text style="color: #F2B47A;">{{item.awardName}}</text>
							</view>
						</view>
						<view class="prize">中奖码：{{item.code}}</view>
						<view v-if="item.prizeType =='COIN'"  class="ells-one prize">盲豆 x{{item.value}}</view>
						<view v-else class="ells-one prize">{{item.prizeTitle}}</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 中奖 -->
		<u-popup :show="activityShow" mode="center" round="11" @close="close" :closeable="true" overlayOpacity="0.5"
			@touchmove.prevent.stop>
			<view class="activityShow-wrap">
				<view class="activityShow-wrap-award">
					<view class="award">恭喜你 获得{{listData.awardName}}</view>
					<view v-if="listData.prizeType && listData.prizeType =='COIN'"  class="award-name ells-one">盲豆 x{{listData.value}}</view>
					<view v-else class="award-name ells-one">{{listData.prizeTitle}}</view>
				</view>
				<view class="activityShow-wrap-rela">
					<image :src="listData.prizePicUrl" mode="aspectFit" class="relaimg"></image>
					<!-- <image src="../static/activity/effectstwo.png" mode="aspectFit" class="relaimg"></image> -->
				</view>
				<view v-if="listData.prizeType && listData.prizeType !='COIN'" class="activityShow-wrap-library">
					奖品已放入我的奖品库</view>
				<view v-else class="activityShow-wrap-library">奖品已放入“我的盲豆”</view>
				<view class="flex activityShow-wrap-btn">
					<button @click="toPrize()" v-if="listData.prizeType && listData.prizeType !='COIN'" class="btnone"
						style="">前往查看</button>
					<button @click="toCore()" v-else class="btnone">去兑换商品</button>

					<button @click="close()" class="btntwo" style="">关闭</button>

				</view>

			</view>
		</u-popup>

		<!-- 未中奖 -->
		<u-popup :show="closeShow" mode="center" round="17" @close="close" :closeable="true" overlayOpacity="0.5"
			@touchmove.prevent.stop>
			<view class="choiceShow-wrap">
				<view class="choiceShow-wrap-award">
					<view></view>
					<view class="awardone">
						很遗憾, 您未中奖
					</view>
					<view  class="awardtwo">
						欢迎继续参与其他抽奖, 好运就在你身边
					</view>
				</view>
				<button @click="close()" class="btntwo">确定</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import $http from '@/utils/request.js'
	export default {
		data() {
			return {
				list: [],
				marketingId: '',
				closeShow: false,
				activityShow: false,
				listData: {},
				pagesNum: "",
			}
		},
		onLoad(opthios) {
			this.marketingId = opthios.id
			this.pageList()
		},
		onShow() {
			this.pagesNum = getCurrentPages().length
		},
		methods: {
			toActivity() {
				uni.reLaunch({
					url: `/pages/activity/index?triggerStatus=1`
				})
			},
			toCore() {
				uni.reLaunch({
					url: '/pages/core/index'
				})
			},

			pageList() {
				this.pageNum = 1
				this.list = []
				this.getList()
			},
			getList() {
				uni.showLoading({
					title: '加载中'
				});
				this.loading = true
				$http.post(`/api/v1/mp/user/marketing/hit/prize/list`, {
					marketingId: this.marketingId,
				}).then(res => {
					uni.hideLoading();
					this.loading = false
					if (res.code == 0) {
						res.rows.forEach(item => {
							let prizePicUrlArr = item.prizePicUrl.split(',')
							item.prizePicUrl = env.filePublic + prizePicUrlArr[0] + '?imageView2/2/w/170'
							item.avatar = env.filePublic + item.avatar + '?imageView2/2/w/170'
						})
						this.list = this.list.concat(res.rows)
					}
				}).catch(() => {
					uni.hideLoading();
					this.loading = false
				});

				try {
					const value = uni.getStorageSync(this.marketingId);
					if (value) {

					} else {
						this.successFail()
						uni.setStorageSync(this.marketingId, this.marketingId);
					}
				} catch (e) {
					// error
				}

			},
			close() {
				this.closeShow = false
				this.activityShow = false
			},

			toPrize() {
				if (this.listData.prizeType != 'GOODS') {
					uni.navigateTo({
						url: '/packagePrize/prize/index?coupon=1'
					})
				}else{
					uni.navigateTo({
						url: '/packagePrize/prize/index?coupon=0'
					})
				}

			},
			successFail() {
				this.listData = {}
				$http.post(`/api/v1/mp/user/marketing/hit/prize/isHit/${this.marketingId}`, {}).then(
					res => {
						if (res.code == 0 && res.data && res.data.isHit == 1) {
							let prizePicUrlArr = res.data.prizePicUrl.split(',')
							res.data.prizePicUrl = env.filePublic + prizePicUrlArr[0] + '?imageView2/2/w/170'
							this.listData = res.data
							this.activityShow = true
						}
						if (res.code == 0 && res.data && res.data.isHit == 0) {
							this.closeShow = true
						}
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {

		&-view {
			padding: 10rpx 20rpx;

			.award {
				justify-content: flex-start;
				border-radius: 22rpx;
				width: 100%;
				height: 108px;
				background-color: #fff;
				overflow: hidden;

				&-avatar {
					padding: 50rpx 32rpx;

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

				&-nickNames {
					flex: 1;
					padding: 30rpx 0;

					.prize {
						line-height: 46rpx;
						color: #666666;
					}

					.nickName {
						line-height: 60rpx;
						font-size: 30rpx;

						.awardName {
							display: inline-block;

							image {
								width: 40rpx;
								height: 36rpx;
								margin-left: 30rpx;
								vertical-align: -10%;
							}

							text {
								display: inline-block;
								font-size: 26rpx;
								line-height: 26rpx;
							}
						}

					}
				}
			}
		}

		// 设置ios刘海屏底部横线安全区域
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	.activityShow-wrap {
		border-radius: 22rpx;
		overflow: hidden;
		width: 600rpx;
		height: 650rpx;

		&-rela {
			position: relative;

			.relaimg {
				margin-top: 130rpx;
				height: 250rpx;
				position: absolute;
				top: -260rpx;
				left: 125rpx;
				width: 350rpx;
			}
		}

		&-award {
			width: 100%;
			height: 320rpx;
			text-align: center;
			background: linear-gradient(0deg, #FF866B, #FFAE64);
			box-shadow: 0px 6px 6px 0px rgba(26, 109, 190, 0.1);
			text-align: center;

			.award {
				font-size: 40rpx;
				color: #fff;
				font-weight: bold;
				line-height: 80rpx;
				padding-top: 50rpx;

				&-name {
					font-size: 30rpx;
					color: #fff;
					font-weight: bold;
				}
			}
		}

		&-library {
			text-align: center;
			margin-top: 110rpx;
			font-size: 24rpx;
			color: #999;
			line-height: 80rpx;
		}

		&-btn {
			// padding-bottom: 40rpx;
			padding: 10rpx 20rpx 40rpx;

			.btnone {
				width: 252rpx;
				height: 84rpx;
				font-size: 34rpx;
				line-height: 82rpx;
				background-color: #fff;
				color: #F8832C;
				border: 2rpx solid #F8832C;
			}

			.btntwo {
				width: 252rpx;
				height: 82rpx;
				font-size: 34rpx;
				line-height: 82rpx;
				background-color: #F8832C;
				color: #fff;
				border: 2rpx solid #F8832C;
			}
		}
	}

	.choiceShow-wrap {
		border-radius: 22rpx;
		overflow: hidden;
		width: 600rpx;
		height: 500rpx;
		&-award {
			width: 100%;
			height: 290rpx;
			text-align: center;
			font-weight: bold;
			background: linear-gradient(0deg, #FF866B, #FFAE64);
			box-shadow: 0px 6px 6px 0px rgba(26, 109, 190, 0.1);
			text-align: center;
			.awardone {
				padding-top: 70rpx; color: #fff;font-size: 40rpx;
			}
			.awardtwo {
				padding-top: 60rpx;color: #fff;font-size: 30rpx;
			}
		}
		.btntwo {
			width: 252rpx;
			height: 82rpx;
			font-size: 34rpx;
			line-height: 82rpx;
			background-color: #F8832C;
			color: #fff;
			margin-top: 50rpx;
		}

	}
</style>
