<template>
	<view>
		<uni-popup ref="popup" type="center" :mask-click="false">
			<view class="giftpop y-f">
				<image class="close_icon" src="@/static/images/ad/close_icon.png" @click="closePop"></image>
				<image class="gift_img_head" src="@/static/images/ad/gift_img_head.png" mode="widthFix"></image>
				<view class="giftpop-body y-f">
					<view class="new_user_bg">
						<image style="width: 308rpx;height: auto;" src="@/static/images/ad/new_user_bg.svg"
							mode="widthFix"></image>
					</view>
					<image class="free_font_img" src="@/static/images/ad/free_font_img.svg" mode="widthFix"></image>
					<view class="y-f" :style="{display: haveGift ? 'flex':'none'}">
						<image class="gift-img" :src="giftImage" mode="aspectFill"></image>
						<text class="gift-name textOne">{{package.packageName}}</text>
					</view>
					<view class="y-f" :style="{display: !haveGift ? 'flex':'none'}">
						<image class="gift-img" src="/static/image/nodata.png" mode="aspectFill"></image>
						<text class="gift-name textOne">暂无礼品</text>
					</view>
				</view>
				<view class="giftpop-footer x-c" v-if='showBtn&&package.packageId'>
					<image class="buy_btn" src="@/static/images/ad/buy_btn.svg" mode="widthFix" @click="handClick(1)"></image>
					<image class="addfans_btn" src="@/static/images/ad/addfans_btn.svg" mode="widthFix" @click="handClick(2)"></image>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import { popAd } from '@/api/user.js'
	import {getConfigByKey} from '@/api/common.js'
	 import { gotoMiniProgram } from '@/utils/healthButlerPop.js'
	export default {
		data() {
			return {
				giftImage: '',
				package: {},
				showBtn: false,
				haveGift: true
			}
		},
		mounted() {
			this.getConfigByKey()
		},
		methods: {
			openPop() {
				this.$refs.popup.open('center')
				popAd().then(res=>{
					if(res.code == 200) {
						this.showBtn = true
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			closePop() {
				this.$refs.popup.close()
			},
			getConfigByKey(){
				let param = {key:"app.config"};
				getConfigByKey(param).then(
					res => {
						if(res.code==200){
							let data=JSON.parse(res.data);
							this.giftImage = data.giftImage
							this.package = data.fsPackage&&data.fsPackage.length > 0 ? data.fsPackage[0] : {}
							this.haveGift = this.package.packageId ? true : false
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				)
			},
			handClick(type) {
				if(type == 1) {
					uni.navigateTo({
						url: '/pages/store/packageDetails?choose=1&packageId='+this.package.packageId || ''
					})
				} else {
					gotoMiniProgram();
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.close_icon {
		width: 64rpx;
		height: 64rpx;
		position: absolute;
		right: 0;
		top: 0;
	}
	.giftpop {
		width: 590rpx;
		min-height: 758rpx;
		margin-bottom: 100rpx;
		position: relative;
		.gift_img_head {
			width: 312rpx;
			height: auto;
		}

		.new_user_bg {
			width: 308rpx;
			margin-top: -4rpx;
		}

		.free_font_img {
			width: 520rpx;
			height: auto;
			margin-top: 16rpx;
		}

		.gift-img {
			width: 470rpx;
			height: 320rpx;
			margin-top: 24rpx;
			background: #FFFFFF;
			border-radius: 36rpx 36rpx 36rpx 36rpx;
		}

		.gift-name {
			width: 90%;
			margin-top: 26rpx;
			text-align: center;
		}

		&-footer {
			margin-top: 48rpx;
		}

		.buy_btn {
			width: 240rpx;
			height: auto;
		}

		.addfans_btn {
			width: 318rpx;
			height: auto;
			margin-left: 32rpx;
		}

		&-body {
			width: 582rpx;
			min-height: 632rpx;
			margin-top: 4rpx;
			padding-bottom: 34rpx;
			background: linear-gradient(180deg, #F7E4DE 0%, #FFEDD8 27%, #FFF7ED 100%);
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			box-sizing: border-box;
			position: relative;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #FF5C03;

			&::after {
				content: "";
				position: absolute;
				width: 590rpx;
				height: 640rpx;
				background: linear-gradient(180deg, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				top: -4rpx;
				left: -4rpx;
				z-index: -1;
			}
		}
	}
</style>