<template>
	<view>
		<view class="lf-p-t-20 head" v-if="tab_list.length">
			<u-tabs :list="tab_list" :is-scroll="true" :current="current" @change="tabChange"></u-tabs>
		</view>
		<swiper :style="{height: 'calc('+ windowHeight +'px - 110rpx)', width: '750rpx'}" :current="current" @change="swiperChange">
			<swiper-item v-for="(tabItem, tabIndex) in tab_list" :key="tabIndex">
				<scroll-view class="com" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
					<view class="lf-m-t-20"></view>
					<lf-waterfall :list="tabItem.list"></lf-waterfall>
					<view class="loading-more">
						<text class="loading-more-text" v-if="tabItem.list.length">正在加载</text>
						<lf-nocontent v-else></lf-nocontent>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				tab_list: [{
					name: '推荐',
					list: []
				},{
					name: '酒店',
					list: []
				},{
					name: '景点',
					list: []
				},{
					name: '国内游',
					list: []
				},{
					name: '国际游',
					list: []
				},{
					name: '跟团游',
					list: []
				}],
				current: 0,
				windowHeight: 0,
				isRefresher: false, // scroll-view下拉刷新状态，当前默认没有触发
				list: [
				 {
				  price: 35,
				  title: '北国风光，千里冰封，万里雪飘',
				  shop: '李白杜甫白居易旗舰店',
				  image: 'http://pic.sc.chinaz.com/Files/pic/pic9/202002/zzpic23327_s.jpg',
				 },
				 {
				  price: 75,
				  title: '望长城内外，惟余莽莽',
				  shop: '李白杜甫白居易旗舰店',
				  image: 'http://pic.sc.chinaz.com/Files/pic/pic9/202002/zzpic23325_s.jpg',
				 },
				 {
				  price: 385,
				  title: '大河上下，顿失滔滔',
				  shop: '李白杜甫白居易旗舰店',
				  image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
				 },
				 {
				  price: 784,
				  title: '欲与天公试比高',
				  shop: '李白杜甫白居易旗舰店',
				  image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/zzpic23369_s.jpg',
				 },
				 {
				  price: 7891,
				  title: '须晴日，看红装素裹，分外妖娆',
				  shop: '李白杜甫白居易旗舰店',
				  image: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2130_s.jpg',
				 },
				 {
				  price: 2341,
				  shop: '李白杜甫白居易旗舰店',
				  title: '江山如此多娇，引无数英雄竞折腰',
				  image: 'http://pic1.sc.chinaz.com/Files/pic/pic9/202002/zzpic23346_s.jpg',
				 }
				]
			}
		},
		onLoad(){
			this.windowHeight = getApp().globalData.windowHeight;
			this.addRandomData();
		},
		methods: {
			addRandomData() {
				for(let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.list.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.id = this.$u.guid();
					this.tab_list[0].list.push(item);
				}
			},
			tabChange(current){
				this.current = current;
			},
			// 滑块下标值变化
			swiperChange(event){
				this.current = event.detail.current;
				// if(event.detail.source == '') return; // 如果是被动出发，没有事件类型则不做处理
				// if(this.tab_list[event.detail.current].list.length <= 0){
				// 	this.getGoodsList(); // tab下没有数据，请求第一页
				// }
			},
			// 页面触底，加载下一页
			onScrolltolower(){
				return;
				let tab_item = this.tab_list[this.current];
				if(tab_item.isPage){
					tab_item.page = tab_item.page + 1;
					this.getGoodsList();
				}
			},
			// scroll-view 下拉刷新
			onRefresherrefresh(){
				this.isRefresher = true;
				return;
				this.getCategoryList({type: 'scrollRefresh'});
			}
		}
	}
</script>

<style>
	page{
		background-color: #F6F6F6;
	}
</style>
<style lang="scss" scoped="scoped">
	.head{
		background-color: #FFFFFF;
	}
	.com{
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		padding: 0rpx 32rpx;
	}
</style>
