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

		<div class="mui-content">
			<div class="mui-content-padded">
				<ul class="mui-table-view openfyy-list">
					<li class="mui-table-view-cell mui-media" v-for="(item,index) in recordList">
						<router-link :to="{name:'CommonNoticeInfo',query:{id:item.messageId}}" class="mui-navigate-right">
							<div :class="'mui-media-body dian-list '+(item.readStatus?'':'red-after')">
								<div class="mui-ellipsis">{{item.title}}</div>
								<p class="mui-ellipsis" v-text="item.createTime"></p>
							</div>
						</router-link>
					</li>
				</ul>
			</div>
		</div>
		<NullList :remark="'暂无消息'" v-if="!recordList.length"></NullList>

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

<script>
	import * as API_Notice from '@/apis/Common/notice'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import isReachBottom from '$project/utils/isReachBottom'
	import TopHeader from '$project/components/TopHeader.vue'
	import NullList from '$project/components/NullList.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'CommonNotice',
		components: {
			Common,
			Loading,
			TopHeader,NullList
		},
		data() {
			return {
				pageTitle: '消息列表',

				isLoading: false,

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
					type: this.$route.query.type
				},
				recordList: [],
			}
		},
		created() {},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_Notice.getMessageList(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;
					}
				}
			},
			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',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style scoped>
	.red-after:after {
		background: red;
	}
</style>
