<template>
	<!-- 礼品弹窗 -->
	<uni-popup ref="appPopup" type="center" :is-mask-click="false">
		<view class="appPopup-mask">
			<image class="tipimg" src="https://cos.his.cdwjyyh.com/fs/20250909/d5736027b6ac4255bfa2415cf400969c.png"></image>
			<image class="close_icon" src="https://cos.his.cdwjyyh.com/fs/20250909/c8a5a9f34e5a4bd786f9fd2a380508dd.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)"> -->
					<view class="goodsitem" v-for="(item,index) in products" :key="index" >
						<image class="bg" src="https://cos.his.cdwjyyh.com/fs/20250909/13630e9a4a054fa487e5c50b7d5ab1d2.png" mode="widthFix"></image>
						<image class="img" :src="item.imageUrl" mode="aspectFill"></image>
						<view class="goodsitem-name ellipsis">{{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="x-bc" style="padding: 0 24rpx;">
					<!-- <view class="appPopup-btn" style="margin-right: 12px;" @click="navTo('/pages_user/user/storeOrder?status=0')">查看芳华币订单</view> -->
					<view style="width: 100%;display: flex;flex-direction: column;align-items: center;">
						<view class="app-tips">兑换提示：请前往芳华未来APP兑换</view>
						<view class="appPopup-btn" @click="navTo('/pages_course/appDownload')">如何下载芳华未来APP?</view>
					</view>
				</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()	
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
				// 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) {
				uni.navigateTo({
					url: '/pages/shopping/productList?cateId=320&pid=321&isCourse=1'
				})
				// 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;
	}
	.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;
			z-index: 99;
		}
		.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;
		}
		&-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;
		}
	}
	.app-tips {
		width: 560rpx;
		margin: 0 32rpx 32rpx 0;
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #333;
		padding: 10rpx;
		background-color: #fefbea;
	}
	.my-integral {
		margin: 24rpx 0;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 28rpx;
		color: #222222;
		text {
			color: #FF5C03;
		}
	}
	.appPopup-tips {
		margin-top: 32rpx;
	}
</style>