<template>
<view>
<!--components/popAd/popAd.wxml-->
<template name="home_pop_up_ads">
  <block v-if="!first&&!iscouponAd&&!storeShow&&isAppLayerAd">
    <view class="layer" v-if="popAdTemplate&&popAdTemplate.state==0&&isLayerAd&&popAdList.pic">
      <image lazy-load="true" :src="popAdList.pic" mode="aspectFit" @tap="getUrl2" :data-type="popAdList.type" :data-content="popAdList.content"></image>
      <image class="close" src="/static/pages/images/ad_close_w.png" @tap="hideAd"></image>
    </view>
  </block>
</template>
</view>
</template>

<script>
	const req = require("../../utils/request");
	const utils = require("../../utils/util");
	const app = getApp();
	export default {
		data() {
			return {
				isAppLayerAd:app.globalData.isLayerAd
			};
		},

		components: {},
		props: {
			first:Boolean,
			popAdTemplate:Object,
			isLayerAd:Boolean,
			popAdList:Object,
			iscouponAd:Boolean,
			storeShow:Boolean
		},
		options: {
			addGlobalClass: true
		},

		// created(){
		//   console.log(this.data.merchant)
		//   req.getRequest('/api/merchant/getMerchantList',{}, res => {
		//     res = res.filter(it=>it.isDefault==1)
		//      this.setData({merchant:res[0]})
		//    })
		// },
		mounted() {
			// console.log(this.iscouponAd,this.first,this.storeShow)
		},

		methods: {
			getUrl2(e) {
				var dt = e.currentTarget.dataset;
				var url = "";
				var id = "";
				var acid = "";
			
				if (dt.content != "") {
					let conunt = dt.content.split("_");
					id = conunt[1];
					acid = conunt[0];
				}
			
				if (dt.type * 1 == 2 && dt.content != "") {
					url = "product/detail/detail?id=" + dt.content;
				} else if (dt.type * 1 == 4) {
					url = "product/groupDetail/groupDetail?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 5) {
					url = "product/coupon/coupon";
				} else if (dt.type * 1 == 6) {
					url = "service/live/live";
				} else if (dt.type * 1 == 7) {
					url = "product/groupList/groupList" + dt.merchant;
				} else if (dt.type * 1 == 9 && dt.content != "") {
					url = "product/list/list?id=" + dt.content;
				} else if (dt.type * 1 == 10) {
					url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + dt.content;
				} else if (dt.type * 1 == 11) {
					url = "activity/group/index/index" + dt.merchant;
				} else if (dt.type * 1 == 12) {
					url = "activity/seckill/seckill" + dt.merchant;
				} else if (dt.type * 1 == 13) {
					url = "activity/bargain/index/index" + dt.merchant;
				} else if (dt.type * 1 == 14) {
					url = "activity/newbornZone/newbornZone" + dt.merchant;
				} else if (dt.type * 1 == 15 && dt.content != "") {
					url = "activity/newbornDetails/newbornDetails?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 16 && dt.content != "") {
					url = "activity/seckillDetails/seckillDetails?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 17 && dt.content != "") {
					url = "activity/bargain/detail/detail?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 18 && dt.content != "") {
					url = "activity/group/detail/detail?acid=" + acid + "&id=" + id;
				} else {
					url = "";
				}
			
				if (dt.type * 1 == 6) app.globalData.switchTab(url);
				else app.globalData.openPage(url);
				this.hideAd();
			},
			
			hideAd() {
				//关闭广告
				// if(this.data.first==false){
				this.setData({
					isLayerAd: false
				}); // }
			},
		}
	};
</script>
<style>
@import "./popAd.css";
</style>