<template>
	<view>
		<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="盲票详情"></u-navbar>
		<view class="detail">
			<view class="detail-top">
				<u-swiper :list="picUrlArr" height="320" :indicator="true" :circular="true"></u-swiper>
			</view>
			<view class="flex detail-info">
				<view class="detail-info__left">
					<text class="title">{{ info.title }}</text>
					<view class="flex num">
						<u-icon name="gift" size="25" color="#EB7009"></u-icon>
						<text>100%抽中，商品价值10元-10万元</text>
					</view>
					<view class="tip">图片仅供参考，请以实物为准</view>
				</view>
				<view class="detail-info__right">
					<text class="money">￥{{ $numberFormat(info.salePrice) }}</text>
					<text>销量 {{ info.saleQty }}</text>
				</view>
			</view>
			<view class="detail-goods">
				<view class="detail-goods-title">可获得奖品</view>
				<view class="detail-goods-list">
					<navigator :url="`/pages/prizeGoods/detail?id=${ item.prizeId }`" class="detail-goods-list-item"
						hover-class="navigator-hover" v-for="(item, index) in prizeList" :key="index">
						<view class="detail-goods-list-item__value">
							<view class="flex image-wrap">
								<image :src="item.picUrl" mode="scaleToFill"></image>
							</view>
							<view class="info">
								<text>{{ item.title }}</text>
								<text>价值：￥{{ $numberFormat(item.value) }}</text>
								<text>概率：{{ item.hitRate }}%</text>
							</view>
							<view class="name">{{ item.name }}</view>
						</view>
					</navigator>
				</view>
			</view>
		</view>
		<view class="footer-fixed">
			<view class="flex btn">
				<button type="default" @click="exchange">10元 立即开刮</button>
			</view>
		</view>

		<pay-popup :pay-show="payShow" :pay-info="payInfo" @close="close" @success="toProcess" />
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import $http from '@/utils/request.js'
	import PayPopup from '../../components/pay-popup/pay-popup.vue'
	export default {
		components: {
			PayPopup
		},
		data() {
			return {
				boxId: '',
				picUrlArr: [],
				info: {},
				prizeList: [],

				payShow: false,
				payInfo: {}
			};
		},
		onLoad(opthios) {
			this.getDetail(opthios.id)
		},
		methods: {
			getDetail(id) {
				uni.showLoading({
					title: '加载中'
				});
				$http.post('/api/v1/mp/channel/mall/ticket/detail', {
					boxId: id
				}).then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						this.info = res.data
						let picUrlArr = res.data.picUrl.split(',')
						picUrlArr.forEach(item => {
							this.picUrlArr.push(env.filePublic + item)
						})
						let prizeList = res.data.prizeList
						prizeList.forEach(item => {
							item.picUrl = env.filePublic + item.picUrl
						})

						this.prizeList = prizeList
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},

			close() {
				this.payShow = false
			},
			
			toProcess(id) {
				this.payShow = false
				uni.navigateTo({
					url: `/pages/process/index?id=${ id }`
				})
			},

			exchange() {
				let data = {
					couponIds: [],
					autoCoupon: 1,
					boxId: this.info.boxId,
					ticketId: this.info.ticketId,
					orderNum: 1
				}
				$http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
					if (res.code == 0) {
						let info = {
							...res.data,
							...this.info,
							picUrl: env.filePublic + res.data.picUrl,
						}
						this.payInfo = info
						this.payShow = true
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.detail {
		padding-bottom: 100rpx;

		&-top {
			margin-bottom: 20rpx;
		}

		&-info {
			justify-content: space-between;
			box-sizing: border-box;
			padding: 24rpx 16rpx;
			background-color: #fff;
			margin: 10rpx 10rpx 20rpx;
			border-radius: 10rpx;

			&__left {
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				text {
					line-height: 24rpx;
					display: inline-block;
				}

				.title {
					color: rgba(16, 16, 16, 100);
					font-size: 32rpx;
					line-height: 32rpx;
					font-weight: bold;
				}

				.num {
					color: $uni-text-color;
					font-size: 28rpx;
					justify-content: flex-start;
					margin: 20rpx 0;
				}

				.tip {
					font-size: 24rpx;
				}
			}

			&__right {
				display: flex;
				flex-direction: column;
				align-items: flex-end;
				justify-content: space-between;
				height: 162rpx;

				text {
					color: rgba(157, 157, 157, 100);
					font-size: 14px;
				}

				.money {
					font-size: 40rpx;
					font-weight: bold;
					line-height: 40rpx;
					font-weight: bold;
					color: $uni-text-color;
					margin-bottom: 40rpx;
				}
			}
		}

		&-sku {
			background-color: #fff;
			border-radius: 10rpx;
			margin: 10rpx 10rpx 20rpx;

			&-title {
				padding: 24rpx 16rpx 12rpx;
			}

			&-item {
				padding-bottom: 10rpx;

				view {
					padding-left: 50rpx;
					line-height: 50rpx;
				}
			}
		}

		&-goods {
			margin: 10rpx 10rpx 20rpx;

			&-title {
				margin-bottom: 20rpx;
			}

			&-list {

				&-item {
					position: relative;
					background-color: #FFFFFF;
					margin-bottom: 40rpx;
					border-radius: 10rpx;


					&__value {
						display: flex;
					}

					.image-wrap {
						width: 250rpx;
						height: 250rpx;
						margin-right: 30rpx;

						image {
							width: 180rpx;
							height: 120rpx;
						}
					}

					.name {
						position: absolute;
						line-height: 28rpx;
						padding: 6rpx 20rpx;
						color: #FFFFFF;
						background-color: $uni-bg-color;
					}

					.info {
						display: flex;
						flex-direction: column;
						font-size: 24rpx;

						text {
							margin-bottom: 10rpx;
						}

						text:first-child {
							font-size: 28rpx;
							margin-top: 24rpx;
							margin-bottom: 55rpx;
							font-weight: bold;
						}
					}
				}

				&-item:last-child {
					border: none;
				}
			}
		}
	}

	.footer-fixed {
		position: fixed;
		bottom: var(--window-bottom);
		left: 0;
		right: 0;
		z-index: 11;
		box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
		background: #fff;
		// 设置ios刘海屏底部横线安全区域
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.btn {
			padding: 20rpx 40rpx;

			/deep/ button {
				width: 100%;
				line-height: 60rpx;
				font-size: 28rpx;
				height: 60rpx;
				color: #fff;
				background-color: $uni-bg-color;
				border: none;
				border-radius: 100rpx;
			}
		}
	}
</style>
