<template>
	<view class="list">
		<view class="msearch">
			<u-search v-model="param.name" :animation="true" action-text="取消" placeholder="输入搜索内容" shape="round" @search="search" @clear="clear"></u-search>
		</view>
		<view class="r_item" v-for="(item, index) in list" :key="index" @click="detail(item)">
			<image :src="ip + item.showPictures[0]" mode="aspectFill" class="pic"></image>
			<view class="con">
				<view class="title omit">{{ item.name }}</view>
				<view class="ms omit">
					<text class="icon">&#xe64a;</text>
					<text class="tti">{{ item.addres }}</text>
				</view>
				<view class="ms">
					<u-rate :count="5" v-model="value" active-color="#FF9800" :disabled="true"></u-rate>
					<text>5.0</text>
				</view>
			</view>
			<view class="clear"></view>
		</view>
		<view class="loading"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.$http.urls.ip,
			value: 5,
			list: [],
			param: { pageNum: 1, pageSize: 10, name: '' },
			loadMore: true
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		//获取数据
		getData() {
			this.$http.request({
				url: this.$http.urls.hotelList,
				data: this.param,
				loading: 'false',
				success: res => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach(item => {
						item.showPictures = item.showPictures.split(',');
						this.list.push(item);
					});
				}
			});
		},
		//详情
		detail(item) {
			uni.navigateTo({ url: '/pages/shop/detail?shopId=' + item.shopId });
		},
		//点击键盘搜索按钮触发
		search() {
			this.refresh();
		},
		//清空搜索内容
		clear() {
			this.refresh(); 
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			uni.stopPullDownRefresh();
			this.refresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.list {
	padding: 10px 17px 70px 17px;
}
</style>
