<template>
	<div>
		<common ref="common" @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle"></top-header>

		<div class="mui-content">
			<div v-for="(item,index) in recordList" class="vongi-sqhd-list">
				<p class="vongi-center" v-text="item.startTime.substr(0,10)"></p>
				<router-link :to="{name:'MasterActivityInfo',query:{id:item.id}}" class="mui-card">
					<div class="mui-card-content">
						<div class="mui-card-content-inner">
							<img :src="item.frontCover" width="100%" />
						</div>
					</div>
					<div class="mui-card-footer mui-ellipsis mui-navigate-right" v-text="item.title"></div>
				</router-link>
			</div>
		</div>
		<NullList :remark="'暂无活动'" v-if="!recordList.length"></NullList>

		<loading :visible="isLoading"></loading>
	</div>
</template>

<script>
	import * as API_Activity from '@/apis/Master/activity'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import NullList from '$project/components/NullList.vue'
	import isReachBottom from '$project/utils/isReachBottom'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterActivityList',
		components: {
			Common,
			Loading,
			TopHeader,
			NullList
		},
		data() {
			return {
				isLoading: false,

				pageTitle: '小区活动',

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
				},
				recordList: [],
			}
		},
		created() {},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_Activity.getActivityList(this.listForm).then(response => {
					if (response) {
						if (this.listForm.pageIndex == 1) {
							this.recordList = response.data;
							this.listForm.pageIndex = response.pageNumber;
							this.listForm.totalPage = response.totalPage;
						} else {
							this.recordList = [
								...this.recordList,
								...response.data
							];
						}
					}
					this.listForm.pageIndex++;
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//下拉事件
			handleScrool() {
				if (isReachBottom()) {
					console.log('到达底部')
					if (this.listForm.pageIndex <= this.listForm.totalPage && this.isLoading == false) {
						this.getList();
					} else {
						return;
					}
				}
			},
			//获取审核状态
			getStatusName(status) {
				let statusArr = ['待审核', '已批准', '未批准'];
				return statusArr[status];
			},
			goToAdd() {
				this.$router.push({
					name: 'MasterActivityAdd'
				})
			},
			asynCallBack() {

			},
		},
		mounted() {
			this.getList();
			//监控下拉加载事件
			var _this = this;
			window.addEventListener('scroll', _this.handleScrool);
		},
		destroyed() {
			//销毁监听事件
			var _this = this;
			window.removeEventListener('scroll', _this.handleScrool);
		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style>
</style>
