<template>
	<!-- app回答正确弹窗 -->
	<uni-popup ref="appPopup" type="center" :is-mask-click="false">
		<view class="appPopup-mask">
			<image class="tipimg" src="@/static/images/course_answer_img.png" mode="aspectFill"></image>
			<image class="close_icon" src="@/static/images/tc_close_icon.png" mode="aspectFill" @click="closePop"></image>
			<view class="appPopup-box">
				<view class="appPopup-title">恭喜你，<text style="color: #FF5C03;">回答正确</text></view>
				<view>百种好礼等你兑换</view>
				<view class="goodslist">
					<view class="goodsitem" v-for="(item,index) in products" :key="index" @click="handleItem(item,index)">
						<image class="bg" src="/static/Subtract_bg100@2x.png" mode="widthFix"></image>
						<image class="img" :src="item.imageUrl" mode="aspectFill"></image>
						<view class="goodsitem-name textOne">{{item.productName}}</view>
						<view class="goodsitem-integral">
							<text class="goodsitem-integral-num">{{item.requiredPoints}}</text>
							<text>芳华币</text>
						</view>
						<view class="goodsitem-price">原价{{item.otPrice&&item.otPrice.toFixed(2)}}元</view>
					</view>
				</view>
				<view class="changebtn" @click="getInfo">换一批</view>
				<view class="progress">
					<text>奖品兑换进度</text><text class="num">{{goodsInfo.exchangeProgress || 0}}%</text>
					<progress style="margin-top: 30rpx;" active-color="#FAA97F" backgroundColor="#F5F7FA" border-radius="12" :percent="goodsInfo.exchangeProgress" stroke-width="12"></progress>
				</view>
				<view class="my-integral">我的芳华币：<text>{{goodsInfo.currentPoints || 0}}</text> </view>
				<view class="appPopup-btn" @click="goApp">{{goodsInfo.availableCoins}}芳华币已到账，去兑换</view>
				<!-- <view class="appPopup-tips">放弃芳华币，领取红包></view> -->
			</view>
		</view>
	</uni-popup>
</template>

<script>
	import { getCourseIntegralGoods } from "@/api/course.js"
	export default {
		data() {
			return {
				goodsInfo: {},
				products:  []
			}
		},
		methods: {
			openPop() {
				this.$refs.appPopup.open("center")
				this.getInfo()
			},
			closePop() {
				this.$refs.appPopup.close()
			},
			goApp() {
				this.$refs.appPopup.close()
				this.postMessage({
					isFullscreen: false,
					login: 1,
					productId: '',
					pagesUrl:'/pages/user/integral/integralGoodsList'
				})
			},
			//app礼品列表
			getInfo() {
				uni.showLoading({
					title: '加载中'
				})
				getCourseIntegralGoods().then(res=>{
					uni.hideLoading()
					if(res.code == 200) {
						this.goodsInfo = res.data
						this.products = res.data && res.data.products? res.data.products:[]
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(()=>{
					uni.hideLoading()
				})
			},
			postMessage(data) {
				this.uniReady(() => {
					uni.webView.postMessage({
					    data: data
					});  
				})	
			},
			uniReady(callback) {
			  if (uni.webView) {
				callback()
			  } else {
				document.addEventListener('UniAppJSBridgeReady', callback, { once: true })
			  }
			},
			handleItem(item,index) {
				this.postMessage({
					isFullscreen: false,
					login: 1,
					productId: item.productId,
					pagesUrl:''
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@mixin u-flex($flexD, $alignI, $justifyC) {
		display: flex;
		flex-direction: $flexD;
		align-items: $alignI;
		justify-content: $justifyC;
	}
	.textOne {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.num {
		margin-left: 12rpx;
		font-family: DINPro, DINPro;
		font-size: 40rpx;
	}
	.appPopup-mask {
		margin-top: -88rpx;
		width: 670rpx;
		@include u-flex(column, center, center);
		.tipimg {
			height: 206rpx;
			width: 206rpx;
		}
		.close_icon {
			height: 48rpx;
			width: 48rpx;
			position: absolute;
			top: 34rpx;
			right: 20rpx;
		}
		.appPopup-box {
			width: 670rpx;
			padding-bottom: 32rpx;
			background: linear-gradient( 180deg, #FFEBBD 0%, #FFFFFF 9%, #FFFFFF 100%);
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			overflow: hidden;
			margin-top: -103rpx;
			padding-top: 103rpx;
			box-sizing: border-box;
			font-family: PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #757575;
			text-align: center;
		}
		.appPopup-title {
			margin-bottom: 10rpx;
			font-family: PingFang SC;
			font-weight: 600;
			font-size: 40rpx;
			color: #222222;
		}
	}
	.goodslist {
		margin-top: 58rpx;
		padding: 24rpx 10rpx;
		@include u-flex(row, center, space-evenly);
	}
	.bg {
		width: 100%;
		height: 100%;
		position: absolute;
		bottom: 0;
		left: 0;
		z-index: -1;
	}
	.goodsitem {
		flex: 1;
		max-width: 200rpx;
		min-height: 124rpx;
		border-radius: 10rpx;
		@include u-flex(column, center, flex-start);
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 22rpx;
		color: #999999;
		position: relative;
		z-index: 2;
		.img {
			width: 153rpx;
			height: 126rpx;
			margin-top: -44rpx;
			border-radius: 10rpx;
		}
		&-name {
			width: 100%;
			padding: 8rpx 14rpx;
			text-align: center;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #222222;
			box-sizing: border-box;
			word-break: break-all;
		}
		&-integral {
			min-width: 80%;
			padding-bottom: 16rpx;
			box-sizing: border-box;
			font-family: PingFang SC;
			font-weight: 400;
			font-size: 22rpx;
			color: #FF5C03;
			border-bottom: 2px #999999 dotted;
			&-num {
				font-family: DINPro, DINPro;
				font-weight: 500;
				font-size: 36rpx;
			}
		}
		&-price {
			padding: 10rpx 0;
		}
	}
	.appPopup-btn {
		width: 560rpx;
		height: 84rpx;
		margin: 0 auto;
		background: #FF5C03;
		border-radius: 42rpx 42rpx 42rpx 42rpx;
		@include u-flex(row, center, center);
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
	}
	.changebtn {
		width: 152rpx;
		height: 64rpx;
		margin: 0 auto;
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		border: 1rpx solid #FF5C03;
		@include u-flex(row, center, center);
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FF5C03;
	}
	.progress {
		padding: 0 90rpx;
		margin-top: 40rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #222222;
	}
	::v-deep {
		.uni-progress-bar, .uni-progress-inner-bar {
			border-radius: 6px;
		}
	}
	.my-integral {
		margin: 32rpx 0;
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #222222;
		text {
			color: #FF5C03;
		}
	}
	.appPopup-tips {
		margin-top: 32rpx;
	}
</style>