shoplist.vue 7.8 KB
Newer Older
M
maguohua 已提交
1
<template>
M
maguohua 已提交
2
	<div class="shoplist_container">
M
maguohua 已提交
3
		<ul v-load-more="loaderMore" v-if="shopListArr.length" type="1">
M
maguohua 已提交
4
			<router-link :to="{path: 'shop', query:{geohash, id: item.id}}" v-for="item in shopListArr" tag='li' :key="item.id" class="shop_li">
M
updata  
maguohua 已提交
5
				<section>
M
maguohua 已提交
6
					<img :src="getImgPath(item.image_path)" class="shop_img">
M
updata  
maguohua 已提交
7 8 9 10 11
				</section>
				<hgroup class="shop_right">
					<header class="shop_detail_header">
						<h4 :class="item.is_premium? 'premium': ''" class="" class="shop_title ellipsis">{{item.name}}</h4>
						<ul class="shop_detail_ul">
M
updata  
maguohua 已提交
12
							<li v-for="item in item.supports" :key="item.id" class="supports">{{item.icon_name}}</li>
M
updata  
maguohua 已提交
13 14 15 16 17
						</ul>
					</header>
					<h5 class="rating_order_num">
						<section class="rating_order_num_left">
							<section class="rating_section">
M
maguohua 已提交
18
								<rating-star :rating='item.rating'></rating-star>
M
updata  
maguohua 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
								<span class="rating_num">{{item.rating}}</span>
							</section>
							<section class="order_section">
								月售{{item.recent_order_num}}
							</section>
						</section>
						<section class="rating_order_num_right" v-if="item.delivery_mode">
							<span class="delivery_style delivery_left">{{item.delivery_mode.text}}</span>
							<span class="delivery_style delivery_right">准时达</span>
						</section>
					</h5>
					<h5 class="fee_distance">
						<section class="fee">
							¥{{item.float_minimum_order_amount}}起送 
							<span class="segmentation">/</span>
							{{item.piecewise_agent_fee.tips}}
						</section>
						<section class="distance_time">
							<span>{{item.distance > 1000? (item.distance/1000).toFixed(2) + 'km': item.distance + 'm'}}
								<span class="segmentation">/</span>
							</span>
							<span class="order_time">{{item.order_lead_time}}分钟</span>
						</section>
					</h5>
				</hgroup>
			</router-link>
		</ul>
M
updata  
maguohua 已提交
46
		<p v-else class="empty_data">没有更多了</p>
M
updata  
maguohua 已提交
47
		<aside class="return_top" @click="backTop" v-if="showBackStatus">
M
updata  
maguohua 已提交
48 49 50
			<svg class="back_top_svg">
				<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#backtop"></use>
			</svg>
M
updata  
maguohua 已提交
51
		</aside>
M
updata  
maguohua 已提交
52
		<footer class="loader_more" v-show="preventRepeatReuqest">正在加载更多商家...</footer>
M
updata  
maguohua 已提交
53
		<div ref="abc" style="background-color: red;"></div>
M
maguohua 已提交
54 55 56
		<transition name="loading">
			<loading v-show="showLoading"></loading>
		</transition>
M
updata  
maguohua 已提交
57
	</div>
M
maguohua 已提交
58 59 60 61 62
</template>

<script>

import {mapState} from 'vuex'
M
maguohua 已提交
63
import {shopList} from '../../service/getData'
M
updata  
maguohua 已提交
64
import {showBack, animate} from '../../config/mUtils'
M
maguohua 已提交
65 66
import {loadMore, getImgPath} from './mixin'
import loading from './loading'
M
maguohua 已提交
67
import ratingStar from './ratingStar'
M
updata  
maguohua 已提交
68

M
maguohua 已提交
69 70 71 72 73
export default {
	data(){
		return {
			offset: 0, // 批次加载店铺列表,每次加载20个 limit = 20
			shopListArr:[], // 店铺列表数据
M
updata  
maguohua 已提交
74
			preventRepeatReuqest: false, //到达底部加载数据,防止重复加载
M
updata  
maguohua 已提交
75
			showBackStatus: false, //显示返回顶部按钮
M
maguohua 已提交
76
			showLoading: true, //显示加载动画
M
maguohua 已提交
77 78 79
		}
	},
	async mounted(){
M
updata  
maguohua 已提交
80
		//获取数据
M
maguohua 已提交
81
		this.shopListArr = await shopList(this.latitude, this.longitude, this.offset, this.restaurantCategoryId);
M
update  
maguohua 已提交
82
		this.hideLoading();
M
maguohua 已提交
83
		//开始监听scrollTop的值,达到一定程度后显示返回顶部按钮
M
updata  
maguohua 已提交
84 85 86
		showBack(status => {
			this.showBackStatus = status;
		});
M
maguohua 已提交
87
	},
M
maguohua 已提交
88 89
	components: {
		loading,
M
maguohua 已提交
90
		ratingStar,
M
maguohua 已提交
91 92 93
	},
	props: ['restaurantCategoryId', 'restaurantCategoryIds', 'sortByType', 'deliveryMode', 'supportIds', 'confirmSelect', 'geohash'],
	mixins: [loadMore, getImgPath],
M
maguohua 已提交
94 95 96 97 98 99
	computed: {
		...mapState([
			'latitude','longitude'
		])
	},
	methods: {
M
updata  
maguohua 已提交
100 101 102 103 104 105
		//到达底部加载更多数据
		async loaderMore(){
			//防止重复请求
			if (this.preventRepeatReuqest) {
				return 
			}
M
updata  
maguohua 已提交
106

M
updata  
maguohua 已提交
107
			this.preventRepeatReuqest = true;
M
updata  
maguohua 已提交
108
			//数据的定位加20位
M
updata  
maguohua 已提交
109
			this.offset += 20;
M
maguohua 已提交
110
			this.showLoading = true;
M
maguohua 已提交
111
			let res = await shopList(this.latitude, this.longitude, this.offset, this.restaurantCategoryId);
M
updata  
maguohua 已提交
112
			this.shopListArr = this.shopListArr.concat(res);
M
update  
maguohua 已提交
113
			this.hideLoading();
M
updata  
maguohua 已提交
114 115 116 117 118 119 120 121
			//当获取数据小于20,说明没有更多数据,不需要再次请求数据
			if (res.length < 20) {
				return
			}
			this.preventRepeatReuqest = false;
		},
		//返回顶部
		backTop(){
M
updata  
maguohua 已提交
122
			animate(document.body, {scrollTop: '0'}, 400,'ease-out');
M
updata  
maguohua 已提交
123 124 125 126
		},
		//监听父级传来的数据发生变化时,触发此函数重新根据属性值获取数据
		async listenPropChange(){
			this.offset = 0;
M
maguohua 已提交
127
			this.showLoading = true;
M
updata  
maguohua 已提交
128
			this.shopListArr = await shopList(this.latitude, this.longitude, this.offset, '', this.restaurantCategoryIds, this.sortByType, this.deliveryMode, this.supportIds);
M
update  
maguohua 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
			if (process.env.NODE_ENV !== 'development') {
				this.shopListArr = this.shopListArr.reverse();
			}
			this.hideLoading();
		},
		hideLoading(){
			if (process.env.NODE_ENV !== 'development') {
				clearTimeout(this.timer);
				this.timer = setTimeout(() => {
					clearTimeout(this.timer);
					this.showLoading = false;
				}, 1000)
			}else{
				this.showLoading = false;
			}
		},
M
updata  
maguohua 已提交
145
	},
M
maguohua 已提交
146
	watch: {
M
updata  
maguohua 已提交
147
		//监听父级传来的restaurantCategoryIds,当值发生变化的时候重新获取餐馆数据,作用于排序和筛选
M
updata  
maguohua 已提交
148 149
		restaurantCategoryIds: function (value){
			this.listenPropChange();
M
updata  
maguohua 已提交
150
		},
M
updata  
maguohua 已提交
151 152 153
		//监听父级传来的排序方式
		sortByType: function (value){
			this.listenPropChange();
M
maguohua 已提交
154
		},
M
updata  
maguohua 已提交
155 156 157 158
		//监听父级的确认按钮是否被点击,并且返回一个自定义事件通知父级,已经接收到数据,此时父级才可以清除已选状态
		confirmSelect: function (value){
			this.listenPropChange();
			this.$emit('DidConfrim');
M
updata  
maguohua 已提交
159
		}
M
maguohua 已提交
160 161 162 163 164
	}
}
</script>

<style lang="scss" scoped>
M
maguohua 已提交
165
	@import '../../style/mixin';
M
maguohua 已提交
166 167 168
	.shoplist_container{
		background-color: #fff;
	}
M
maguohua 已提交
169 170 171
	.shop_li{
		display: flex;
		border-bottom: 0.025rem solid #f1f1f1;
M
updata  
maguohua 已提交
172
		padding: 0.7rem 0.4rem;
M
maguohua 已提交
173 174 175 176
	}
	.shop_img{
		@include wh(2.7rem, 2.7rem);
		display: block;
M
updata  
maguohua 已提交
177
		margin-right: 0.4rem;
M
maguohua 已提交
178 179 180 181 182 183 184 185
	}
	.shop_right{
		flex: auto;
		.shop_detail_header{
			@include fj;
			align-items: center;
			.shop_title{
				width: 8.5rem;
M
updata  
maguohua 已提交
186 187 188
				color: #333;
				@include font(0.65rem, 0.65rem, 'PingFangSC-Regular');
				font-weight: 700;
M
maguohua 已提交
189
			}
M
updata  
maguohua 已提交
190 191 192 193 194 195 196 197 198
			.premium::before{
				content: '品牌';
				display: inline-block;
				font-size: 0.5rem;
				background-color: #ffd930;
				padding: 0 0.1rem;
				border-radius: 0.1rem;
				margin-right: 0.2rem;
				vertical-align: top;
M
maguohua 已提交
199 200 201 202 203 204 205 206
			}
			.shop_detail_ul{
				display: flex;
				.supports{
					@include sc(0.5rem, #999);
					border: 0.025rem solid #f1f1f1;
					padding: 0.04rem;
					border-radius: 0.08rem;
M
updata  
maguohua 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
					margin-left: 0.05rem;
				}
			}
		}
		.rating_order_num{
			@include fj(space-between);
			height: 0.6rem;
			margin-top: 0.52rem;
			.rating_order_num_left{
				@include fj(flex-start);
				.rating_section{
					display: flex;
					.rating_num{
						@include sc(0.4rem, #ff6000);
						margin: 0 0.2rem;
					}
				}
				.order_section{
						@include sc(0.4rem, #666);
				}
			}
			.rating_order_num_right{
				display: flex;
				.delivery_style{
					font-size: 0.4rem;
					padding: 0.04rem 0.08rem 0;
					border-radius: 0.08rem;
					margin-left: 0.08rem;
				}
				.delivery_left{
					color: #fff;
					background-color: $blue;
					border: 0.025rem solid $blue;
				}
				.delivery_right{
					color: $blue;
					border: 0.025rem solid $blue;
				}
			}
		}
		.fee_distance{
			margin-top: 0.52rem;
			@include fj;
			@include sc(0.5rem, #666);
			.distance_time{
M
maguohua 已提交
252 253 254
				span{
					color: #888;
				}
M
updata  
maguohua 已提交
255 256
				.order_time{
					color: $blue;
M
maguohua 已提交
257
				}
M
maguohua 已提交
258 259 260
				.segmentation{
					color: #ccc;
				}
M
updata  
maguohua 已提交
261 262 263 264 265 266 267 268
			}
		}
	}
	.loader_more{
		@include font(0.6rem, 3);
		text-align: center;
	    color: #999;
	}
M
updata  
maguohua 已提交
269 270 271 272 273
	.empty_data{
		@include sc(0.5rem, #666);
		text-align: center;
		line-height: 2rem;
	}
M
updata  
maguohua 已提交
274 275 276 277 278 279
	.return_top{
		position: fixed;
		bottom: 3rem;
		right: 1rem;
		.back_top_svg{
			@include wh(2rem, 2rem);
M
maguohua 已提交
280 281
		}
	}
M
maguohua 已提交
282 283 284 285 286 287
	.loading-enter-active, .loading-leave-active {
		transition: opacity 1s
	}
	.loading-enter, .loading-leave-active {
		opacity: 0
	}
M
maguohua 已提交
288
</style>