<template>
	<view >
		<swiper class="screen-swiper square-dot margin-sm" style="height: 260rpx;min-height: 268rpx;"
			:indicator-dots="true" :circular="true" :autoplay="true" interval="5000" duration="500">
			<swiper-item>
				<div>
					<div id="launch-btn"></div>
				</div>
			</swiper-item>

			<swiper-item v-if="item.type!=0" v-for="(item,index) in adsList" :key="index">
				<u-image  @click="jump(item.path)" style="width: 100%;height: 268rpx;" :src="item.url"
					mode="aspectFill"></u-image>
			</swiper-item>
		</swiper>
		<goods :goodsList="goodsList" :activityId="activityId"></goods>
		<view style="height: 50rpx;">
			
		</view>
	</view>
</template>

<script>
	import goods from "@/components/goods/goods.vue"
	import {
		wx_launch
	} from "../../common/utils/wx_launch.js"; // 引入公共js文件
	export default {
		components: {
			goods
		},
		props: {
			activityId: {
				type: String,
				default: '',
			}
		},
		data() {
			return {
				goodsList: [],
				adsList: [],
				appletList: []
			}
		},
		created() {
			this.$shareConfig({}, this)
			this.fetchGoodsList();
		},
		 async mounted() {
			 let res = await this.$u.api.pointsGoods.ads({
			 	activityId: this.activityId
			 })
			 this.adsList = res.records;
			 this.appletList = this.adsList.filter(item => item.type == 0)
			 let image=this.appletList[0].url
			 let appid=this.appletList[0].path
			 let page=this.appletList[0].page
			// 自定义html内容
			let content = `
				 <image class="img"  src="${image}"
					mode="scaleToFill"></image>
			      <style>
			         .img{
					  z-index:999,
			          width:100%;
					  height: 268rpx;
			        }
			      </style>
			      `
			let launchParams = {
				eleId: "launch-btn", // 元素id
				url: page+".html", // 跳转小程序的页面路径
				appid,
				content // 自定义的html内容
			};
			wx_launch(launchParams);
		},
		methods: {
			async fetchAds() {
				let res = await this.$u.api.pointsGoods.ads({
					activityId: this.activityId
				})
				this.adsList = res.records;
				this.appletList = this.adsList.filter(item => item.type == 0)
			},
			fetchGoodsList() {
				this.$u.api.pointsGoods.list({
					activityId: this.activityId
				}).then(res => {
					this.goodsList = res.records;
				})
			},
			jump(url) {
				uni.navigateTo({
					url: '/pages/web-view/web-view?url=' + url
				})
			}
		}
	}
</script>

<style>

</style>
