<template>
	<view>
		<!--template/couponAd/index.wxml-->
		<template name="red_envelopes">
			<block v-if="!first&&!storeShow">
				<view class="layer" v-if="couponAd&&couponAd.state==0&&couponAd.titleCon&&iscouponAd">
					<image lazy-load="true" :src="couponAd.titleCon" mode="aspectFit" @tap="redEnvelopes" :data-type="couponAd.type"
					 :data-content="couponAd.content"></image>
					<image class="close" src="/static/pages/images/ad_close_w.png" @tap="hidecouponAd"></image>
				</view>
			</block>
		</template>
	</view>
</template>

<script>
	const req = require("../../utils/request.js");
	export default {
		data() {
			return {};
		},

		components: {},
		props: {
			first: Boolean, //点击此处关闭气泡
			couponAd: Object, //红包配置
			iscouponAd: Boolean, //是否关闭红包
			storeShow:Boolean //是否显示组件
		},
		mounted() {
			// console.log(this.iscouponAd,this.first,this.couponAd)
		},
		methods: {
			// 关闭优惠券广告
			hidecouponAd() {
				this.setData({
					iscouponAd: false
				})
				this.$emit('iscouponAd', {
				  detail: this.iscouponAd
				});
			},
			// 领红包
			redEnvelopes() {
				if (!req.getStorage('userInfo')) {
					let params = '?couponId=' + this.couponAd.contentId
					req.redirectIndex(params)
				} else {
					req.postRequest('/api/coupon/receiveCoupon', {
						id: this.couponAd.contentId
					}, data => {
						// console.log(data)
						if (data == 1) {
							this.setData({
								iscouponAd: false
							})
							return req.msg('领取成功')
						}
					})
					// console.log(1233)
				}
				// req.isLogin().then(success => {
				//   console.log(success)
				//   if (success) {
				//     this.setData({iscouponAd:false})
				//   }
				// })
			},
		}
	};
</script>
<style>
	@import "./index.css";
</style>
