<template>
	<view>
		<u-navbar title="兑奖" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
		<view class="process">
			<view class="flex box-wrap">
				<view class="flex box">
					<image :src="picUrlArr[0]" mode=""></image>
					<view class="box-title">
						<view class="txt">{{ info.title }}</view>
						<view class="id">序列号：{{ info.serialNo }}</view>
					</view>
				</view>
			</view>
			<view class="flex btn-wrap">
				<view class="btn" @click="toChoice">立即刮开兑奖</view>
				<!-- <view class="btn" @click="put">暂不兑奖</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import $http from '@/utils/request.js'
	export default {
		data() {
			return {
				id: '',
				info: {},
				picUrlArr: []
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getDetail()
		},
		methods: {
			getDetail() {
				uni.showLoading({
					title: '加载中'
				});
				$http.post('/api/v1/mp/user/ticket/query', {
					orderId: this.id,
				}).then(res => {
					if (res.code == 0) {
						uni.hideLoading();
						this.info = res.data
						let picUrlArr = res.data.picUrl.split(',')
						picUrlArr.forEach(item => {
							this.picUrlArr.push(env.filePublic + item + '?imageView2/2/w/750')
						})
					} else if (res.code == 1022) {
						let time = setInterval(() => {
							uni.showLoading({
								title: '加载中'
							});
							$http.post('/api/v1/mp/user/ticket/query', {
								orderId: this.id,
							}).then(ele => {
								if (ele.code == 0) {
									uni.hideLoading();
									clearInterval(time)
									this.info = ele.data
									let picUrlArr = ele.data.picUrl.split(',')
									picUrlArr.forEach(item => {
										this.picUrlArr.push(env.filePublic + item)
									})
								}
							})
						}, 1000)
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},

			put() {
				uni.navigateBack({
					delta: 1
				})
			},

			toChoice() {
				uni.redirectTo({
					url: `/packagePrize/choice/index?id=${ this.info.ticketId }&type=onLine`
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.process {
		width: 100%;
		min-height: calc(100vh - 44px - var(--status-bar-height));
		background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/openprize_bg.png) center center;
	}

	.box-wrap {
		padding: 140rpx 0 120rpx;

		.box {
			flex-direction: column;
			justify-content: flex-start;
			position: relative;
			width: 540rpx;
			height: 820rpx;
			background-color: rgba(255, 255, 255, 0.75);
			border-radius: 10rpx;

			image {
				width: 480rpx;
				height: 630rpx;
				padding-top: 40rpx;
			}

			&-title {
				margin-top: 20rpx;

				.txt {
					text-align: center;
					font-size: 36rpx;
					font-weight: bold;
					line-height: 50rpx;
					margin-bottom: 16rpx;
				}

				.id {
					line-height: 40rpx;
					text-align: center;
					color: #888787;
				}
			}
		}
	}

	.btn-wrap {
		flex-direction: column;

		.btn {
			width: 400rpx;
			height: 80rpx;
			font-size: 36rpx;
			line-height: 80rpx;
			border-radius: 20rpx;
			background-color: rgba(235, 112, 9, 100);
			color: #FFFFFF;
			text-align: center;
			margin-bottom: 40rpx;
		}

		.btn:last-child {
			background-color: #FFFFFF;
			color: rgba(235, 112, 9, 100);
			border: 1px solid rgba(235, 112, 9, 100);
		}
	}
</style>
