<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  v-for="(item,index) in adsList" :key="index">
				<u-image  @click="jump(item)" style="width: 100%;height: 268rpx;" :src="item.url"
					mode="aspectFill"></u-image>
			</swiper-item>
		</swiper>
		<meScroll  :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
			<goods :goodsList="goodsList" :activityId="activityId"></goods>
		</meScroll>
	</view>
</template>

<script>
	import meScroll from "../mescroll-body/mescroll-uni.vue"
	import goods from "@/components/goods/goods.vue"
	import {
		wx_launch
	} from "../../common/utils/wx_launch.js"; // 引入公共js文件
	export default {
		components: {
			goods,meScroll
		},
		props: {
			activityId: {
				type: String,
				default: '',
			}
		},
		data() {
			return {
				status: 'loadmore',
				current:1,
				
				goodsList: [],
				adsList: [],
				appletList: [],
				
				isInit: false, // 是否初始化
				goodsList: [], // 列表数据
				mescroll: null, // mescroll 对象
				// 上拉配置参数
				up: {
					noMoreSize: 3,
					offset: 200,
					auto: true,
					page: {
						page: 0,
						size: 500
					}
				},
				// 下拉配置参数
				down: {
					use: false, 
					auto: false
				}
			}
		},
		created() {
			// this.fetchGoodsList();
			this.fetchAds()
		},
		methods: {
			initMeScroll(mescroll) {
				this.mescroll = mescroll
			},
			async fetchAds() {
				let res = await this.$u.api.pointsGoods.ads({
					activityId: this.activityId
				})
				this.adsList = res.records;
			},
			fetchGoodsList() {
				let params={
					activityId: this.activityId,
					current:this.current,
				}
				this.$u.api.pointsGoods.list(params).then(res => {
					this.goodsList =[...this.goodsList,...res.records]
				})
			},
			jump(item) {
				if (item.type==0) {
					window.location.href=item.path
					return
				}
				uni.navigateTo({
					url: '/pages/web-view/web-view?url=' + item.path
				})
			},
			upFn(mescroll) {
				let params={
					activityId: this.activityId,
					current:mescroll.num,
					size:mescroll.size
				}
				try{
					this.$u.api.pointsGoods.list(params).then(res => {
						let data=res.records
						mescroll.endBySize(data.length, res.total);
						if(mescroll.num == 1) this.goodsList = []; //如果是第一页需手动制空列表
						this.goodsList=this.goodsList.concat(data); //追加新数据
					})
				}catch(e){
					mescroll.endErr();
				}
			},
		}
	}
</script>

<style>

</style>
