<template>
	<view>
		<view class="list">
			<view class="search">
				<u-search placeholder="搜索互市" v-model="param.name" bgColor="white" @search="refresh()" :animation="true" actionText="取消" @clear="refresh()"></u-search>
			</view>
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="title omit">{{ item.name }}</view>
				<view class="desc">{{ item.address }}</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>
	</view>
</template>

<script>
export default {
	data() {
		return {
			param: { pageNo: 1, pageSize: 20 },
			list: [],
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/level-one-server/app/TbTradeArea/getList',
				loading: 'false',
				data: this.param,
				success: res => {
					this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
					this.list.push(...res.data.data);
					uni.setNavigationBarTitle({ title: '互市选择(' + res.data.dataCount + ')' });
				}
			});
		},
		detail(item) {
			uni.$emit('area', 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();
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $pg;
}
.list {
	padding: 12px;
	.search {
		padding-top: 0px;
	}
	.item {
		padding: 13px;
		background-color: white;
		margin-bottom: 10px;
		border-radius: 5px;
		.title {
			font-weight: bold;
		}
		.desc {
			padding-top: 5px;
			font-size: 14px;
			color: #7a7a7a;
		}
	}
}
</style>
