<template>
	<view class="">
		<block v-for="(item, index) in communityList" :key="index">
			<view @click="toDetails(item.id)" style="border-bottom: 1px solid #efefef;">
				<pic-text :info="item" :index="index" :stopVideo="stopVideo" :currentPlay="currentPlay" @changePlay="changePlay()"></pic-text>
			</view>
		</block>
	</view>
</template>

<script>
	import App from '@/common/js/app.js';
	import picText from "@/components/template/pic_text/pic_text.vue"
	export default {
		data(){
			return {
				communityList: [],
				stopVideo: 0,
				scrollTimer: null,
				currentPlay: -2,//当前正在播放的视频在列表中的索引,-2表示没有正在播放
			}
		},
		props:{
			tab1Page: {
				type: Number
			},
			scrollLock: {
				type: Boolean
			}
		},
		components:{
			picText
		},
		watch: {
			tab1Page: {
				handler(newVal, oldVal){
					this.getList(newVal, true)
				}
			},
			scrollLock: {
				handler(newVal, oldVal){
					this.handlerScroll();
				}
			}
		},
		created() {
			this.getList(this.tab1Page);
		},
		methods: {
			// 跳转正文详情
			toDetails(id){
				uni.navigateTo({
					url:"/pagesA/pictureTextDetails/pictureTextDetails?id=" + id
				})
			},
			// 获取学生社区图文列表
			getList(page = 1, isPage = false){
				let _this = this;
				let data = {
					id: 0,//0对应掌上生活的全部类目
					two_id: undefined,
					page,
					page_index: 10,
					homeflag: 1,
					keyword: '',
				};
				App._post_form('&p=pocket&do=infoList', data, res => {
					let list = [];
					if (!isPage) {
						if (res.data.list.length > 0) {
							list = res.data.list;
							_this.setData({
								communityList: list
							})
						} else {
							// _this.noMore1 = true;
							_this.$emit('changenoMore1', true);
						}
					}else{//第二页走这里
						if (res.data.list.length > 0){
							list = [..._this.communityList, ...res.data.list];
							_this.setData({
								communityList: list
							})
						}else{
							// _this.noMore1 = true;
							_this.$emit('changenoMore1', true);
						}
					}
				});
			},
			handlerScroll(){
				if(this.scrollLock){
					clearTimeout(this.scrollTimer);
				}
				this.scrollTimer = setTimeout(()=>{
					// this.scrollLock = false;
					this.$emit('changeScrollLock', false)
					this.stopVideo++;
				}, 500)
			},
			changePlay(e){
				this.stopVideo++;//先关闭上一个播放的按钮，再改变当前播放索引=最新播放视频索引
				this.currentPlay = e;
			}
		}
	}
</script>

<style>
</style>