<template>
	<gracePage :customHeader="false">
		<view class="container" slot="gBody">
			<swiper class="swiper" @change="change" :circular="swiper.circular" :current="index">
				<swiper-item v-for="(v, k) in fetch.items"  v-if="v.data" :key="k" >
					<scroll-view scroll-y="true" scroll-x="true" class="scroll-height">
						<dream ref="dream" @cate="cate" @community="community" :index="k" :item="v" :control="control" class="item"></dream>
					</scroll-view>
				</swiper-item>
			</swiper>
			<graceDrawer :show="cate_drawer.show" :zIndex="cate_drawer.index" padding="cate_drawer.padding" :top="cate_drawer.top" direction="left" width="100%" v-on:closeDrawer="closeCate">
				<view slot="links">
					<cate ref="cate" @goIndex="goIndex" :index="index" :content_id="content_id" :info_id="fetch.info_id" :page_id="fetch.page_id" :parent_page_id="fetch.parent_page_id"></cate>
				</view>
			</graceDrawer>
			
			<graceDrawer :show="community_drawer.show" :zIndex="community_drawer.index" padding="community_drawer.padding" :top="community_drawer.top" direction="right" width="100%" v-on:closeDrawer="closeCommunity">
				<view slot="links">
					<community ref="community" @goIndex="goIndex" :index="index" :content_id="content_id" :info_id="fetch.info_id" :page_id="fetch.page_id" :parent_page_id="fetch.parent_page_id" :type="community_drawer.type" :type_id="content_id"></community>
				</view>
			</graceDrawer>
		</view>
	</gracePage>
</template>
<script>
import cate from "@/pages/dream/view/cate.vue";
import community from "@/pages/dream/view/community.vue";
import dream from "@/pages/dream/view/dream.vue";
var graceRichText = require("@/lib/graceUI/jsTools/richText.js");
export default{
	data() {
		return {
			id : 1,
			page_id : 1,
			index : 0,
			content_id : 0,
			swiper : {
				index : 0,
				circular : false,
			},
			fetch: {
				items : [],
				info_id : 0,
				page_id : 0,
				parent_page_id : 0,
			},
			control : {},
			cate_drawer : {
				index : 5,
				top: 0,
				padding: '0rpx',
				show : false,
			},
			community_drawer : {
				index : 5,
				top: 0,
				padding: '0rpx',
				show : false,
				type : 3,
			},
		}
	},
	onLoad(option) {
		this.id = option.id;
		this.page_id = option.page_id;
		this.index = option.index;
		this.getData();
	},
	// 重新加载
	onPullDownRefresh: function() {
		if (this.cate_drawer.show == true) {
			this.$refs.cate.getData();
		} else if (this.community_drawer.show == true) {
			this.$refs.community.getData();
		} else {
			this.getData();
		}
	},
	methods:{
		change : function(e) {
			this.swiper.index = e.detail.current;
			if (this.control) {
				var i = 0;
				for (i in this.control) {
					if (this.control[i].load) {
						console.info(i);
						if (this.swiper.index == i) {
							console.info('start');
							this.control[i].start();
						} else {
							this.control[i].stop();
						}
					}
				}
			}
			if (this.swiper.index == this.fetch.items.length - 1) {
				//this.$refs.dream[this.swiper.index].setShow();
			}
		},
		view : function() {
			this.Dever.location('dream/view?id=1');
		},
		getData : function() {
			this.Dever.get(this, 'app/collection/?l=api.getContent', {id:this.id, page_id:this.page_id});
		},
		goIndex : function(index) {
			this.index = index;
			this.closeCate();
			this.closeCommunity();
			var dream = this.$refs.dream[this.swiper.index];
			dream.setShow();
		},
		cate : function() {
			this.getContentId();
			this.cate_drawer.show = !this.cate_drawer.show;
		},
		closeCate : function() {
			this.cate_drawer.show = false;
		},
		community : function() {
			this.getContentId();
			this.community_drawer.show = !this.community_drawer.show;
		},
		closeCommunity : function() {
			this.community_drawer.show = false;
		},
		getContentId : function() {
			this.content_id = this.fetch.items[this.swiper.index].id;
		}
		
	},
	components:{
		dream,cate,community
	}
}
</script>
<style>
.container {
  position: absolute;
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  -webkit-overflow-scrolling: touch; 
}
.swiper {
	width: 750rpx;
	height: 100%;
}
swiper-item>view{
  height: 100%;
}
swiper-item image{
  width: 750rpx;
  height: 100%;
}
.scroll-height {
	height:100%;
}
</style>