<template>
	<view class="list">
		<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
			<view class="address">
				<view class="con">
					<view class="title omit">{{ item.address }} </view>
					<view class="desc">
						<text>{{item.name}}</text>
						<text>{{item.phone}}</text>
					</view>
				</view>
				<view class="icon">&#xe8f2;</view>
				<view class="clear"></view>
			</view>
		</view>
		<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
		<u-empty v-if="!loadMore && list.length == 0"></u-empty>
	</view>
</template>

<script>
export default {
	data() {
		return {
			select: false,
			list: [],
			param: { pageNo: 1, pageSize: 10 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.select = e.select || false;
		this.getData();
		uni.$on('address', res => {
			this.refresh();
		});
	},
	methods: {
		getData() {
			this.http.request({
				url: '/transport-server/app/TbFavoriteContacts/getAppList',
				data: this.param,
				loading: 'false',
				success: res => {
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
				}
			});
		},
		detail(item) {
			uni.$emit('one-address', item);
			uni.navigateBack();
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNo = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNo++;
			this.getData();
		}
	},
	onNavigationBarButtonTap() {
		uni.navigateTo({ url: 'add' });
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
.list {
	padding: 12px;
	.item {
		padding: 5px;
		color: $font-c;
		background-color: white;
		border-radius: 10px;
		margin-bottom: 10px;
	}
}
</style>
