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

		<div class="mui-content vongi-zctj">
			<div class="vongi-bagfff margin10">
				<div class="vongi-xzdw-search">
					<input v-model="listForm.name" @keyup.enter="reloadList" type="search" placeholder="搜索姓名">
					<span class="mui-icon mui-icon-search"></span>
				</div>
			</div>
			<div class="vongi-fx-list">
				<ul class="mui-table-view">
					<li v-for="(item,index) in recordList" class="mui-table-view-cell">
						<router-link :to="{name:'OtherReturnInfo',query:{id:item.id}}" class="mui-navigate-right">
							<div class="mui-pull-left">
								{{item.name}}<span :class="item.sex=='1'?'color4fc5f7':'colorfe616c'" v-text="item.sex=='1'?'男':'女'"></span>{{item.phone}}
							</div>
							<span v-if="item.newFlag" class="mui-pull-right mui-badge mui-badge-danger">NEW</span>
						</router-link>
					</li>
				</ul>
			</div>
		</div>

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

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

				pageTitle: '返乡人员登记信息',

				listForm: {
					name: '',
					pageIndex: '',
					pageSize: 20,
					totalPage: 1,
				},
				recordList: [],
			}
		},
		created() {},
		methods: {
			//重新搜索加载
			reloadList() {
				this.listForm.pageIndex = 1;
				this.getList();
			},
			//获取列表
			getList() {
				this.isLoading = true;
				API_return.commissionerReturnInfoList(this.listForm).then(response => {
					this.isLoading = false;

					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++;

				}).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() {
				//从外部进入可能
				this.getList();
			},
		},
		mounted() {
			//监控下拉加载事件
			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',
				menu_list: 'menu_list',
				common_menu_list: 'common_menu_list',
			})
		}
	}
</script>

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