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

		<div class="mui-content vongi-hdsq">
			<div id="slider" class="mui-slider mui-fullscreen ">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<router-link :to="{name:'MasterActivityExamineList',query:{isVerify:0}}" :class="'mui-control-item '+(listForm.isVerify==0?'mui-active':'')">
							<span class="fyy-badge">待处理<span class="mui-badge" v-if="firstRecordsTotal" v-text="firstRecordsTotal"></span></span>
						</router-link>
						<router-link :to="{name:'MasterActivityExamineList',query:{isVerify:1}}" :class="'mui-control-item '+(listForm.isVerify==1?'mui-active':'')">
							已处理
						</router-link>
					</div>
				</div>

				<NullList :remark="'暂无审批记录'" v-if="!recordList.length"></NullList>

				<div v-if="recordList.length" class="mui-slider-group">
					<div v-show="listForm.isVerify==0" class="mui-slider-item mui-control-content">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<ul class="mui-table-view">
									<li v-for="(item,index) in recordList" :key="item.id" class="mui-table-view-cell">
										<router-link :to="{name:'MasterActivityExamineInfo',query:{id:item.id}}">
											<div class="mui-media-body flew-sp">
												<div class="mui-col-xs-9" v-text="item.title"></div>
												<div class="mui-col-xs-3">
													<button type="button" :style="getStatusStyle(item.verify)" class="mui-btn mui-btn-greye mui-btn-outlined" v-text="getStatusName(item.verify)"></button>
												</div>
											</div>
											<p class="flew-items flew-sp">
												发 起 人：{{item.applicant}} {{item.roomNumber}}
												<span class='mui-ellipsis'>{{item.createTime}}</span>
											</p>
										</router-link>
									</li>
								</ul>
							</div>
						</div>
					</div>
					<div v-show="listForm.isVerify==1" class="mui-slider-item mui-control-content">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<ul class="mui-table-view">
									<li v-for="(item,index) in recordList" :key="item.id" class="mui-table-view-cell">
										<router-link :to="{name:'MasterActivityExamineInfo',query:{id:item.id}}">
											<div class="mui-media-body flew-sp">
												<div class="mui-col-xs-9" v-text="item.title"></div>
												<div class="mui-col-xs-3">
													<button type="button" :style="getStatusStyle(item.verify)" class="mui-btn mui-btn-greye mui-btn-outlined" v-text="getStatusName(item.verify)"></button>
												</div>
											</div>
											<p class="flew-items flew-sp">
												发 起 人：{{item.applicant}} {{item.roomNumber}}
												<span class='mui-ellipsis'>{{item.createTime}}</span>
											</p>
										</router-link>
									</li>
								</ul>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<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: 'MasterActivityExamineList',
		components: {
			Common,
			Loading,
			TopHeader,
			NullList
		},
		data() {
			return {
				isLoading: false,

				pageTitle: '活动审批',

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
					isVerify: this.$route.query.isVerify ? this.$route.query.isVerify : 0,
				},
				recordList: [],

				firstRecordsTotal: 0,
			}
		},
		created() {},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_Activity.getExamineActivityList(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;
					}
				}
			},
			//切换
			reloadList(status) {
				this.listForm.isVerify = status;
				this.listForm.pageIndex = 1;
				this.getList();
			},
			//获取审核状态
			getStatusName(status) {
				let statusArr = ['待审核', '已批准', '未批准'];
				return statusArr[status];
			},
			//获取审核状态
			getStatusStyle(status) {
				let statusArr = ['color:#3385FF;border-color:#3385FF', 'color:#389E0D;border-color:#389E0D', 'color:#FF6666;border-color:#FF6666'];
				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',
			})
		},
		watch: {
			//本页面监听到路由（参数）改变
			'$route': function(to, from) {
				this.reloadList(to.query.isVerify ? to.query.isVerify : 0)
			}
		},
	}
</script>

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